Aui Style Sheets#
CSS-like styling system
Detailed Description#
AUI uses CSS-like stylesheet domain specific language, ASS (stands for Aui Style Sheets). Like CSS, ASS is a list
of rules. A rule consists of a ass_selectors and a list of ass_properties . Selector is a basic matcher
that determines whether apply a rule to the specific view or not. Selector is the first statement in a
rule and further statements are style properties.
Property controls the specific aspect of view's style (i.e. FontSize { 18_pt } equals
"call setFontSize(18_pt) for every matched view").
| CSS | AUI ASS | Meaning |
|---|---|---|
|
Set all buttons' background to red and text color to white | |
|
|
Set all text fields' border to #00f (blue) on hover |
Using global style#
Global stylesheet is applied to the whole program.
Somewhere in your entry point, you may write:
AStylesheet::global().addRules({
{
t<ALabel>(),
BackgroundSolid { AColor::RED },
TextAlign::CENTER,
},
{
t<AButton>(),
BackgroundSolid { 0x000000_rgb },
TextAlign::CENTER,
},
});
Using container stylesheet#
Container stylesheet is applied only to children (both direct and indirect) of the container.
container->setExtraStylesheet({
{
t<ALabel>(),
BackgroundSolid { AColor::RED },
TextAlign::CENTER,
},
{
t<AButton>(),
BackgroundSolid { 0x000000_rgb },
TextAlign::CENTER,
},
});
Using AUI_OVERRIDE_STYLE#
The code below draws "Hello" label with red background and centered alignment, and "World" label with blue background, using AUI_OVERRIDE_STYLE:
using namespace ass;
setContents(Centered{
Label { "Hello" } AUI_OVERRIDE_STYLE {
BackgroundSolid { AColor::RED },
TextAlign::CENTER,
},
Label { "World" } AUI_OVERRIDE_STYLE {
BackgroundSolid { 0x0000ff_rgb },
},
})
Using setCustomStyle#
In case AUI_OVERRIDE_STYLE is not applicable, you may use setCustomStyle instead.
using namespace ass;
auto l = _new<ALabel>("Hello world");
l->setCustomStyle({
BackgroundSolid { AColor::RED },
TextAlign::CENTER,
}),
setContents(Centered{ l });
Selectors#
As said earlier, first statement in a rule is selector. Here's some examples.
Select all ALabels#
using namespace ass;
AStylesheet::global().addRules({
{
t<ALabel>(),
BackgroundSolid { AColor::RED },
TextAlign::CENTER,
},
});
Select all ASS name#
using namespace ass;
AStylesheet::global().addRules({
{
c(".highlight"),
BackgroundSolid { AColor::RED },
TextAlign::CENTER,
},
});
// ...
auto v = _new<AView>();
v->addAssName(".highlight");
setContents(Centered { v });
// or
setContents(Centered {
_new<AView>() << ".highlight",
});
Select all ALabel's or AButton's#
using namespace ass;
AStylesheet::global().addRules({
{
{t<ALabel>(), t<AButton>()},
BackgroundSolid { AColor::RED },
TextAlign::CENTER,
},
});
Select all labels with ASS name#
using namespace ass;
AStylesheet::global().addRules({
{
t<ALabel>() && c(".highlight"),
BackgroundSolid { AColor::RED },
},
});
// ...
setContents(Centered {
Label { "Highlighted" } << ".highlight",
Label { "Not highlighted" },
Button { Label { "Not highlighted either" } },
});
Select indirect child#
using namespace ass;
AStylesheet::global().addRules({
{
c(".highlight_container") >> t<ALabel>(),
BackgroundSolid { AColor::RED },
TextAlign::CENTER,
},
});
// ...
setContents(Centered {
Vertical {
Label { "Highlighted" },
Centered { Label { "Highlighted" } },
} << ".highlight_container",
Vertical {
Label { "Not highlighted" },
},
});
Select direct child#
Works faster than selecting indirect child
using namespace ass;
AStylesheet::global().addRules({
{
c(".highlight_container") > t<ALabel>(),
BackgroundSolid { AColor::RED },
TextAlign::CENTER,
},
});
// ...
setContents(Centered {
Vertical {
Label { "Highlighted" },
Centered { Label { "Not highlighted" } },
} << ".highlight_container",
Vertical {
Label { "Not highlighted" },
},
} << ".highlight_container");
Sub selectors#
Sub selector is kind of a selector that depends on view's state (i.e, pressed or focused). Sub selectors, as well as other selectors don't replace previous rules entirely. Instead, they extend existing rules. However, same properties are replaced.
Hover sub selector#
Hovered view is a view below mouse cursor.
using namespace ass;
AStylesheet::global().addRules({
{
t<ALabel>::hover(),
BackgroundSolid { AColor::RED },
TextAlign::CENTER,
},
});
Active sub selector#
Active view is a pressed view.
using namespace ass;
AStylesheet::global().addRules({
{
t<ALabel>::hover(),
BackgroundSolid { AColor::RED },
},
});
Focus sub selector#
Focused view is a view that was clicked and currently receiving keyboard input.
using namespace ass;
AStylesheet::global().addRules({
{
t<ALabel>::focus(),
Border { 1_px, AColor::RED },
TextColor { AColor::RED },
},
});
Disabled sub selector#
Disabled view is a view with AView::setEnabled(false) thus not able to change it's state.
using namespace ass;
AStylesheet::global().addRules({
{
t<ALabel>::disabled(),
Border { 1_px, AColor::RED },
TextColor { AColor::RED },
},
});
Box Model (Padding, Margin)#
See AUI Box Model.
ASS Refenence#
See below for declarations and selectors.
Related Pages#
-
Produces sound effect when the style applied.
-
Controls the image rendering type.
-
Specifies text floating in text wrapping views, i.e, ATextArea, AText.
-
Controls the text transform of AView.
-
Controls the text vertical alignment of AView.
-
Controls screen orientation.
-
Controls visibility of the overflowed contents of AView with AView::drawStencilMask.
-
Controls behavior of the overflowed text. Relevant to AAbstractLabel and its derivatives only.
-
Controls the behaviour of the default AView::drawStencilMask() implementation.
-
Controls the text alignment inside AView.
-
Controls the opacity of AView.
-
Represents box shadow.
-
Controls the padding of AView.
-
Controls the rendering offset transform of AView.
-
Represents solid (single color) background.
-
Controls the expanding of AView.
-
Controls the fixed size of AView.
-
Represents top border.
-
Represents custom-rendered background effect.
-
Base class for all properties.
-
Indicates that the value for this property should be inherited from parent view.
-
Custom property with user-defined handlers.
-
Controls the max size of AView.
-
Controls line height multiplier of the font of the AView.
-
Controls the rendering offset transform of AView.
-
Determines sizing rules of a background texture (BackgroundImage).
-
Represents textured (image) background.
-
Controls background texture cropping by exact UV coordinates. Useful for texture atlases.
-
Represents gradient background.
-
Controls how do scrollbars and content appear in AScrollArea. This rule is applicable to AScrollArea only.
-
Controls the font of AView.
-
Controls the font size of AView.
-
Represents left border.
-
Controls the text shadow of AView.
-
Controls the text color of AView.
-
Controls border radius.
-
Controls view's margins.
-
Represents border.
-
Represents right border.
-
Represents backdrop filter effect which applied to the pixels behind the view (i.e., blur, grayscale, etc.)
-
Controls the min size of AView.
-
Represents bottom border.
-
Controls the rendering scale transform of AView.
-
Controls the gap between elements of the container. Basically acts like a margin, but the gaps appear between views only, not around them.
-
Controls the text border of AView.
-
Controls the font family of AView.
-
Represents box shadow.
-
Hovered LESS-style subselector.
-
Activated LESS-style subselector.
-
Focused LESS-style subselector.
-
Disabled LESS-style subselector.
-
Wraps another selector matching Selected views.
-
Controls how fonts are rendered in the view.
-
Represents cursor type.