Update child controls style when a control is restyled#6264
Update child controls style when a control is restyled#6264eoineoineoin wants to merge 5 commits intospace-wizards:masterfrom
Conversation
|
This should really check if the control is possibly involved in a child selector, and only do the recalculation in that case. |
|
Also, while I admit I'm pointing this out due to self-interest, as it affects switch buttons. But I do think having children update automatically is likely to be more generally useful. And the comment on the workaround in |
I agree with the sentiment - in 2e1c831, I added this; doesn't feel great, but would also worry that doing something more sophisticated would add a lot of complexity.
Nice spot! I've removed the workaround since whatever solution we land on should obsolete that. The only other thing in Content (right now, at least) which uses parent selectors is hud tooltips, which wouldn't ever have their styles changed after construction. |
|
I think I have worked out how to work around the lack of this for switch buttons; I can apply relevant pseudoclasses to the buttons' children and change the style rules accordingly. I'm going to put off actually implementing that for the moment, though, in hopes that this gets merged and saves me from having to. |
I have implemented a workaround in switch buttons. It ended up being a bit messier than I'd hoped, so I'm definitely still hoping this change will some day remove the need for workarounds. |
| @@ -24,11 +24,6 @@ public Button() | |||
| protected override void StylePropertiesChanged() | |||
Mildly-controversial PR incoming.
I was looking to fix space-wizards/space-station-14#40923 - in that issue, the problematic element is a
CollapsibleHeading. TheCollapsibleHeadingis aContainerButtonwith a childTextureRect, which is what is used to display the triangles.So, the following style rules should do the trick. Use
collapsedTexturenormally, butexpandedTexturewhen the heading has been pressed:However, this only works once, and can't be changed once the
CollapsibleHeadingis visible. Pressing theCollapsibleHeadingwill toggle it's pressed pseudo state, which causes theCollapsibleHeadingto be restyled. However, the style rules are targetting the childTextureRect, which never gets queued to refresh it's style.This PR enqueues a style update for any child
Controls whenever a parentControl's style is updated. Potentially, this is a bunch more style re-evalulations, but not sure there's a cleverer way to do this, sinceSelector.Matchescould be doing anything, so no real way to know if child styles are affected.