rule

Create a style rule for the given node.

Template parameters are used to select the node the rule applies to, based on its type and the tags it has. Regular parameters define the changes made by the rule. These are created by using automatically defined members of Rule, which match names of Style fields. For example, to change the property Style.textColor, one would assign Rule.textColor inside this parameter list.

rule!Label(
    Rule.textColor = color("#fff"),
    Rule.backgroundColor = color("#000"),
)

It is also possible to pass a when subrule to apply changes based on runtime conditions:

rule!Button(
    Rule.backgroundColor = color("#fff"),
    when!"a.isHovered"(
        Rule.backgroundColor = color("#ccc"),
    )
)

If some directives are repeated across different rules, they can be reused:

myRule = rule(
    Rule.textColor = color("#000"),
),
rule!Button(
    myRule,
    Rule.backgroundColor = color("#fff"),
)

Moreover, rules respect inheritance. Since Button derives from Label and Node, rule!Label will also apply to buttons, and so will rule!Node.

For more advanced use-cases, it is possible to directly pass a delegate that accepts a node and returns a subrule.

rule!Button(
    a => rule(
        Rule.backgroundColor = pickColor(),
    )
)

It is recommended to use the with (Rule) statement to make rule definitions clearer.

template rule(T : Node = Node, tags...)
@safe
rule
(
Ts...
)
()

Members

Functions

rule
Rule rule(Ts fields)
Undocumented in source. Be warned that the author may not have intended to support it.

Meta