stathissideris/clarity — comment on commit e975b3a61130e4ce7f03e9860ab60e1e692d25b2
File:  line 0
By daveray:

On Fri, Feb 10, 2012 at 7:24 PM, Stathis Sideris

wrote:
> Well, the main problem is *when*. The way the (make) macro works in
> clarity, I would have to apply the stylesheet at creation time. The
> stylesheet mechanism starts with the root and tests each of the
> members of the component hierarchy on whether they match any of the
> rules, and applies the different looks when applicable. The problem
> with that is that when it's just been created, the component is empty,
> so nothing happens (unless the root itself matches, in which case
> itself is configured but non of its children that are added later). My
> solution to that was to add a ContainerListener and listen for
> componentAdded events, and apply the same stylesheet to each one of
> them as they were being added.

It seems to boil down to the fact that unlike the DOM in a browser
it's really hard to know when a widget is added/removed from the
hierarchy... and as a bonus, there can be multiple hierarchies at the
same time.

I wonder if you could use the ContainerListener approach, but queue up
all of the changes and then apply them all at once with invokeLater or
something. That would (mostly) eliminate duplicate applications of the
stylesheet.

> The problem with this solution is that it has the potential to result
> in the same stylesheet being applied to the component more than once
> (although now that I think about it, maybe not). This should never
> happen, because styles in clarity are just a bunch of "mutators",
> basically a bit of code that can contain anything (for example a
> "style" could add a listener that changes the background on mouse
> over) and definitely has side-effects, so "applying" it twice to a
> component could have unforeseen and hard to debug consequences.

Yep. It seems like it's best to have the requirement that styles be
idempotent so applying them multiple times won't hurt anything.

> Does that make sense?

Yep. Thanks!