Skip to content

masonry: allow swapping tree-wide default properties at runtime#1821

Open
mark-ik wants to merge 1 commit into
linebender:mainfrom
mark-ik:masonry-swap-default-properties
Open

masonry: allow swapping tree-wide default properties at runtime#1821
mark-ik wants to merge 1 commit into
linebender:mainfrom
mark-ik:masonry-swap-default-properties

Conversation

@mark-ik
Copy link
Copy Markdown

@mark-ik mark-ik commented May 29, 2026

Scope
Touches masonry_core (the method), masonry_testing (a one-line TestHarness::set_default_properties passthrough for the test), and masonry (the test).

Background
DefaultProperties is fixed at construction, so a host that wants to re-theme a running app (e.g. a light/dark theme toggle re-coloring widgets that rely on default ContentColor / Background) cannot do so today without restarting.

Fix
This PR adds RenderRoot::set_default_properties, which swaps the arena's default properties. It iterates over the tree flagging every widget and invalidating each property cache so the update-props pass re-fires Widget::property_changed. Each widget's handler (with the built-in core_property_changed) then requests whatever paint or layout that property needs.

A defaults swap does not change a defaulted property's resolved stack index (only its fallback value); the cache invalidation is what triggers the per-entry re-fire of property_changed.

Testing
Also adds a TestHarness::set_default_properties passthrough and a test (set_default_properties_refires_property_changed in masonry/src/tests/update.rs) that (1) seeds a cached ContentColor read, (2) swaps defaults, and (3) asserts property_changed re-fires for the cached type. The test fails against the fluke fix I made earlier (in issue #1819).

Disclosure: AI-assisted; my responsibility.

Relevant issues:

#1819: closes
#1765: related, leaves background_color(), system light/dark detection, and the per-widget override API to that issue.
#1786: related, leaves per-widget-type styling for later.

Copilot AI review requested due to automatic review settings May 29, 2026 22:16
Comment thread masonry_core/src/app/render_root.rs
@PoignardAzur
Copy link
Copy Markdown
Contributor

The test fails against the fluke fix I made earlier (in issue #1819).

Nice.

Comment thread masonry/src/tests/update.rs Outdated
Comment thread masonry_core/src/app/render_root.rs
@mark-ik mark-ik force-pushed the masonry-swap-default-properties branch from 3022aa0 to e6987c5 Compare May 30, 2026 13:44
@mark-ik
Copy link
Copy Markdown
Author

mark-ik commented May 30, 2026

Ok, comment block truncated, and self.run_rewrite_passes(); is in! Thank you! I'll save closing #1819 for when the next PR (Xilem) merges.

`DefaultProperties` is fixed at construction, so a host that wants to
re-theme a running app (e.g. a light/dark toggle re-coloring widgets that
rely on default `ContentColor` / `Background`) cannot do so today without
rebuilding.

Add `RenderRoot::set_default_properties`, which swaps the arena's default
set and re-runs the update-properties pass over the whole tree: it marks
every widget and invalidates each property cache, so the pass re-fires
`Widget::property_changed` for every cached property. Each widget's handler
(with the built-in `core_property_changed`) then requests whatever paint or
layout that property needs. A defaults swap does not change a defaulted
property's resolved stack index (only its fallback value), so the cache
invalidation is what forces the per-entry re-fire.

Also adds a `TestHarness::set_default_properties` passthrough and a test
that seeds a cached `ContentColor` read, swaps defaults, and asserts
`property_changed` re-fires for the cached type. The test fails against
the bare-repaint version, so it guards the propagation invariant.

Signed-off-by: Markik <54276851+mark-ik@users.noreply.github.com>
@mark-ik mark-ik force-pushed the masonry-swap-default-properties branch from e6987c5 to d457d22 Compare May 30, 2026 18:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants