Macro cushy::define_components

source ยท
macro_rules! define_components {
    ($($widget:ident { $($(#$doc:tt)* $component:ident($type:ty, $name:expr $(, $($default:tt)*)?))* })*) => { ... };
    ($type:ty, . $($path:tt)*) => { ... };
    ($type:ty, |$context:ident| $($expr:tt)*) => { ... };
    ($type:ty, @$path:path) => { ... };
    ($type:ty, contrasting!($bg:ident, $($fg:ident),+ $(,)?)) => { ... };
    ($type:ty, ) => { ... };
    ($type:ty, $($expr:tt)+) => { ... };
    (default $component:ident $type:ty, . $($path:tt)*) => { ... };
    (default $component:ident $type:ty, |$context:ident| $($expr:tt)*) => { ... };
    (default $component:ident $type:ty, @$path:path) => { ... };
    (default $component:ident $type:ty, contrasting!($bg:ident, $($fg:ident),+ $(,)?)) => { ... };
    (default $component:ident $type:ty, ) => { ... };
    (default $component:ident $type:ty, $($expr:tt)+) => { ... };
}
Expand description

Defines a set of style components for Cushy.

These macros implement NamedComponent and ComponentDefinition for each entry defined. The syntax is:

use cushy::define_components;
use cushy::styles::Dimension;
use cushy::styles::components::{SurfaceColor, TextColor};
use cushy::kludgine::Color;
use cushy::figures::Zero;

define_components! {
    GroupName {
        /// This is the documentation for example component. It has a default value of `Dimension::ZERO`.
        ExampleComponent(Dimension, "example_component", Dimension::ZERO)
        /// This component whose default value is a color from the current theme.
        ThemedComponent(Color, "themed_component", .primary.color)
        /// This component is a color whose default value is the currently defined `TextColor`.
        DependentComponent(Color, "dependent_component", @TextColor)
        /// This component defaults to picking a contrasting color between `TextColor` and `SurfaceColor`
        ContrastingColor(Color, "contrasting_color", contrasting!(ThemedComponent, TextColor, SurfaceColor))
        /// This component shows how to use a closure for nearly infinite flexibility in computing the default value.
        ClosureDefaultComponent(Color, "closure_component", |context| context.get(&TextColor))
    }
}