Skip to content

xilem: WindowView::with_default_properties for runtime theme swap#1822

Open
mark-ik wants to merge 2 commits into
linebender:mainfrom
mark-ik:xilem-with-default-properties
Open

xilem: WindowView::with_default_properties for runtime theme swap#1822
mark-ik wants to merge 2 commits into
linebender:mainfrom
mark-ik:xilem-with-default-properties

Conversation

@mark-ik

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

Copy link
Copy Markdown
Contributor

Scope
One file: xilem/src/window_view.rs.

Background
[RenderRoot::set_default_properties] (added in #1821) lets a host swap the tree-wide default property set at runtime, but it's only reachable from code that holds a RenderRoot. Xilem apps go through WindowView, so they can't reach the new method at the moment.

Fix
Adds WindowView::with_default_properties(Arc<DefaultProperties>). The new set gets pushed to the render root in rebuild only when the Arc identity changes (Arc::ptr_eq), so steady-state frames don't re-apply. None (the default) leaves the startup set untouched.

Testing
No tests in this PR. Xilem doesn't have masonry's TestHarness, and the propagation invariant is already covered by the test that landed with #1821. Anecdotally, when applied to my fork in my app, a theme toggle correctly recolors ContentColor-defaulted widgets without restart. I have screenshots or screen recordings available if desired.

Disclosure: AI-assisted; still my responsibility.

Closes #1819.

Relevant issues:

Surfaces `RenderRoot::set_default_properties` (added in linebender#1821) reactively
on `WindowView`, so a Xilem app can swap its theme's default property set
mid-session without restarting.

`WindowView` gains a reactive `default_properties: Option<Arc<DefaultProperties>>`
field plus `with_default_properties(..)`. The new set is pushed to the
render root in `rebuild` only when the `Arc` identity changes
(`Arc::ptr_eq`), so steady-state frames don't re-apply. `None` (the
default) leaves the startup set untouched.

Signed-off-by: Markik <54276851+mark-ik@users.noreply.github.com>
mark-ik added a commit to mark-ik/xilem that referenced this pull request May 31, 2026
Trim verbose field/builder docs and replace the match-style rebuild
block with the upstream-idiomatic if-let chain + `is_none_or`, matching
linebender#1822. Behavior unchanged; verified live: woodshed theme
toggle still recolors default-driven widgets.
@mark-ik
mark-ik marked this pull request as ready for review May 31, 2026 21:22
Copilot AI review requested due to automatic review settings May 31, 2026 21:22

@PoignardAzur PoignardAzur left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Comment thread xilem/src/window_view.rs
Comment on lines +127 to +134
if let Some(props) = &self.default_properties
&& prev
.default_properties
.as_ref()
.is_none_or(|p| !Arc::ptr_eq(p, props))
{
window.render_root().set_default_properties(props.clone());
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is fine for now, but I'd add a TODO comment to mention the case where default_properties go from Some to None.

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.

Runtime theme switching: swap DefaultProperties without a restart

2 participants