CSS: inheriting styles in the OO sense (was: Are more font variants in the pipeline?)
David Grieve
david.grieve at oracle.com
Thu Aug 23 08:18:19 PDT 2012
Not a bad idea. Certainly the idea has merit and there is a W3C working draft on CSS Selectors 4 so maybe this could be proposed.
For JavaFX purposes, it might be possible to use a functional pseudo-element to accomplish this:
.my-specific-label-style::-fx-inherit(.my-base-label-style) { … }
The function syntax could allow multiple args for your multiple inheritance. Declarations would be copied from the inherited rules in the order given in the args (thus, later declarations override earlier ones) but coming before the declarations in the child rule.
As an alternative, it would be fairly straight forward to pre-process a file with suitable "extends" syntax and generate a new file with all of the "inherited" declarations rolled into the normalized selector that would be parseable by standard CSS syntax.
It never hurts to create a feature request so ideas like these aren't lost.
On Aug 23, 2012, at 9:19 AM, Daniel Zwolenski wrote:
> This is maybe a good opening to ask what the thoughts would be on adding some stuff beyond web-css, in particular "inheritance" (in the OO sense, not the containment sense that CSS already supports).
>
> So if I have a base style like:
>
> .my-base-label-style {
> -fx-font: 15px "Open Sans";
> -fx-background-color: red;
> }
>
> Then we have specific instances that then extend this, and override as needed:
>
> .my-specific-label-style extends my-base-label-style {
> -fx-border: 1px solid green;
> -fx-background-color: red;
> }
>
> (syntax used is for descriptive purposes only, not a suggestion).
>
> So the resulting styles would be the merged set of these two (with the base class overriding the parent class styles).
>
> This would mean we could avoid adding both styles in the code, and just add the actual specific class (which implies the base class), which means styling is kept nicely in the stylesheet. If I want to change my button to not use the base class, that's a CSS change, not a code change.
>
> Multiple inheritance would be bonus points (where each 'extends' overrides the last).
>
> I don't know the ramifications of doing this and if it is possible in the JFX implementation. I just know this type of usage is something I have often wanted and wondered about.
>
> If 'extends' style doesn't work, what about an -fx-base-class attribute:
>
> .my-specific-label-style {
> -fx-base-class: my-base-label-style1, my-base-label-style2;
> -fx-border: 1px solid green;
> -fx-background-color: red;
> }
>
> Bad idea?
>
>
David Grieve | Principal Member of Technical Staff
Mobile: +16033121013
Oracle Java Client UI and Tools
Durham, NH 03824
Oracle is committed to developing practices and products that help protect the environment
More information about the openjfx-dev
mailing list