[Documentation] Color sub-property assignment doesn't propagate (expected behavior) #174

Closed
opened 2026-01-04 04:58:33 +00:00 by john · 0 comments
Owner

Summary

Assigning to color sub-properties like caption.fill_color.g = 128 doesn't work - the change is lost. This is expected behavior due to how Python C extensions work, but should be documented.

Cause

When you access obj.fill_color, the getter returns a new PyColor object containing a copy of the sf::Color. Modifications to that copy don't affect the original.

cap.fill_color.g = 128  # This is actually:
                        # temp = cap.fill_color  (creates copy)
                        # temp.g = 128           (modifies copy)
                        # (temp discarded)       (changes lost)

Workarounds

1. Get, modify, set back

color = caption.fill_color
color.g = 128
caption.fill_color = color

2. Use Animation for sub-properties (works correctly)

anim = mcrfpy.Animation('fill_color.g', 128, 0.0, 'linear')
anim.start(caption)

Possible Enhancements

  1. Add component properties: fill_color_r, fill_color_g, etc. directly on drawables
  2. Bound color objects: Colors that remember their parent and propagate changes
  3. set_color() method: caption.set_fill_color(g=128) with keyword args

Action Items

  • Document workaround in Color class docstring
  • Document workaround in fill_color property docstrings
  • Consider adding component properties in future
## Summary Assigning to color sub-properties like `caption.fill_color.g = 128` doesn't work - the change is lost. This is **expected behavior** due to how Python C extensions work, but should be documented. ## Cause When you access `obj.fill_color`, the getter returns a **new** PyColor object containing a **copy** of the sf::Color. Modifications to that copy don't affect the original. ```python cap.fill_color.g = 128 # This is actually: # temp = cap.fill_color (creates copy) # temp.g = 128 (modifies copy) # (temp discarded) (changes lost) ``` ## Workarounds ### 1. Get, modify, set back ```python color = caption.fill_color color.g = 128 caption.fill_color = color ``` ### 2. Use Animation for sub-properties (works correctly) ```python anim = mcrfpy.Animation('fill_color.g', 128, 0.0, 'linear') anim.start(caption) ``` ## Possible Enhancements 1. **Add component properties**: `fill_color_r`, `fill_color_g`, etc. directly on drawables 2. **Bound color objects**: Colors that remember their parent and propagate changes 3. **set_color() method**: `caption.set_fill_color(g=128)` with keyword args ## Action Items - [x] Document workaround in Color class docstring - [x] Document workaround in fill_color property docstrings - [ ] Consider adding component properties in future
john closed this issue 2026-01-04 05:01:10 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
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#174
No description provided.