maomi
Introduction
Guide
Documents

Global Stylesheets

Global stylesheet usage

Some constants may be used in several stylesheets in the whole crate. It is able to write them in a global stylesheet.

The default global stylesheet is located at "src/lib.mcss". This path can be changed by "stylesheet-mod-root" in Cargo.toml.

[package.metadata.maomi]
stylesheet-mod-root = "src/lib.mcss"

Constants can be declared inside this file.

pub(crate) const TEXT_COLOR: value = rgb(32, 32, 32);

Stylesheets can use the global constants with a "use" statement.

stylesheet! {
use crate::*;
class my_class {
color = TEXT_COLOR;
}
}

Normal functions (not dynamic style functions) can also be declared.

pub(crate) const TEXT_COLOR: value = rgb(32, 32, 32);
pub(crate) fn paddings() {
padding = Px(1) Px(2);
}

Then in stylesheets:

stylesheet! {
use crate::*;
class my_class {
color = TEXT_COLOR;
paddings();
}
}

Submodules in global stylesheets

If the global stylesheet is large, the "mod" statement can be used to split it into several files.

pub(crate) mod my_sub;

In "src/my_sub.mcss":

pub(crate) const TEXT_COLOR: value = rgb(32, 32, 32);

Then in stylesheets:

stylesheet! {
use crate::my_sub::*;
class my_class {
color = TEXT_COLOR;
}
}