macro_rules! setters {
($($name:ident => |$style:ident| $body:expr;)*) => {
$(
fn $name(mut self) -> Self {
{
let $style = self.style();
$body;
}
self
}
)*
};
}
macro_rules! scale_methods {
($prefix:ident, $apply:expr) => {
scale_steps! {
$prefix, $apply;
(0, 0.0), (px, 0.25), (0_5, 0.5), (1, 1.0), (1_5, 1.5), (2, 2.0), (2_5, 2.5), (3, 3.0), (3_5, 3.5),
(4, 4.0), (5, 5.0), (6, 6.0), (7, 7.0), (8, 8.0), (9, 9.0), (10, 10.0), (11, 11.0), (12, 12.0),
(14, 14.0), (16, 16.0), (20, 20.0), (24, 24.0), (28, 28.0), (32, 32.0), (36, 36.0), (40, 40.0),
(44, 44.0), (48, 48.0), (52, 52.0), (56, 56.0), (60, 60.0), (64, 64.0), (72, 72.0), (80, 80.0),
(96, 96.0)
}
};
}
macro_rules! scale_steps {
($prefix:ident, $apply:expr; $(($name:tt, $units:expr)),*) => {
paste::paste! {
$(
fn [<$prefix _ $name>](mut self) -> Self {
let apply: fn(&mut crate::view::style::Style, crate::core::Pixels) = $apply;
apply(self.style(), crate::core::Pixels($units * 4.0));
self
}
)*
}
};
}
macro_rules! fractions {
($prefix:ident, $field:ident) => {
fraction_steps! {
$prefix, $field;
(1_2, 1.0 / 2.0), (1_3, 1.0 / 3.0), (2_3, 2.0 / 3.0), (1_4, 1.0 / 4.0), (3_4, 3.0 / 4.0),
(1_6, 1.0 / 6.0), (5_6, 5.0 / 6.0)
}
};
}
macro_rules! fraction_steps {
($prefix:ident, $field:ident; $(($name:tt, $part:expr)),*) => {
paste::paste! {
$(
fn [<$prefix _ $name>](mut self) -> Self {
self.style().$field = Some(crate::view::style::Length::Percent($part));
self
}
)*
}
};
}
pub(crate) use {fraction_steps, fractions, scale_methods, scale_steps, setters};