Theming GTK3 Widgets With CSS

Embed Size (px)

Citation preview

  • 7/29/2019 Theming GTK3 Widgets With CSS

    1/28

    Theming GTK3 widgets with CSS

    Cosimo Cecchi

    Desktop Summit 2011

    August 7, 2011

  • 7/29/2019 Theming GTK3 Widgets With CSS

    2/28

    Agenda

    1 History

    2 CSS

    3 GTK3 Theming

    4 Questions

    Cosimo Cecchi Theming GTK3 widgets with CSS Desktop Summit Berlin 2/29

  • 7/29/2019 Theming GTK3 Widgets With CSS

    3/28

    GTK theming model 10000ft overview

    GTK applications set of widgets

    Widgets drawing functions

    Drawing functions overridden by themes

    GTK theming system GTK engines

    Cosimo Cecchi Theming GTK3 widgets with CSS Desktop Summit Berlin 3/29

  • 7/29/2019 Theming GTK3 Widgets With CSS

    4/28

    GTK2 Theming - Engines

    GTK2 Engines

    implement the gtk paint * methods

    custom engine-specific rendering properties

    access the GtkWidget itself powerful

    Cosimo Cecchi Theming GTK3 widgets with CSS Desktop Summit Berlin 4/29

  • 7/29/2019 Theming GTK3 Widgets With CSS

    5/28

    GTK2 Theming - GtkRC

    Custom text format to describe and configure GTK2 options

    style classes

    set widget style properties and engine custom renderingproperties

    class/widget class/widget name matchers

    association matchers style classes

    Cosimo Cecchi Theming GTK3 widgets with CSS Desktop Summit Berlin 5/29

  • 7/29/2019 Theming GTK3 Widgets With CSS

    6/28

    GTK2 Theming - Problems

    GtkRC base syntax very limited and not expressive

    dozens of very specialized different engines

    modifying an engine is difficult (C code...)

    no standard way to render a desired effect

    no standard way of testing regressions

    accessing GTK internals from the engine

    weak separation between content and presentation

    Cosimo Cecchi Theming GTK3 widgets with CSS Desktop Summit Berlin 6/29

  • 7/29/2019 Theming GTK3 Widgets With CSS

    7/28

    CSS - Universal language

    CSS is a markup language designed to enable separation between adocument content and its presentation semantics

    W3C standard

    well-known syntax, documentation widely available on the web

    natively supports a large superset of the GtkRC features

    no need to worry about whether a feature is supported in aspecific engine

    well-maintained dynamic standard, in continuous evolution

    driven by the web

    Cosimo Cecchi Theming GTK3 widgets with CSS Desktop Summit Berlin 7/29

  • 7/29/2019 Theming GTK3 Widgets With CSS

    8/28

    CSS - Clear semantics

    Using CSS enables a clear disambiguation on the meaning of styleproperties

    style properties semantics are predictable, and can be tested(reftests)

    CSS Box model (padding, margin, border)

    inheritance

    font properties

    shorthand properties

    Cosimo Cecchi Theming GTK3 widgets with CSS Desktop Summit Berlin 8/29

  • 7/29/2019 Theming GTK3 Widgets With CSS

    9/28

    CSS - Cool Effects

    CSS3 specification draft family of appealing/rich visual featuresand effects

    border-image

    box-shadow

    text-shadow

    nth-child and siblings styling support

    gradient support (not yet formalized by W3C, supported as-gtk-gradient in GTK)

    Cosimo Cecchi Theming GTK3 widgets with CSS Desktop Summit Berlin 9/29

  • 7/29/2019 Theming GTK3 Widgets With CSS

    10/28

    CSS - Cool Effects

    Not all the CSS style properties make sense in a toolkit like GTK

    OTOH GTK might need some specific properties which wouldntmake sense in the web

    icon-shadow

    transition

    add your favorite $property here...

    Cosimo Cecchi Theming GTK3 widgets with CSS Desktop Summit Berlin 10/29

  • 7/29/2019 Theming GTK3 Widgets With CSS

    11/28

    GTK3 Theming - GtkStyleContext

    GtkStyleContext GtkStyle on steroids

    application-side interface to drawing and theming

    each widget holds its own different context

    independent from GtkWidget, operates on GtkWidgetPathstructures

    GtkWidgetPath contains information for generic toplevel child widget hierarchies

    easy styling of foreign toolkits (WebKit, QT, ...)

    Cosimo Cecchi Theming GTK3 widgets with CSS Desktop Summit Berlin 11/29

  • 7/29/2019 Theming GTK3 Widgets With CSS

    12/28

    GTK3 Theming - GtkStyleContext

    Style classes.scrollbar .slider + .trough + .button

    conceptually decompose a widget in a set of one or more baseelements

    apply a style to each base widget element

    same widget lots of possibilities without touching code

    .toolbar vs .primary-toolbar

    Cosimo Cecchi Theming GTK3 widgets with CSS Desktop Summit Berlin 12/29

  • 7/29/2019 Theming GTK3 Widgets With CSS

    13/28

    GTK3 Theming - GtkStyleContext

    Widget regionsGtkTreeView row, column, column-header

    number of repeated elements of the same type in a widget notknown

    named class + a set of order-based flagseven, odd, first, last, sorted

    use nth-child to match the desired flag from the CSS

    Cosimo Cecchi Theming GTK3 widgets with CSS Desktop Summit Berlin 13/29

  • 7/29/2019 Theming GTK3 Widgets With CSS

    14/28

    GTK3 Theming - GtkStyleContext

    Native nth-child support in containers

    construct a selector matching the position of an element inrelation to its siblings

    works by default for widgets packed in GtkBox andGtkToolbar

    Cosimo Cecchi Theming GTK3 widgets with CSS Desktop Summit Berlin 14/29

  • 7/29/2019 Theming GTK3 Widgets With CSS

    15/28

    GTK3 Theming - GtkStyleContext

    animatable regions

    of course get/set style properties as GtkStyle used to

    Cosimo Cecchi Theming GTK3 widgets with CSS Desktop Summit Berlin 15/29

  • 7/29/2019 Theming GTK3 Widgets With CSS

    16/28

    GTK3 Theming - GtkThemingEngine

    Theme-side counterpart of GtkStyleContext

    Calls into cairo to do the actual rendering

    Cosimo Cecchi Theming GTK3 widgets with CSS Desktop Summit Berlin 16/29

    GTK3 Th i G kTh i E i

  • 7/29/2019 Theming GTK3 Widgets With CSS

    17/28

    GTK3 Theming - GtkThemingEngine

    Theme-side counterpart of GtkStyleContext

    default implementation inside GTK+

    external theming engines subclass + .so module library

    no access to GTK internals

    access to all the style information stored in GtkStyleContext

    register custom style properties

    Cosimo Cecchi Theming GTK3 widgets with CSS Desktop Summit Berlin 17/29

    GTK3 Th i Th d l

  • 7/29/2019 Theming GTK3 Widgets With CSS

    18/28

    GTK3 Theming - Theme developers

    Where we want to be

    You should not write a GtkThemingEngine subclass unless youhave a very good reason to

    You should be able to do everything you need with CSS and SVGassets

    Cosimo Cecchi Theming GTK3 widgets with CSS Desktop Summit Berlin 18/29

    GTK3 Th i Th d l

  • 7/29/2019 Theming GTK3 Widgets With CSS

    19/28

    GTK3 Theming - Theme developers

    Where we are right now

    Not yet possible to write a full-featured complex theme (e.g.Adwaita) entirely in CSS and SVG

    features missing from GTK

    multiple layer of backgroundsinconsistent focus theming properties

    hard GTK limitations

    not possible to render outside the widget allocation box

    working around widget bugs

    Cosimo Cecchi Theming GTK3 widgets with CSS Desktop Summit Berlin 19/29

    GTK3 Th i Th d l

  • 7/29/2019 Theming GTK3 Widgets With CSS

    20/28

    GTK3 Theming - Theme developers

    Where we are right now

    Not yet possible to write a full-featured complex theme (e.g.

    Adwaita) entirely in CSS and SVG

    But...

    Adwaita is now 90% CSS and SVG

    about 1000 lines of C code

    Cosimo Cecchi Theming GTK3 widgets with CSS Desktop Summit Berlin 20/29

    GTK3 Th i Th d l

  • 7/29/2019 Theming GTK3 Widgets With CSS

    21/28

    GTK3 Theming - Theme developers

    Upstream GTK is very receptive about improving the CSS themingengine and adding support for additional style properties

    if youre writing a custom style property, please consider usinga CSS standard and pushing it upstream

    file bugs, write patches, talk to us

    Cosimo Cecchi Theming GTK3 widgets with CSS Desktop Summit Berlin 21/29

    GTK3 Theming App developers

  • 7/29/2019 Theming GTK3 Widgets With CSS

    22/28

    GTK3 Theming - App developers

    Should applications completely specify a customized look likewebsites do?

    Two schools of thought

    1 applications know better

    2 themes know better

    Cosimo Cecchi Theming GTK3 widgets with CSS Desktop Summit Berlin 22/29

    GTK3 Theming App developers

  • 7/29/2019 Theming GTK3 Widgets With CSS

    23/28

    GTK3 Theming - App developers

    The theme always knows better

    Except when an application really needs to force a completelyunique look altogether

    Cosimo Cecchi Theming GTK3 widgets with CSS Desktop Summit Berlin 23/29

    GTK3 Theming App developers

  • 7/29/2019 Theming GTK3 Widgets With CSS

    24/28

    GTK3 Theming - App developers

    The theme always knows better

    hardcoded colors in applications basically unthemable

    the engine lacks constructs to fully describe a complex layout

    to matchthe first sidebar left of a view widget

    CSS3 has such constructs (nth-child and friends) - weshould extend our support for them

    special-casing app widgets or layouts in the theme instead ofhardcoding theme information in the apps

    Cosimo Cecchi Theming GTK3 widgets with CSS Desktop Summit Berlin 24/29

    GTK3 Theming App developers

  • 7/29/2019 Theming GTK3 Widgets With CSS

    25/28

    GTK3 Theming - App developers

    When an app needs to force an unique look altogether...

    Pro-oriented (e.g. Ardour)

    Games, educational or unconventionalSpecial accessibility requirements

    using a custom CSS theme makes a lot of things very easy

    apps could even install and use their own theming enginemodule to bypass the default gtk render * implementations

    Cosimo Cecchi Theming GTK3 widgets with CSS Desktop Summit Berlin 25/29

    GTK3 Theming - Future

  • 7/29/2019 Theming GTK3 Widgets With CSS

    26/28

    GTK3 Theming - Future

    drop Raleigh as default GTK theme (?!)

    integrate documentation for the style classes defined by stockwidgets

    tie style classes to HIG 3.0 recommendationsmultiple background compositing

    sanity-check our implementation of focus theming

    easier theming for GtkCellRenderers

    Cosimo Cecchi Theming GTK3 widgets with CSS Desktop Summit Berlin 26/29

    GTK3 Theming - Blue sky future

  • 7/29/2019 Theming GTK3 Widgets With CSS

    27/28

    GTK3 Theming - Blue sky future

    fully implement the CSS box-model logic in GTK

    make every widget capable of rendering a frame and a

    backgroundimproved use of implicit animations

    Cosimo Cecchi Theming GTK3 widgets with CSS Desktop Summit Berlin 27/29

  • 7/29/2019 Theming GTK3 Widgets With CSS

    28/28

    Thanks for attending

    Questions?

    Cosimo Cecchi Theming GTK3 widgets with CSS Desktop Summit Berlin 28/29