UIDrawable overwriting - search and replace by name #40

Closed
opened 2024-03-09 19:31:44 +00:00 by john · 2 comments
Owner

57 feat: "only_one=True" optional arg to __init__ and .rename methods to overwrite an existing Drawable/Entity that would have the same name

See #39

I lack complete clarity on the proper scope of "only_one" - do we have to search from the root down every window, every scene, every nested child element? More likely, I think it should be on the scope of where you place it, for exactly that level (peers on the same Frame or Grid, basically)

Should a "only_one" bool be stored? Can UIDrawables be moved the same way entities are expected to be able to go from grid to grid?

57 feat: "only_one=True" optional arg to `__init__` and `.rename` methods to overwrite an existing Drawable/Entity that would have the same name See #39 I lack complete clarity on the proper scope of "only_one" - do we have to search from the root down every window, every scene, every nested child element? More likely, I think it should be on the scope of where you place it, for exactly that level (peers on the same Frame or Grid, basically) Should a "only_one" bool be stored? Can UIDrawables be moved the same way entities are expected to be able to go from grid to grid?
john added the
Minor Feature
label 2024-03-09 19:31:44 +00:00
john added this to the Alpha Release Targets milestone 2024-03-13 14:49:18 +00:00
Author
Owner

implemented in d11f76ac43 - needs tests

implemented in d11f76ac43012768d5291529d3b18ecd065ab5c2 - needs tests
Author
Owner

Superseded by Issue #41

The original "only_one=True" concept from this issue has been addressed differently:

Instead of an only_one parameter on __init__, we now have a .find() method that allows searching by name. This provides a cleaner API:

# Old concept (not implemented):
frame = Frame(name="player", only_one=True)  # Would overwrite existing

# New approach:
existing = ui.find("player")
if existing:
    ui.remove(ui.index(existing))
frame = Frame(name="player")
ui.append(frame)

# Or simply access/modify existing element directly:
player = ui.find("player")
if player:
    player.x = 100  # Modify in place

The .find() method addresses the core need (finding elements by name) without the complexity of automatic overwriting semantics.

See #41 for the full implementation details.

## Superseded by Issue #41 The original "only_one=True" concept from this issue has been addressed differently: Instead of an `only_one` parameter on `__init__`, we now have a `.find()` method that allows searching by name. This provides a cleaner API: ```python # Old concept (not implemented): frame = Frame(name="player", only_one=True) # Would overwrite existing # New approach: existing = ui.find("player") if existing: ui.remove(ui.index(existing)) frame = Frame(name="player") ui.append(frame) # Or simply access/modify existing element directly: player = ui.find("player") if player: player.x = 100 # Modify in place ``` The `.find()` method addresses the core need (finding elements by name) without the complexity of automatic overwriting semantics. See #41 for the full implementation details.
john closed this issue 2025-11-26 10:23:49 +00:00
Sign in to join this conversation.
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: john/McRogueFace#40
No description provided.