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_WITH_STYLE#
The code below draws "Hello" label with red background and centered alignment, and "World" label with blue background, using AUI_WITH_STYLE:
using namespace ass;
setContents(Centered{
Label { "Hello" } AUI_WITH_STYLE {
BackgroundSolid { AColor::RED },
TextAlign::CENTER,
},
Label { "World" } AUI_WITH_STYLE {
BackgroundSolid { 0x0000ff_rgb },
},
})
Using setCustomStyle#
In case AUI_WITH_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 { "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#
-
Controls the expanding of AView.
-
Controls the text transform of AView.
-
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.
-
Specifies text floating in text wrapping views, i.e, ATextArea, AText.
-
Controls the text alignment inside AView.
-
Controls the text vertical alignment of AView.
-
Controls screen orientation.
-
Controls the image rendering type.
-
Wraps another selector matching Selected views.
-
Hovered LESS-style subselector.
-
Activated LESS-style subselector.
-
Focused LESS-style subselector.
-
Disabled LESS-style subselector.
-
Represents solid (single color) background.
-
Represents border.
-
Determines sizing rules of a background texture (BackgroundImage).
-
Represents textured (image) background.
-
Controls the expanding 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.
-
Represents custom-rendered background effect.
-
Controls the font family of AView.
-
Represents gradient background.
-
Represents box shadow.
-
Controls the font size of AView.
-
Controls the text border of AView.
-
Controls background texture cropping by exact UV coordinates. Useful for texture atlases.
-
Controls the text color of AView.
-
Represents box shadow.
-
Represents backdrop filter effect which applied to the pixels behind the view (i.e., blur, grayscale, etc.)
-
Controls the padding of AView.
-
Controls the rendering offset transform of AView.
-
Custom property with user-defined handlers.
-
Controls line height multiplier of the font of the AView.
-
Controls border radius.
-
Represents left border.
-
Controls the text shadow of AView.
-
Represents right border.
-
Controls the opacity of AView.
-
Represents bottom border.
-
Controls the font of AView.
-
Controls how do scrollbars and content appear in AScrollArea. This rule is applicable to AScrollArea only.
-
Controls the rendering scale transform of AView.
-
Base class for all properties.
-
Controls the max size of AView.
-
Represents top border.
-
Controls view's margins.
-
Controls the rendering offset transform of AView.
-
Controls the fixed size of AView.
-
Controls the min size of AView.
-
Represents cursor type.
-
Produces sound effect when the style applied.