#[repr(transparent)]
#[derive(Copy, Clone, PartialEq, Eq, Debug, Default)]
pub struct Color(pub u32);
impl Color {
pub const TRANSPARENT: Self = Self(0x0000_0000);
pub const WHITE: Self = Self(0xFFFF_FFFF);
pub const BLACK: Self = Self(0xFF00_0000);
#[inline(always)]
pub const fn rgb(r: u8, g: u8, b: u8) -> Self {
Self::rgba(r, g, b, 255)
}
#[inline(always)]
pub const fn rgba(r: u8, g: u8, b: u8, a: u8) -> Self {
Self(((a as u32) << 24) | ((r as u32) << 16) | ((g as u32) << 8) | (b as u32))
}
#[inline(always)]
pub const fn hex(rgb: u32) -> Self {
Self(0xFF00_0000 | (rgb & 0x00FF_FFFF))
}
#[inline(always)]
pub const fn hex_alpha(rgba: u32) -> Self {
let r = ((rgba >> 24) & 0xFF) as u8;
let g = ((rgba >> 16) & 0xFF) as u8;
let b = ((rgba >> 8) & 0xFF) as u8;
let a = (rgba & 0xFF) as u8;
Self::rgba(r, g, b, a)
}
#[inline(always)]
pub const fn a(self) -> u8 {
((self.0 >> 24) & 0xFF) as u8
}
#[inline(always)]
pub const fn r(self) -> u8 {
((self.0 >> 16) & 0xFF) as u8
}
#[inline(always)]
pub const fn g(self) -> u8 {
((self.0 >> 8) & 0xFF) as u8
}
#[inline(always)]
pub const fn b(self) -> u8 {
(self.0 & 0xFF) as u8
}
#[inline]
pub const fn lerp(self, other: Self, t_256: u16) -> Self {
if t_256 == 0 {
return self;
}
if t_256 >= 256 {
return other;
}
let t = t_256 as u32;
let inv = 256 - t;
let sa = self.a() as u32;
let oa = other.a() as u32;
let a = ((sa * inv + oa * t + 128) >> 8) as u8;
if a == 0 {
return Self::TRANSPARENT;
}
if sa == 0 {
return Self::rgba(other.r(), other.g(), other.b(), a);
}
if oa == 0 {
return Self::rgba(self.r(), self.g(), self.b(), a);
}
if sa == 255 && oa == 255 {
let r = ((self.r() as u32 * inv + other.r() as u32 * t + 128) >> 8) as u8;
let g = ((self.g() as u32 * inv + other.g() as u32 * t + 128) >> 8) as u8;
let b = ((self.b() as u32 * inv + other.b() as u32 * t + 128) >> 8) as u8;
return Self::rgba(r, g, b, 255);
}
let w0 = sa * inv;
let w1 = oa * t;
let denom = w0 + w1;
if denom == 0 {
return Self::TRANSPARENT;
}
let half = denom >> 1;
let r = ((self.r() as u32 * w0 + other.r() as u32 * w1 + half) / denom) as u8;
let g = ((self.g() as u32 * w0 + other.g() as u32 * w1 + half) / denom) as u8;
let b = ((self.b() as u32 * w0 + other.b() as u32 * w1 + half) / denom) as u8;
Self::rgba(r, g, b, a)
}
#[inline(always)]
pub const fn scale_alpha(self, opacity: u8) -> Self {
if opacity == 255 {
return self;
}
if opacity == 0 {
return Self::TRANSPARENT;
}
let a = ((self.a() as u16 * opacity as u16) / 255) as u8;
Self::rgba(self.r(), self.g(), self.b(), a)
}
}
#[repr(u8)]
#[derive(Copy, Clone, PartialEq, Eq, Debug, Default)]
pub enum Easing {
Linear = 0,
EaseIn = 1,
#[default]
EaseOut = 2,
EaseInOut = 3,
Spring = 4,
EaseOutBack = 5,
Bounce = 6,
Elastic = 7,
}
impl Easing {
#[inline(always)]
pub const fn from_bits(bits: u8) -> Self {
match bits & 0x07 {
0 => Self::Linear,
1 => Self::EaseIn,
2 => Self::EaseOut,
3 => Self::EaseInOut,
4 => Self::Spring,
5 => Self::EaseOutBack,
6 => Self::Bounce,
_ => Self::Elastic,
}
}
#[inline]
pub fn apply_256(self, t_256: i32) -> i32 {
let t = t_256.clamp(0, 256);
if t >= 256 {
return 256;
}
match self {
Self::Linear => t,
Self::EaseIn => (t * t * t) >> 16,
Self::EaseOut => {
let inv = 256 - t;
256 - ((inv * inv * inv) >> 16)
}
Self::EaseInOut => {
if t < 128 {
(4 * t * t * t) >> 16
} else {
let inv = 256 - t;
256 - ((4 * inv * inv * inv) >> 16)
}
}
Self::Spring => {
let inv = 256 - t;
let base = 256 - ((inv * inv) >> 8);
let overshoot = ((9 * (t as i64) * (t as i64) * (inv as i64)) >> 19) as i32;
base + overshoot
}
Self::EaseOutBack => {
let u = (t - 256) as i64;
let cubic = (692 * u * u * u) >> 24;
let quad = (436 * u * u) >> 16;
(256 + cubic + quad) as i32
}
Self::Bounce => {
let seg = |x: i32, base: i32| ((121 * x * x) >> 12) + base;
let v = if t < 93 {
seg(t, 0)
} else if t < 186 {
seg(t - 140, 192)
} else if t < 233 {
seg(t - 209, 240)
} else {
seg(t - 244, 252)
};
v.min(256)
}
Self::Elastic => {
let e = 10 * t; let k = (e >> 8) as u32;
let frac = e & 0xFF;
let hi = 256i32 >> k.min(16);
let decay = hi - ((hi >> 1) * frac >> 8);
let deg10 = (t * 12000) / 256 - 900;
let (sin_q10, _) = crate::sdf::sin_cos_deg10(deg10);
256 + ((decay * sin_q10) >> 10)
}
}
}
#[inline]
pub fn sample_256(self, elapsed_ms: u32, duration_ms: u32) -> i32 {
if duration_ms == 0 || elapsed_ms >= duration_ms {
return 256;
}
self.apply_256(((elapsed_ms as u64 * 256) / duration_ms as u64) as i32)
}
}
#[repr(u8)]
#[derive(Copy, Clone, PartialEq, Eq, Debug, Default)]
pub enum LoopMode {
#[default]
Once = 0,
Infinite = 1,
PingPong = 2,
}
#[repr(u8)]
#[derive(Copy, Clone, PartialEq, Eq, Debug, Default)]
pub enum TextAlign {
#[default]
Left = 0,
Center = 1,
Right = 2,
}
#[repr(C, i16)]
#[derive(Copy, Clone, PartialEq, Eq, Debug, Default)]
pub enum Length {
#[default]
Auto = 0,
Px(i16) = 1,
Full = 2,
Pct(i16) = 3,
}
#[repr(C)]
#[derive(Copy, Clone, PartialEq, Eq, Debug, Default)]
pub struct Edges<T> {
pub top: T,
pub right: T,
pub bottom: T,
pub left: T,
}
impl<T: Copy> Edges<T> {
#[inline(always)]
pub const fn all(val: T) -> Self {
Self {
top: val,
right: val,
bottom: val,
left: val,
}
}
#[inline(always)]
pub const fn xy(x: T, y: T) -> Self {
Self {
top: y,
right: x,
bottom: y,
left: x,
}
}
}
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
pub enum FlexDir {
Row = 0,
Col = 1,
}
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
pub enum Justify {
Start = 0,
Center = 1,
End = 2,
Between = 3,
Around = 4,
}
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
pub enum AlignItems {
Stretch = 0,
Center = 1,
Start = 2,
End = 3,
}
#[repr(C)]
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
pub struct Style {
pub width: Length,
pub height: Length,
pub padding: Edges<i8>,
pub bg: Color,
pub border_color: Color,
pub gap: i8,
pub rounded: u8,
pub border_width: u8,
pub flex_flags: u8,
}
const _: () = assert!(core::mem::size_of::<Style>() == 24);
impl Default for Style {
#[inline(always)]
fn default() -> Self {
Self::DEFAULT
}
}
impl Style {
pub const DEFAULT: Self = Self::new();
#[inline(always)]
pub const fn new() -> Self {
Self {
width: Length::Auto,
height: Length::Auto,
padding: Edges::all(0),
bg: Color::TRANSPARENT,
border_color: Color::TRANSPARENT,
gap: 0,
rounded: 0,
border_width: 0,
flex_flags: 0,
}
}
#[inline(always)]
pub fn set_row(&mut self) {
self.flex_flags &= !0b0000_0001;
}
#[inline(always)]
pub fn set_col(&mut self) {
self.flex_flags |= 0b0000_0001;
}
#[inline(always)]
pub const fn flex_dir(&self) -> FlexDir {
if (self.flex_flags & 0b0000_0001) != 0 {
FlexDir::Col
} else {
FlexDir::Row
}
}
#[inline(always)]
pub fn set_justify(&mut self, justify: Justify) {
self.flex_flags = (self.flex_flags & !0b0000_1110) | ((justify as u8 & 0b111) << 1);
}
#[inline(always)]
pub fn set_justify_center(&mut self) {
self.set_justify(Justify::Center);
}
#[inline(always)]
pub fn set_justify_between(&mut self) {
self.set_justify(Justify::Between);
}
#[inline(always)]
pub const fn justify(&self) -> Justify {
match (self.flex_flags >> 1) & 0b111 {
1 => Justify::Center,
2 => Justify::End,
3 => Justify::Between,
4 => Justify::Around,
_ => Justify::Start,
}
}
#[inline(always)]
pub fn set_items_align(&mut self, align: AlignItems) {
self.flex_flags = (self.flex_flags & !0b0011_0000) | ((align as u8 & 0b11) << 4);
}
#[inline(always)]
pub fn set_items_center(&mut self) {
self.set_items_align(AlignItems::Center);
}
#[inline(always)]
pub const fn items_align(&self) -> AlignItems {
match (self.flex_flags >> 4) & 0b11 {
1 => AlignItems::Center,
2 => AlignItems::Start,
3 => AlignItems::End,
_ => AlignItems::Stretch,
}
}
#[inline(always)]
pub fn set_grow(&mut self, weight: u8) {
let w = if weight > 3 { 3 } else { weight };
self.flex_flags = (self.flex_flags & !0b1100_0000) | (w << 6);
}
#[inline(always)]
pub const fn flex_grow(&self) -> u8 {
(self.flex_flags >> 6) & 0b11
}
#[inline(always)]
pub const fn rounded_radius(&self) -> u8 {
self.rounded & 0x7F
}
#[inline(always)]
pub fn set_rounded(&mut self, radius: u8) {
self.rounded = (self.rounded & 0x80) | (radius.min(127) & 0x7F);
}
#[inline(always)]
pub const fn flex_wrap(&self) -> bool {
(self.rounded & 0x80) != 0
}
#[inline(always)]
pub fn set_flex_wrap(&mut self, wrap: bool) {
if wrap {
self.rounded |= 0x80;
} else {
self.rounded &= 0x7F;
}
}
#[inline(always)]
pub const fn border_px(&self) -> u8 {
self.border_width & 0x0F
}
#[inline(always)]
pub fn set_border_px(&mut self, width: u8) {
self.border_width = (self.border_width & 0xF0) | (width.min(15) & 0x0F);
}
#[inline(always)]
pub const fn margin_px(&self) -> i8 {
((self.border_width >> 4) & 0x0F) as i8
}
#[inline(always)]
pub fn set_margin_px(&mut self, px: i8) {
let m = px.clamp(0, 15) as u8;
self.border_width = (self.border_width & 0x0F) | (m << 4);
}
}
#[inline(always)]
pub const fn px(val: f32) -> i16 {
if val >= 0.0 {
(val + 0.5) as i16
} else {
(val - 0.5) as i16
}
}
#[inline(always)]
pub const fn rgb(hex: u32) -> Color {
Color::hex(hex)
}
#[inline(always)]
pub const fn rgba(hex: u32) -> Color {
Color::hex_alpha(hex)
}
pub trait FluentBuilder: Sized {
#[inline(always)]
fn when(self, condition: bool, then: impl FnOnce(Self) -> Self) -> Self {
if condition {
then(self)
} else {
self
}
}
#[inline(always)]
fn when_else(
self,
condition: bool,
then: impl FnOnce(Self) -> Self,
else_fn: impl FnOnce(Self) -> Self,
) -> Self {
if condition {
then(self)
} else {
else_fn(self)
}
}
#[inline(always)]
fn when_some<O>(self, option: Option<O>, then: impl FnOnce(Self, O) -> Self) -> Self {
match option {
Some(value) => then(self, value),
None => self,
}
}
#[inline(always)]
fn when_none<O>(self, option: &Option<O>, then: impl FnOnce(Self) -> Self) -> Self {
if option.is_none() {
then(self)
} else {
self
}
}
#[inline(always)]
fn apply<U>(self, f: impl FnOnce(Self) -> U) -> U {
f(self)
}
}
impl<T: Sized> FluentBuilder for T {}
#[derive(Copy, Clone, PartialEq, Eq, Debug, Default)]
pub struct StyleRefinement {
pub bg: Option<Color>,
pub border_width: Option<u8>,
pub border_color: Option<Color>,
pub text_color: Option<Color>,
pub opacity: Option<u8>,
pub rounded: Option<u8>,
}
impl StyleRefinement {
#[inline(always)]
pub const fn new() -> Self {
Self {
bg: None,
border_width: None,
border_color: None,
text_color: None,
opacity: None,
rounded: None,
}
}
#[inline(always)]
pub const fn is_empty(&self) -> bool {
self.bg.is_none()
&& self.border_width.is_none()
&& self.border_color.is_none()
&& self.text_color.is_none()
&& self.opacity.is_none()
&& self.rounded.is_none()
}
#[inline(always)]
pub const fn is_bg_only(&self) -> bool {
self.bg.is_some()
&& self.border_width.is_none()
&& self.border_color.is_none()
&& self.text_color.is_none()
&& self.opacity.is_none()
&& self.rounded.is_none()
}
#[inline(always)]
pub const fn bg(mut self, color: Color) -> Self {
self.bg = Some(color);
self
}
#[inline(always)]
pub const fn border(mut self, width: u8, color: Color) -> Self {
self.border_width = Some(width);
self.border_color = Some(color);
self
}
#[inline(always)]
pub const fn border_0(mut self) -> Self {
self.border_width = Some(0);
self
}
#[inline(always)]
pub const fn border_1(mut self) -> Self {
self.border_width = Some(1);
self
}
#[inline(always)]
pub const fn border_2(mut self) -> Self {
self.border_width = Some(2);
self
}
#[inline(always)]
pub const fn border_4(mut self) -> Self {
self.border_width = Some(4);
self
}
#[inline(always)]
pub const fn border_color(mut self, color: Color) -> Self {
self.border_color = Some(color);
self
}
#[inline(always)]
pub const fn text_color(mut self, color: Color) -> Self {
self.text_color = Some(color);
self
}
#[inline(always)]
pub const fn opacity(mut self, alpha: u8) -> Self {
self.opacity = Some(alpha);
self
}
#[inline(always)]
pub const fn opacity_f(mut self, alpha: f32) -> Self {
let clamped = if alpha <= 0.0 {
0.0
} else if alpha >= 1.0 {
1.0
} else {
alpha
};
self.opacity = Some((clamped * 255.0 + 0.5) as u8);
self
}
#[inline(always)]
pub const fn rounded(mut self, radius: u8) -> Self {
self.rounded = Some(radius);
self
}
#[inline(always)]
pub const fn rounded_none(self) -> Self {
self.rounded(0)
}
#[inline(always)]
pub const fn rounded_sm(self) -> Self {
self.rounded(4)
}
#[inline(always)]
pub const fn rounded_md(self) -> Self {
self.rounded(6)
}
#[inline(always)]
pub const fn rounded_lg(self) -> Self {
self.rounded(8)
}
#[inline(always)]
pub const fn rounded_xl(self) -> Self {
self.rounded(12)
}
#[inline(always)]
pub const fn rounded_full(self) -> Self {
self.rounded(127)
}
}
pub trait Styled: Sized {
fn style_mut(&mut self) -> &mut Style;
#[inline(always)]
fn flex(mut self) -> Self {
self.style_mut().set_row();
self
}
#[inline(always)]
fn flex_row(mut self) -> Self {
self.style_mut().set_row();
self
}
#[inline(always)]
fn flex_col(mut self) -> Self {
self.style_mut().set_col();
self
}
#[inline(always)]
fn flex_wrap(mut self) -> Self {
self.style_mut().set_flex_wrap(true);
self
}
#[inline(always)]
fn flex_nowrap(mut self) -> Self {
self.style_mut().set_flex_wrap(false);
self
}
#[inline(always)]
fn flex_1(mut self) -> Self {
self.style_mut().set_grow(1);
self
}
#[inline(always)]
fn flex_none(mut self) -> Self {
self.style_mut().set_grow(0);
self
}
#[inline(always)]
fn size_full(mut self) -> Self {
self.style_mut().width = Length::Full;
self.style_mut().height = Length::Full;
self
}
#[inline(always)]
fn size(mut self, px: i16) -> Self {
let s = self.style_mut();
s.width = Length::Px(px);
s.height = Length::Px(px);
self
}
#[inline(always)]
fn w_full(mut self) -> Self {
self.style_mut().width = Length::Full;
self
}
#[inline(always)]
fn h_full(mut self) -> Self {
self.style_mut().height = Length::Full;
self
}
#[inline(always)]
fn w_auto(mut self) -> Self {
self.style_mut().width = Length::Auto;
self
}
#[inline(always)]
fn h_auto(mut self) -> Self {
self.style_mut().height = Length::Auto;
self
}
#[inline(always)]
fn w(mut self, px: i16) -> Self {
self.style_mut().width = Length::Px(px);
self
}
#[inline(always)]
fn h(mut self, px: i16) -> Self {
self.style_mut().height = Length::Px(px);
self
}
#[inline(always)]
fn w_pct(mut self, pct: i16) -> Self {
self.style_mut().width = Length::Pct(pct.clamp(0, 100));
self
}
#[inline(always)]
fn h_pct(mut self, pct: i16) -> Self {
self.style_mut().height = Length::Pct(pct.clamp(0, 100));
self
}
#[inline(always)]
fn w_1_2(self) -> Self { self.w_pct(50) }
#[inline(always)]
fn w_1_3(self) -> Self { self.w_pct(33) }
#[inline(always)]
fn w_2_3(self) -> Self { self.w_pct(67) }
#[inline(always)]
fn w_1_4(self) -> Self { self.w_pct(25) }
#[inline(always)]
fn w_3_4(self) -> Self { self.w_pct(75) }
#[inline(always)]
fn h_1_2(self) -> Self { self.h_pct(50) }
#[inline(always)] fn size_0(self) -> Self { self.size(0) }
#[inline(always)] fn size_0_5(self) -> Self { self.size(2) }
#[inline(always)] fn size_1(self) -> Self { self.size(4) }
#[inline(always)] fn size_1_5(self) -> Self { self.size(6) }
#[inline(always)] fn size_2(self) -> Self { self.size(8) }
#[inline(always)] fn size_2_5(self) -> Self { self.size(10) }
#[inline(always)] fn size_3(self) -> Self { self.size(12) }
#[inline(always)] fn size_3_5(self) -> Self { self.size(14) }
#[inline(always)] fn size_4(self) -> Self { self.size(16) }
#[inline(always)] fn size_5(self) -> Self { self.size(20) }
#[inline(always)] fn size_6(self) -> Self { self.size(24) }
#[inline(always)] fn size_7(self) -> Self { self.size(28) }
#[inline(always)] fn size_8(self) -> Self { self.size(32) }
#[inline(always)] fn size_9(self) -> Self { self.size(36) }
#[inline(always)] fn size_10(self) -> Self { self.size(40) }
#[inline(always)] fn size_11(self) -> Self { self.size(44) }
#[inline(always)] fn size_12(self) -> Self { self.size(48) }
#[inline(always)] fn size_14(self) -> Self { self.size(56) }
#[inline(always)] fn size_16(self) -> Self { self.size(64) }
#[inline(always)] fn size_20(self) -> Self { self.size(80) }
#[inline(always)] fn size_24(self) -> Self { self.size(96) }
#[inline(always)] fn size_32(self) -> Self { self.size(128) }
#[inline(always)] fn w_0(self) -> Self { self.w(0) }
#[inline(always)] fn w_0_5(self) -> Self { self.w(2) }
#[inline(always)] fn w_1(self) -> Self { self.w(4) }
#[inline(always)] fn w_1_5(self) -> Self { self.w(6) }
#[inline(always)] fn w_2(self) -> Self { self.w(8) }
#[inline(always)] fn w_2_5(self) -> Self { self.w(10) }
#[inline(always)] fn w_3(self) -> Self { self.w(12) }
#[inline(always)] fn w_3_5(self) -> Self { self.w(14) }
#[inline(always)] fn w_4(self) -> Self { self.w(16) }
#[inline(always)] fn w_5(self) -> Self { self.w(20) }
#[inline(always)] fn w_6(self) -> Self { self.w(24) }
#[inline(always)] fn w_7(self) -> Self { self.w(28) }
#[inline(always)] fn w_8(self) -> Self { self.w(32) }
#[inline(always)] fn w_9(self) -> Self { self.w(36) }
#[inline(always)] fn w_10(self) -> Self { self.w(40) }
#[inline(always)] fn w_11(self) -> Self { self.w(44) }
#[inline(always)] fn w_12(self) -> Self { self.w(48) }
#[inline(always)] fn w_14(self) -> Self { self.w(56) }
#[inline(always)] fn w_16(self) -> Self { self.w(64) }
#[inline(always)] fn w_20(self) -> Self { self.w(80) }
#[inline(always)] fn w_24(self) -> Self { self.w(96) }
#[inline(always)] fn w_28(self) -> Self { self.w(112) }
#[inline(always)] fn w_32(self) -> Self { self.w(128) }
#[inline(always)] fn w_36(self) -> Self { self.w(144) }
#[inline(always)] fn w_40(self) -> Self { self.w(160) }
#[inline(always)] fn w_44(self) -> Self { self.w(176) }
#[inline(always)] fn w_48(self) -> Self { self.w(192) }
#[inline(always)] fn w_52(self) -> Self { self.w(208) }
#[inline(always)] fn w_56(self) -> Self { self.w(224) }
#[inline(always)] fn w_60(self) -> Self { self.w(240) }
#[inline(always)] fn w_64(self) -> Self { self.w(256) }
#[inline(always)] fn w_72(self) -> Self { self.w(288) }
#[inline(always)] fn w_80(self) -> Self { self.w(320) }
#[inline(always)] fn w_96(self) -> Self { self.w(384) }
#[inline(always)] fn h_0(self) -> Self { self.h(0) }
#[inline(always)] fn h_0_5(self) -> Self { self.h(2) }
#[inline(always)] fn h_1(self) -> Self { self.h(4) }
#[inline(always)] fn h_1_5(self) -> Self { self.h(6) }
#[inline(always)] fn h_2(self) -> Self { self.h(8) }
#[inline(always)] fn h_2_5(self) -> Self { self.h(10) }
#[inline(always)] fn h_3(self) -> Self { self.h(12) }
#[inline(always)] fn h_3_5(self) -> Self { self.h(14) }
#[inline(always)] fn h_4(self) -> Self { self.h(16) }
#[inline(always)] fn h_5(self) -> Self { self.h(20) }
#[inline(always)] fn h_6(self) -> Self { self.h(24) }
#[inline(always)] fn h_7(self) -> Self { self.h(28) }
#[inline(always)] fn h_8(self) -> Self { self.h(32) }
#[inline(always)] fn h_9(self) -> Self { self.h(36) }
#[inline(always)] fn h_10(self) -> Self { self.h(40) }
#[inline(always)] fn h_11(self) -> Self { self.h(44) }
#[inline(always)] fn h_12(self) -> Self { self.h(48) }
#[inline(always)] fn h_14(self) -> Self { self.h(56) }
#[inline(always)] fn h_16(self) -> Self { self.h(64) }
#[inline(always)] fn h_20(self) -> Self { self.h(80) }
#[inline(always)] fn h_24(self) -> Self { self.h(96) }
#[inline(always)] fn h_32(self) -> Self { self.h(128) }
#[inline(always)] fn h_40(self) -> Self { self.h(160) }
#[inline(always)] fn h_48(self) -> Self { self.h(192) }
#[inline(always)] fn h_56(self) -> Self { self.h(224) }
#[inline(always)] fn h_64(self) -> Self { self.h(256) }
#[inline(always)]
fn p(mut self, px: i8) -> Self {
self.style_mut().padding = Edges::all(px);
self
}
#[inline(always)]
fn px(mut self, px: i8) -> Self {
let p = &mut self.style_mut().padding;
p.left = px;
p.right = px;
self
}
#[inline(always)]
fn py(mut self, px: i8) -> Self {
let p = &mut self.style_mut().padding;
p.top = px;
p.bottom = px;
self
}
#[inline(always)]
fn pt(mut self, px: i8) -> Self {
self.style_mut().padding.top = px;
self
}
#[inline(always)]
fn pb(mut self, px: i8) -> Self {
self.style_mut().padding.bottom = px;
self
}
#[inline(always)]
fn pl(mut self, px: i8) -> Self {
self.style_mut().padding.left = px;
self
}
#[inline(always)]
fn pr(mut self, px: i8) -> Self {
self.style_mut().padding.right = px;
self
}
#[inline(always)] fn p_0(self) -> Self { self.p(0) }
#[inline(always)] fn p_0p5(self) -> Self { self.p(2) }
#[inline(always)] fn p_0_5(self) -> Self { self.p(2) }
#[inline(always)] fn p_1(self) -> Self { self.p(4) }
#[inline(always)] fn p_1p5(self) -> Self { self.p(6) }
#[inline(always)] fn p_1_5(self) -> Self { self.p(6) }
#[inline(always)] fn p_2(self) -> Self { self.p(8) }
#[inline(always)] fn p_2p5(self) -> Self { self.p(10) }
#[inline(always)] fn p_2_5(self) -> Self { self.p(10) }
#[inline(always)] fn p_3(self) -> Self { self.p(12) }
#[inline(always)] fn p_3p5(self) -> Self { self.p(14) }
#[inline(always)] fn p_3_5(self) -> Self { self.p(14) }
#[inline(always)] fn p_4(self) -> Self { self.p(16) }
#[inline(always)] fn p_5(self) -> Self { self.p(20) }
#[inline(always)] fn p_6(self) -> Self { self.p(24) }
#[inline(always)] fn p_8(self) -> Self { self.p(32) }
#[inline(always)] fn p_10(self) -> Self { self.p(40) }
#[inline(always)] fn p_12(self) -> Self { self.p(48) }
#[inline(always)] fn px_0(self) -> Self { self.px(0) }
#[inline(always)] fn px_0p5(self) -> Self { self.px(2) }
#[inline(always)] fn px_0_5(self) -> Self { self.px(2) }
#[inline(always)] fn px_1(self) -> Self { self.px(4) }
#[inline(always)] fn px_1p5(self) -> Self { self.px(6) }
#[inline(always)] fn px_1_5(self) -> Self { self.px(6) }
#[inline(always)] fn px_2(self) -> Self { self.px(8) }
#[inline(always)] fn px_2p5(self) -> Self { self.px(10) }
#[inline(always)] fn px_2_5(self) -> Self { self.px(10) }
#[inline(always)] fn px_3(self) -> Self { self.px(12) }
#[inline(always)] fn px_3p5(self) -> Self { self.px(14) }
#[inline(always)] fn px_3_5(self) -> Self { self.px(14) }
#[inline(always)] fn px_4(self) -> Self { self.px(16) }
#[inline(always)] fn px_5(self) -> Self { self.px(20) }
#[inline(always)] fn px_6(self) -> Self { self.px(24) }
#[inline(always)] fn px_8(self) -> Self { self.px(32) }
#[inline(always)] fn py_0(self) -> Self { self.py(0) }
#[inline(always)] fn py_0p5(self) -> Self { self.py(2) }
#[inline(always)] fn py_0_5(self) -> Self { self.py(2) }
#[inline(always)] fn py_1(self) -> Self { self.py(4) }
#[inline(always)] fn py_1p5(self) -> Self { self.py(6) }
#[inline(always)] fn py_1_5(self) -> Self { self.py(6) }
#[inline(always)] fn py_2(self) -> Self { self.py(8) }
#[inline(always)] fn py_2p5(self) -> Self { self.py(10) }
#[inline(always)] fn py_2_5(self) -> Self { self.py(10) }
#[inline(always)] fn py_3(self) -> Self { self.py(12) }
#[inline(always)] fn py_3p5(self) -> Self { self.py(14) }
#[inline(always)] fn py_3_5(self) -> Self { self.py(14) }
#[inline(always)] fn py_4(self) -> Self { self.py(16) }
#[inline(always)] fn py_5(self) -> Self { self.py(20) }
#[inline(always)] fn py_6(self) -> Self { self.py(24) }
#[inline(always)] fn py_8(self) -> Self { self.py(32) }
#[inline(always)] fn pt_0(self) -> Self { self.pt(0) }
#[inline(always)] fn pt_1(self) -> Self { self.pt(4) }
#[inline(always)] fn pt_2(self) -> Self { self.pt(8) }
#[inline(always)] fn pt_3(self) -> Self { self.pt(12) }
#[inline(always)] fn pt_4(self) -> Self { self.pt(16) }
#[inline(always)] fn pb_0(self) -> Self { self.pb(0) }
#[inline(always)] fn pb_1(self) -> Self { self.pb(4) }
#[inline(always)] fn pb_2(self) -> Self { self.pb(8) }
#[inline(always)] fn pb_3(self) -> Self { self.pb(12) }
#[inline(always)] fn pb_4(self) -> Self { self.pb(16) }
#[inline(always)] fn pl_0(self) -> Self { self.pl(0) }
#[inline(always)] fn pl_1(self) -> Self { self.pl(4) }
#[inline(always)] fn pl_2(self) -> Self { self.pl(8) }
#[inline(always)] fn pl_3(self) -> Self { self.pl(12) }
#[inline(always)] fn pl_4(self) -> Self { self.pl(16) }
#[inline(always)] fn pr_0(self) -> Self { self.pr(0) }
#[inline(always)] fn pr_1(self) -> Self { self.pr(4) }
#[inline(always)] fn pr_2(self) -> Self { self.pr(8) }
#[inline(always)] fn pr_3(self) -> Self { self.pr(12) }
#[inline(always)] fn pr_4(self) -> Self { self.pr(16) }
#[inline(always)]
fn m(mut self, px: i8) -> Self {
self.style_mut().set_margin_px(px);
self
}
#[inline(always)] fn m_0(self) -> Self { self.m(0) }
#[inline(always)] fn m_0_5(self) -> Self { self.m(2) }
#[inline(always)] fn m_1(self) -> Self { self.m(4) }
#[inline(always)] fn m_1_5(self) -> Self { self.m(6) }
#[inline(always)] fn m_2(self) -> Self { self.m(8) }
#[inline(always)] fn m_2_5(self) -> Self { self.m(10) }
#[inline(always)] fn m_3(self) -> Self { self.m(12) }
#[inline(always)] fn m_4(self) -> Self { self.m(16) }
#[inline(always)]
fn gap(mut self, px: i8) -> Self {
self.style_mut().gap = px;
self
}
#[inline(always)] fn gap_0(self) -> Self { self.gap(0) }
#[inline(always)] fn gap_0p5(self) -> Self { self.gap(2) }
#[inline(always)] fn gap_0_5(self) -> Self { self.gap(2) }
#[inline(always)] fn gap_1(self) -> Self { self.gap(4) }
#[inline(always)] fn gap_1p5(self) -> Self { self.gap(6) }
#[inline(always)] fn gap_1_5(self) -> Self { self.gap(6) }
#[inline(always)] fn gap_2(self) -> Self { self.gap(8) }
#[inline(always)] fn gap_2p5(self) -> Self { self.gap(10) }
#[inline(always)] fn gap_2_5(self) -> Self { self.gap(10) }
#[inline(always)] fn gap_3(self) -> Self { self.gap(12) }
#[inline(always)] fn gap_3p5(self) -> Self { self.gap(14) }
#[inline(always)] fn gap_3_5(self) -> Self { self.gap(14) }
#[inline(always)] fn gap_4(self) -> Self { self.gap(16) }
#[inline(always)] fn gap_5(self) -> Self { self.gap(20) }
#[inline(always)] fn gap_6(self) -> Self { self.gap(24) }
#[inline(always)] fn gap_8(self) -> Self { self.gap(32) }
#[inline(always)]
fn flex_grow(mut self, weight: u8) -> Self {
self.style_mut().set_grow(weight);
self
}
#[inline(always)]
fn items_center(mut self) -> Self {
self.style_mut().set_items_center();
self
}
#[inline(always)]
fn items_start(mut self) -> Self {
self.style_mut().set_items_align(AlignItems::Start);
self
}
#[inline(always)]
fn items_end(mut self) -> Self {
self.style_mut().set_items_align(AlignItems::End);
self
}
#[inline(always)]
fn items_stretch(mut self) -> Self {
self.style_mut().set_items_align(AlignItems::Stretch);
self
}
#[inline(always)]
fn justify_start(mut self) -> Self {
self.style_mut().set_justify(Justify::Start);
self
}
#[inline(always)]
fn justify_center(mut self) -> Self {
self.style_mut().set_justify_center();
self
}
#[inline(always)]
fn justify_between(mut self) -> Self {
self.style_mut().set_justify_between();
self
}
#[inline(always)]
fn justify_end(mut self) -> Self {
self.style_mut().set_justify(Justify::End);
self
}
#[inline(always)]
fn justify_around(mut self) -> Self {
self.style_mut().set_justify(Justify::Around);
self
}
#[inline(always)]
fn bg(mut self, color: Color) -> Self {
self.style_mut().bg = color;
self
}
#[inline(always)]
fn rounded(mut self, radius: u8) -> Self {
self.style_mut().set_rounded(radius);
self
}
#[inline(always)] fn rounded_none(self) -> Self { self.rounded(0) }
#[inline(always)] fn rounded_xs(self) -> Self { self.rounded(2) }
#[inline(always)] fn rounded_sm(self) -> Self { self.rounded(4) }
#[inline(always)] fn rounded_md(self) -> Self { self.rounded(6) }
#[inline(always)] fn rounded_lg(self) -> Self { self.rounded(8) }
#[inline(always)] fn rounded_xl(self) -> Self { self.rounded(12) }
#[inline(always)] fn rounded_2xl(self) -> Self { self.rounded(16) }
#[inline(always)] fn rounded_3xl(self) -> Self { self.rounded(24) }
#[inline(always)] fn rounded_full(self) -> Self { self.rounded(127) }
#[inline(always)]
fn border(mut self, width: u8, color: Color) -> Self {
let s = self.style_mut();
s.set_border_px(width);
s.border_color = color;
self
}
#[inline(always)]
fn border_0(mut self) -> Self {
self.style_mut().set_border_px(0);
self
}
#[inline(always)]
fn border_1(mut self) -> Self {
self.style_mut().set_border_px(1);
self
}
#[inline(always)]
fn border_2(mut self) -> Self {
self.style_mut().set_border_px(2);
self
}
#[inline(always)]
fn border_4(mut self) -> Self {
self.style_mut().set_border_px(4);
self
}
#[inline(always)]
fn border_8(mut self) -> Self {
self.style_mut().set_border_px(8);
self
}
#[inline(always)]
fn border_color(mut self, color: Color) -> Self {
self.style_mut().border_color = color;
self
}
#[inline(always)]
fn flex_shrink_0(self) -> Self {
self
}
}
pub use crate::style_ext::{StyleExt, StyledExt};