[][src]Module pixel_widgets::stylesheet

Styling system

Style in pixel-widgets is defined using stylesheets. These stylesheets are loaded from a file, with a format that is a syntactically a subset of css. The stylesheets are called pwss - pixel-widgets stylesheets.

Features

  • Select widgets, .classes and :states
  • Select child widgets, sibling widgets

Example

This example is not tested
column {
    align-horizontal: center;
}

button {
    background: #444;
    padding: 5;
}

button:hover {
    background: #666;
}

button:pressed {
    background: #222;
}

button:hover > text {
    color: #f00;
}

text {
    text-size: 24;
}

The example sets a few properties on some of the widgets. Just try it out with the examples in the example directory and see for yourself what the effect is.

Syntax

Each pwss file contains a collection of rules. Rules are a group of declarations that are applied to selected widgets.

Rules

A selector has the following format:

This example is not tested
<selector> <selector> ... {
    <property>: <value>;
    <property>: <value>;
    ...
}

The first line expects some selectors. Class selectors can be differentiated from widget selectors by adding a period in front, as in .class, and state selectors have a ':' in front.

This example is not tested
window column button {
    background: @button.png;
}

Entering multiple selectors like in this example will look for a button inside a column inside a window.

Selectors

This table describes the supported selectors

selectorexampledescription
**selects all widgets
widgettextselects all text widgets
.class.fancyselects all widgets that have the class "fancy"
.. widget.fancy textselects all text widgets that are a descendant of a "fancy" classed widget
>widget.fancy > textselects all text widgets that are a direct child of a "fancy" classed widget
+widget.fancy + textselects all widgets that follow directly after a "fancy" classed widget
~widget.fancy ~ textselects all widgets that follow after a "fancy" classed widget
:statebutton:hoverselects all buttons that are hovered by the mouse
:nth-child(n)text:nth-child(2)selects text widgets that are the third child of their parent
:nth-last-child(n)text:nth-last-child(2)selects text widgets that are the third child of their parent, counted from the last widget
:nth-child(odd)text:nth-child(odd)selects text widgets that are an odd child of their parent
:nth-child(even)text:nth-child(even)selects text widgets that are an even child of their parent
:not(selector)button:not(:pressed)selects button widgets that are not pressed
:only-childcolumn > *:only-childselects the only child of a column when the column has only one child

Properties

The interior of a rule consists of a number of declarations. These declarations are what specifies style. A declaration starts with a property, and each property has it's own associated format. Take a look at the table to see what properties exist.

keydescriptionformat
widthwidget widthsize
heightwidget heightsize
backgroundBackground for the widget that full covers the layout rectbackground
paddingAmount of padding to use on each side of the contentrectangle
padding-leftAmount of padding to use on the left side of the contentnumber
padding-rightAmount of padding to use on the right side of the contentnumber
padding-topAmount of padding to use on the top side of the contentnumber
padding-bottomAmount of padding to use on the bottom side of the contentnumber
marginAmount of margin to use on each side of the widgetrectangle
margin-leftAmount of margin to use on the left side of the widgetnumber
margin-rightAmount of margin to use on the right side of the widgetnumber
margin-topAmount of margin to use on the top side of the widgetnumber
margin-bottomAmount of margin to use on the bottom side of the widgetnumber
fontFont to use for text renderingurl
colorColor to use for foreground drawing, including textcolor
text_sizeSize of textnumber
text_wrapWrapping strategy for texttextwrap
layout-directionLayout direction for widgets that support itdirection
align_horizontalhow to align children horizontallyalign
align_verticalhow to align children verticallyalign

Value syntax

TypeSyntaxNotes
color#rgb
#rgba
#rrggbb
#rrggbbaa
Examples:
#fff
#ff00ff
url"filename"An url in between quotes
"image.png"
"font.ttf"
numberfloating point literalA number, such as 2.0 or 42
background<url>
<color>
image(<url>, <color>)
patch(<url>, <color>)
none
If a url ends with .9.png it will be resolved as a 9 patch.
If your 9 slice doesn't end with .9.png, use patch.
rectangle<num>
<num> <num>
<num> <num> <num>
<num> <num> <num> <num>
all sides
top/bottom, right/left
top, right/left, bottom
top, right, bottom, left
textwrapno-wrap
wrap
word-wrap
size<number>
fill(<number>)
exact(<number>)
shrink
Just a number resolves to exact
directiontop-to-bottom
left-to-right
right-to-left
bottom-to-top
alignbegin
center
end

Structs

Style

A style loaded from a .pwss file.

Stylesheet

A fully resolved stylesheet, passed by reference to Widget::draw. Contains the final versions of all possible rules.

Enums

Declaration

A property and a value

Error

Errors that can be encountered while loading a stylesheet

Selector

A stylesheet selector, which widgets have to match against.

SelectorWidget

Widget name as used in a Selector.

StyleState

Widget states