.parent quirks #183
Labels
No labels
Alpha Release Requirement
Bugfix
Demo Target
Documentation
Major Feature
Minor Feature
priority:tier1-active
priority:tier2-foundation
priority:tier3-future
priority:tier4-deferred
Refactoring & Cleanup
system:animation
system:documentation
system:grid
system:input
system:performance
system:procgen
system:python-binding
system:rendering
system:ui-hierarchy
Tiny Feature
workflow:blocked
workflow:needs-benchmark
workflow:needs-documentation
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
john/McRogueFace#183
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
setting
.parentseems to add an object as a child, but it doesn't clean it up from an existing parent; moreover, assigning the same parent multiple times results in several references to the same object appearing as children in the parent.Desired behavior:
.parentshould be None only when the object is not in any UIDrawable collection..parentshould return the Scene if the object is a top-level object in a Scene (i.e. being on a Scene is distinct from being "nowhere").parent, removing an object from a collection should consistently perform the other action: single parent, single collection membership..parentto None should have the same effect as removing the object from its parent's collection.Fixed
The following issues have been addressed:
1. Duplicate parent assignments
Setting
.parentmultiple times to the same parent no longer creates duplicate children entries. Theset_parent()function now checks if the drawable is already present in the target parent's collection before adding.2. Grid parent handling
removeFromParent()now properly handles both UIFrame and UIGrid parent types. Previously only Frame parents were supported, so moving a drawable from a Grid to another parent (or setting.parent = None) wouldn't remove it from the Grid's children.Bonus: Fixed #189 regression
While testing, discovered that accessing
frame.childrenorgrid.childrenwas causing a segfault. This was because #189 madeUICollectionan internal type (not exported to module), butget_children()still tried to get it viaPyObject_GetAttrString(module, "UICollection"). Fixed by using the type directly from the namespace.Note: The issue's desired behavior for
.parentreturning Scene for top-level elements was descoped -.parentremainsNonefor scene-level elements, which is consistent and simpler.Regression test
Added
tests/regression/issue_183_parent_quirks_test.pycovering:Scene Parent Tracking Implemented
Added scene-level parent tracking to complete the fix. The
.parentproperty now correctly handles scene-level elements:New Behaviors
scene.children.append())Implementation Details
parent_scenestring field toUIDrawableto track scene ownershipscene_namefield toPyUICollectionObjectfor scene collectionssetParentScene()clears drawable parent,setParent()clears scene parent (mutually exclusive)removeFromParent()now handles both drawable and scene parent removalFiles Modified
src/UIDrawable.h- Addedparent_scenefield andsetParentScene()declarationsrc/UIDrawable.cpp- ImplementedsetParentScene(), updatedremoveFromParent()for scene removalsrc/UICollection.cpp- Updatedappend()to setparent_scenefor scene collectionssrc/McRFPy_API.cpp- Updated_sceneUI()to setscene_nameon returned collectionNote on
.parentreturn valuePer earlier discussion,
.parentreturnsNonefor scene-level elements (not the Scene object itself). This keeps the type system simpler while still enabling proper parent management.Test Results
All 9 tests pass:
Implementation Complete
All three desired behaviors have been implemented:
1.
.parentreturns Scene for top-level elements ✓parent_scenestring field to UIDrawable for scene-level ownership trackingget_parent()now looks up and returns the actual Scene object viaPySceneClass::get_scene_by_name()None2. Single parent, single collection membership ✓
set_parent()callsremoveFromParent()before adding to new parentremoveFromParent()handles Frame, Grid, and Scene parents3. Setting
.parent = Noneremoves from collection ✓Files Modified
src/UIDrawable.h- Addedparent_scenefield,setParentScene()methodsrc/UIDrawable.cpp- Updatedget_parent(),set_parent(),removeFromParent()src/UICollection.cpp- Setparent_scenewhen appending to scene collectionsrc/McRFPy_API.cpp- Track scene name in UICollection forsceneUI()src/PySceneObject.h/cpp- Addedget_scene_by_name()lookup functionRegression Test
tests/regression/issue_183_parent_quirks_test.py- 10 comprehensive tests covering all behaviorsAdditional Enhancement: Direct
.parent = sceneAssignmentAdded support for directly assigning a Scene to
.parent:This also properly removes from existing parents when moving to a Scene:
Updated
set_parent()insrc/UIDrawable.cppto handle Scene type.Regression test expanded to 12 tests covering all parent assignment scenarios.