Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [nebula-dev] Custom Widget Toolkit

Jeremy Dowdall schrieb:
> Hi Tom,
> 
> I spent some time this evening looking at the docs for Qt's Style Sheet
> implementation and it looks really good.  Some basic CSS handling is
> already in the SVG code; breaking it out and exposing it for use with
> something like this is certainly doable - the Qt work would be a good
> reference to start from, do you have any others that you've seen and
> think are good examples?

As said in UFaceKit we have a parser definition for CSS and a custom
markup language named USML (UFaceKitStylingMarkupLanguage). I'm not
proposing here that CWT writes an CSS-Parser and the logic which style
applies to which control.

I propose that we provide an API which makes it possible for external
styling frameworks to control the L&F of our controls. So IMHO the only
thing we need to provide is the setStylesheet-Method and the
styledefinition parser which translates something like:

background-color: #FF0000 into a object instance implementors of a
widget can easily use. We could also provide ResourceHandling for
Images, Fonts and Colors so that the widget implementor doesn't has to
take core of them (In UFaceKit we have ResourceManagers who using
ref-counting to keep native resources only as long as needed).

> 
> Are you thinking that this would be just for CWT based custom widgets,
> or would this also be used as a theming engine to set the styles on SWT
> controls as well?

No only for CWT controls not SWT ones (Why not SWT see below).

> 
> Also, can you fill me in a little on where E4 is with theming and
> styling?  How do you see this fitting in with that work?
> 

E4 has already a CSS-Parser and a framework to apply those styles to
SWT-Widgets but because they don't own the widgets themselves (the
SWT-Team owns it :-) they need to use the public API (e.g. to draw a
gradient they need to create an image on the fly and set it as the
background-image).


Just a short idea how this could look like:

public interface StyledWidget {
   public void setStylesheet(String stylesheet);
   public void setStyle(CSSStyle style);
}

public class CSSStyle {
   private Color backgroundColor;
   private CWidget widget;

   private static Color getColor(backgroundColor) {
       // parse color
   }

   public void setBackgroundColor(String backgroundColor) {
      this.backgroundColor = getColor();
      // Inform widget about new color
   }

   Color getBackgroundColor() {
       return backgroundColor;
   }
}


public class CWidget implements StyledWidget {
   private CSSStyle currentStyle;

   public void setStylesheet(String stylesheet) {
        // Should be moved to a delegate
        StringTokenizer tk = new StringTokenizer(stylesheet,";");
        CSSStyle style = new CSSStyle();

        while( tk.hasMoreElements() ) {
           String[] parts = tk.nextToken().split(":");

           if( parts[0].equals("background-color") ) {
             style.setBackgroundColor(parts[1].trim());
           } // ...
        }
   }
}

This is a just a short mock up the whole system is only a bit more
complex (e.g. how the widget is informed about style-changes, ...).

Tom


Back to the top