Support #5865
openAdding and Removing Rules with WCssStyleSheet
0%
Description
Hi,
I'm trying to use the internal stylesheet to dynamically update the appearence of a template (divs that are not mapped to Wt widgets). I'm probably missing something as you can see from the following questions:
When adding a rule to the internal stylesheet one might supply a name which may be used to detect (WCssStyleSheet::isdefined()) wether it is already set.
But after removing that rule WCssStyleSheet::isdefined() still returns true. Is that a bug?
How can I change a rule? There is a function WCssRule::modified() but I found no way to achieve the modification.
To remove a rule I have to keep track of the pointers returned from "WCssStyleSheet::addRule". I would have expected a getter like "getRuleByName" and a way to change the declarations of a rule.
What do I miss?
The widgets I want to style in this way are divs of complex flex layouts which - as far as I know - can not be mapped to Wt-widgets if I do not use Wt-layouts to manage their content. That's why I do not use external stylesheets and addStyleClass in this case.
Thanks for any advice?
Regards,
Heiko
Updated by Wim Dumon over 7 years ago
Hello Heiko,
We usually don't edit stylesheets to modify the looks of a widget, but add CSS rules for the possible visual states and apply the appropriate style classes to widgets when they should be displayed differently. In many cases, the use of an appropriate CSS selector will allow you to modify the style class on the WTemplate so that a div (with a styleclass) inside the WTemplate changes appearance. If you need more fine-grained control, you can set a style class that is a var and use bindstring to modify the style class:
<message ..>
<div class="${div-class}">blah</div>
</message>
if (...)
template->bindString("div-class", "important");
else
template->bindString("div-class", "not-so-important");
I see that using the WCssStyleSheet class to modify stylesheets can be confusing. Originally it wasn't intended to be used in such a way, but all methods seem to be present to allow it, a bit poorly.
Best regards,
Wim.
Updated by Heiko Gerdau over 7 years ago
Many thanks Wim,
I wasn't aware that I may use WTemplate::bindString dynamically again and again on the same variable. Nice.
Although this solves my problems I still think WCssStyleSheet::isdefined() should be based on a map not on a set which looses the name<->rule connection.
Regards,
Heiko