Macros
Macros lets you define a snippet of RSML which can be reused throughout your styles. You can import them from another Style Sheet via the @derive declaration.
They can be defined via the macro declaration:
@macro MyCoolMacro {
Size = udim2 (200px, 100px);
Position = udim2 (.5, .5);
}Macros can be given arguments which can be referenced via a & prefix
@macro MyCoolMacro (&size) {
Size = &size;
Position = udim2 (.5, .5);
}Return Context
By default macro's must return fully qualified expression(s) or block(s). But they can be customized to return a selector or a datatype by defining a return context.
| Name | Context |
|---|---|
| Construct | Must return a fully qualified expression(s) or block(s). |
| Datatype | Must return a datatype. |
| Selector | Must return a selector. |
@macro MyCoolMacro (&arg) -> Datatype {
rgb (35, 24, 31)
}
@macro MyCoolMacro (&arg) -> Selector {
::TextButton
}Calling Macros
A macro can be called by referencing its name with a ! suffix. All arguments of a macro must be datatypes.
MyCoolMacro! (udim2 (500px))Overloading
You can define multiple macros with the same name but with a different amount of parameters.
-- Padding A
@macro Padding (&all) {
::UIPadding {
PaddingTop = &all;
PaddingBottom = &all;
PaddingLeft = &all;
PaddingRight = &all;
}
}
-- Padding B
@macro Padding (&top_bottom, &left_right) {
::UIPadding {
PaddingTop = &top_bottom;
PaddingBottom = &top_bottom;
PaddingLeft = &left_right;
PaddingRight = &left_right;
}
}
-- Padding C
@macro Padding (&top, &left_right, &bottom) {
::UIPadding {
PaddingTop = ⊤
PaddingLeft = &left_right;
PaddingRight = &left_right;
PaddingBottom = ⊥
}
}
-- Padding D
@macro Padding (&top, &right, &bottom, &left) {
::UIPadding {
PaddingTop = ⊤
PaddingRight = &right;
PaddingBottom = ⊥
PaddingLeft = &left;
}
}
.Button {
-- `Padding C` will be called
-- as we have three parameters.
Padding! (10px, 20px, 8px);
}Built-In Macros
RSML has some macros built-in to speed up development: Padding (seen in the example above), CornerRadius, and Scale. An up to date list can be found here.