Skip to main content

velox_engine/
style.rs

1//! 24 字节紧凑样式结构体 `Style` 与 Tailwind 风格链式修饰符 `Styled`。
2
3/// ARGB8888 32 位颜色表示(`0xAARRGGBB`)。
4#[repr(transparent)]
5#[derive(Copy, Clone, PartialEq, Eq, Debug, Default)]
6pub struct Color(pub u32);
7
8impl Color {
9    /// 完全透明色。
10    pub const TRANSPARENT: Self = Self(0x0000_0000);
11    /// 纯白色。
12    pub const WHITE: Self = Self(0xFFFF_FFFF);
13    /// 纯黑色。
14    pub const BLACK: Self = Self(0xFF00_0000);
15
16    /// 从不透明 RGB 分量构造颜色。
17    #[inline(always)]
18    pub const fn rgb(r: u8, g: u8, b: u8) -> Self {
19        Self::rgba(r, g, b, 255)
20    }
21
22    /// 从 RGBA 分量构造颜色。
23    #[inline(always)]
24    pub const fn rgba(r: u8, g: u8, b: u8, a: u8) -> Self {
25        Self(((a as u32) << 24) | ((r as u32) << 16) | ((g as u32) << 8) | (b as u32))
26    }
27
28    /// 从 24 位十六进制 RGB 整数构造不透明颜色(如 `Color::hex(0xd4d4d4)`)。
29    #[inline(always)]
30    pub const fn hex(rgb: u32) -> Self {
31        Self(0xFF00_0000 | (rgb & 0x00FF_FFFF))
32    }
33
34    /// 从 32 位十六进制 `0xRRGGBBAA` 整数构造颜色(如 `Color::hex_alpha(0x171717cc)`)。
35    #[inline(always)]
36    pub const fn hex_alpha(rgba: u32) -> Self {
37        let r = ((rgba >> 24) & 0xFF) as u8;
38        let g = ((rgba >> 16) & 0xFF) as u8;
39        let b = ((rgba >> 8) & 0xFF) as u8;
40        let a = (rgba & 0xFF) as u8;
41        Self::rgba(r, g, b, a)
42    }
43
44    /// Alpha 通道(`0..=255`)。
45    #[inline(always)]
46    pub const fn a(self) -> u8 {
47        ((self.0 >> 24) & 0xFF) as u8
48    }
49
50    /// Red 通道(`0..=255`)。
51    #[inline(always)]
52    pub const fn r(self) -> u8 {
53        ((self.0 >> 16) & 0xFF) as u8
54    }
55
56    /// Green 通道(`0..=255`)。
57    #[inline(always)]
58    pub const fn g(self) -> u8 {
59        ((self.0 >> 8) & 0xFF) as u8
60    }
61
62    /// Blue 通道(`0..=255`)。
63    #[inline(always)]
64    pub const fn b(self) -> u8 {
65        (self.0 & 0xFF) as u8
66    }
67
68    /// 定点数颜色线性插值(`t_256` 取值范围 `0..=256`)。
69    ///
70    /// 正确处理透明色与半透明色(预乘 Alpha 权重插值):
71    /// 当任一端为完全透明(`a == 0`,如 `Color::TRANSPARENT`)时保留另一端的 RGB 色相、仅插值 Alpha,
72    /// 彻底消除 `Outline` / `Ghost` 等透明底按钮在亮色/暗色主题下悬停过渡时的黑灰闪烁。
73    #[inline]
74    pub const fn lerp(self, other: Self, t_256: u16) -> Self {
75        if t_256 == 0 {
76            return self;
77        }
78        if t_256 >= 256 {
79            return other;
80        }
81        let t = t_256 as u32;
82        let inv = 256 - t;
83        let sa = self.a() as u32;
84        let oa = other.a() as u32;
85        let a = ((sa * inv + oa * t + 128) >> 8) as u8;
86        if a == 0 {
87            return Self::TRANSPARENT;
88        }
89        if sa == 0 {
90            return Self::rgba(other.r(), other.g(), other.b(), a);
91        }
92        if oa == 0 {
93            return Self::rgba(self.r(), self.g(), self.b(), a);
94        }
95        if sa == 255 && oa == 255 {
96            let r = ((self.r() as u32 * inv + other.r() as u32 * t + 128) >> 8) as u8;
97            let g = ((self.g() as u32 * inv + other.g() as u32 * t + 128) >> 8) as u8;
98            let b = ((self.b() as u32 * inv + other.b() as u32 * t + 128) >> 8) as u8;
99            return Self::rgba(r, g, b, 255);
100        }
101        // 半透明预乘加权插值再还原直通 RGB,避免低 Alpha 端暗色拉黑
102        let w0 = sa * inv;
103        let w1 = oa * t;
104        let denom = w0 + w1;
105        if denom == 0 {
106            return Self::TRANSPARENT;
107        }
108        let half = denom >> 1;
109        let r = ((self.r() as u32 * w0 + other.r() as u32 * w1 + half) / denom) as u8;
110        let g = ((self.g() as u32 * w0 + other.g() as u32 * w1 + half) / denom) as u8;
111        let b = ((self.b() as u32 * w0 + other.b() as u32 * w1 + half) / denom) as u8;
112        Self::rgba(r, g, b, a)
113    }
114
115    /// 按给定不透明度 `opacity`(`0..=255`)调制当前颜色的 Alpha 通道。
116    #[inline(always)]
117    pub const fn scale_alpha(self, opacity: u8) -> Self {
118        if opacity == 255 {
119            return self;
120        }
121        if opacity == 0 {
122            return Self::TRANSPARENT;
123        }
124        let a = ((self.a() as u16 * opacity as u16) / 255) as u8;
125        Self::rgba(self.r(), self.g(), self.b(), a)
126    }
127}
128
129/// 动画缓动曲线类型。
130#[repr(u8)]
131#[derive(Copy, Clone, PartialEq, Eq, Debug, Default)]
132pub enum Easing {
133    /// 线性匀速插值。
134    Linear = 0,
135    /// 三次方渐入(加速)。
136    EaseIn = 1,
137    /// 三次方渐出(减速,默认)。
138    #[default]
139    EaseOut = 2,
140    /// 三次方渐入渐出(S 型曲线)。
141    EaseInOut = 3,
142    /// 欠阻尼弹簧过冲曲线(带约 8% 物理回弹质感)。
143    Spring = 4,
144    /// 回拉过冲渐出(`easeOutBack`,末端约 10% 过冲后回落,适合弹窗/卡片入场)。
145    EaseOutBack = 5,
146    /// 落地弹跳渐出(`easeOutBounce`,模拟小球落地多次弹跳,结果不超出 `0..=256`)。
147    Bounce = 6,
148    /// 弹性振荡渐出(`easeOutElastic`,指数衰减正弦振荡,适合提醒/抖动效果)。
149    Elastic = 7,
150}
151
152impl Easing {
153    /// 从低 3 位编码还原缓动曲线(与 `Easing as u8` 互逆)。
154    #[inline(always)]
155    pub const fn from_bits(bits: u8) -> Self {
156        match bits & 0x07 {
157            0 => Self::Linear,
158            1 => Self::EaseIn,
159            2 => Self::EaseOut,
160            3 => Self::EaseInOut,
161            4 => Self::Spring,
162            5 => Self::EaseOutBack,
163            6 => Self::Bounce,
164            _ => Self::Elastic,
165        }
166    }
167
168    /// 纯整数定点缓动求值:输入归一化进度 `t_256`(`0..=256`),输出 `0..=256`
169    /// (`Spring` / `EaseOutBack` / `Elastic` 允许短暂过冲超出 `256` 或低于 `0`)。
170    #[inline]
171    pub fn apply_256(self, t_256: i32) -> i32 {
172        let t = t_256.clamp(0, 256);
173        if t >= 256 {
174            return 256;
175        }
176        match self {
177            Self::Linear => t,
178            Self::EaseIn => (t * t * t) >> 16,
179            Self::EaseOut => {
180                let inv = 256 - t;
181                256 - ((inv * inv * inv) >> 16)
182            }
183            Self::EaseInOut => {
184                if t < 128 {
185                    (4 * t * t * t) >> 16
186                } else {
187                    let inv = 256 - t;
188                    256 - ((4 * inv * inv * inv) >> 16)
189                }
190            }
191            Self::Spring => {
192                // 二阶欠阻尼弹簧拟合:快速上升并在 t ≈ 180..200 时产生约 +20..26/256 (8%~10%) 的过冲随后收敛至 256
193                let inv = 256 - t;
194                let base = 256 - ((inv * inv) >> 8);
195                let overshoot = ((9 * (t as i64) * (t as i64) * (inv as i64)) >> 19) as i32;
196                base + overshoot
197            }
198            Self::EaseOutBack => {
199                // 1 + c3·(t-1)³ + c1·(t-1)²,c1 ≈ 1.70158 (436/256),c3 ≈ 2.70158 (692/256)
200                let u = (t - 256) as i64;
201                let cubic = (692 * u * u * u) >> 24;
202                let quad = (436 * u * u) >> 16;
203                (256 + cubic + quad) as i32
204            }
205            Self::Bounce => {
206                // 标准 easeOutBounce 分段抛物线(n1 = 7.5625 = 121/16,d1 = 2.75)
207                let seg = |x: i32, base: i32| ((121 * x * x) >> 12) + base;
208                let v = if t < 93 {
209                    seg(t, 0)
210                } else if t < 186 {
211                    seg(t - 140, 192)
212                } else if t < 233 {
213                    seg(t - 209, 240)
214                } else {
215                    seg(t - 244, 252)
216                };
217                v.min(256)
218            }
219            Self::Elastic => {
220                // 2^(-10t) · sin((10t - 0.75) · 2π/3) + 1
221                let e = 10 * t; // 以 1/256 为单位的指数
222                let k = (e >> 8) as u32;
223                let frac = e & 0xFF;
224                // 2^-k 与 2^-(k+1) 之间线性插值近似 2^-(k + frac)
225                let hi = 256i32 >> k.min(16);
226                let decay = hi - ((hi >> 1) * frac >> 8);
227                let deg10 = (t * 12000) / 256 - 900;
228                let (sin_q10, _) = crate::sdf::sin_cos_deg10(deg10);
229                256 + ((decay * sin_q10) >> 10)
230            }
231        }
232    }
233
234    /// 按已流逝时间 `elapsed_ms` / 总时长 `duration_ms` 求值缓动输出(`0..=256` 定点数)。
235    #[inline]
236    pub fn sample_256(self, elapsed_ms: u32, duration_ms: u32) -> i32 {
237        if duration_ms == 0 || elapsed_ms >= duration_ms {
238            return 256;
239        }
240        self.apply_256(((elapsed_ms as u64 * 256) / duration_ms as u64) as i32)
241    }
242}
243
244/// 动画循环模式。
245#[repr(u8)]
246#[derive(Copy, Clone, PartialEq, Eq, Debug, Default)]
247pub enum LoopMode {
248    /// 单次过渡动画(默认)。
249    #[default]
250    Once = 0,
251    /// 无限单向循环(`0 -> 1 -> 0 -> 1`)。
252    Infinite = 1,
253    /// 无限往复呼吸循环(`0 -> 1 -> 0`)。
254    PingPong = 2,
255}
256
257/// 文本水平对齐方式。
258#[repr(u8)]
259#[derive(Copy, Clone, PartialEq, Eq, Debug, Default)]
260pub enum TextAlign {
261    /// 左对齐(默认)。
262    #[default]
263    Left = 0,
264    /// 水平居中对齐。
265    Center = 1,
266    /// 右对齐。
267    Right = 2,
268}
269
270/// 尺寸长度单位(严格 4 字节表示)。
271#[repr(C, i16)]
272#[derive(Copy, Clone, PartialEq, Eq, Debug, Default)]
273pub enum Length {
274    /// 由内容自适应决定尺寸。
275    #[default]
276    Auto = 0,
277    /// 固定像素长度。
278    Px(i16) = 1,
279    /// 撑满父容器可用空间(100%)。
280    Full = 2,
281    /// 按父容器可用空间的百分比(`0..=100`)计算长度。
282    Pct(i16) = 3,
283}
284
285/// 四边边距(4 字节当 `T = i8`)。
286#[repr(C)]
287#[derive(Copy, Clone, PartialEq, Eq, Debug, Default)]
288pub struct Edges<T> {
289    pub top: T,
290    pub right: T,
291    pub bottom: T,
292    pub left: T,
293}
294
295impl<T: Copy> Edges<T> {
296    /// 四边统一边距。
297    #[inline(always)]
298    pub const fn all(val: T) -> Self {
299        Self {
300            top: val,
301            right: val,
302            bottom: val,
303            left: val,
304        }
305    }
306
307    /// 水平与垂直对称边距。
308    #[inline(always)]
309    pub const fn xy(x: T, y: T) -> Self {
310        Self {
311            top: y,
312            right: x,
313            bottom: y,
314            left: x,
315        }
316    }
317}
318
319/// 主轴排列方向(1 bit)。
320#[derive(Copy, Clone, PartialEq, Eq, Debug)]
321pub enum FlexDir {
322    Row = 0,
323    Col = 1,
324}
325
326/// 主轴对齐方式(3 bits)。
327#[derive(Copy, Clone, PartialEq, Eq, Debug)]
328pub enum Justify {
329    Start = 0,
330    Center = 1,
331    End = 2,
332    Between = 3,
333    Around = 4,
334}
335
336/// 交叉轴对齐方式(2 bits,默认 `0 = Stretch` 遵循 CSS Flexbox 规范)。
337#[derive(Copy, Clone, PartialEq, Eq, Debug)]
338pub enum AlignItems {
339    Stretch = 0,
340    Center = 1,
341    Start = 2,
342    End = 3,
343}
344
345/// 紧凑位域样式结构体(严格 **24 字节**)。
346#[repr(C)]
347#[derive(Copy, Clone, PartialEq, Eq, Debug)]
348pub struct Style {
349    /// 宽度策略(4 Bytes)。
350    pub width: Length,
351    /// 高度策略(4 Bytes)。
352    pub height: Length,
353    /// 四周内边距(4 Bytes)。
354    pub padding: Edges<i8>,
355    /// 背景填充色(4 Bytes)。
356    pub bg: Color,
357    /// 边框颜色(4 Bytes)。
358    pub border_color: Color,
359    /// 子节点间距(1 Byte)。
360    pub gap: i8,
361    /// 圆角半径 `0..=127px`(1 Byte)。
362    pub rounded: u8,
363    /// 边框宽度(1 Byte)。
364    pub border_width: u8,
365    /// 位域:`flex_dir(1b) | justify(3b) | items_align(2b) | flex_grow(2b)`(1 Byte)。
366    pub flex_flags: u8,
367}
368
369const _: () = assert!(core::mem::size_of::<Style>() == 24);
370
371impl Default for Style {
372    #[inline(always)]
373    fn default() -> Self {
374        Self::DEFAULT
375    }
376}
377
378impl Style {
379    /// 全零默认值样式常量(供所有组件 `const fn new` 零成本初始化)。
380    pub const DEFAULT: Self = Self::new();
381
382    /// 构造全默认样式。
383    #[inline(always)]
384    pub const fn new() -> Self {
385        Self {
386            width: Length::Auto,
387            height: Length::Auto,
388            padding: Edges::all(0),
389            bg: Color::TRANSPARENT,
390            border_color: Color::TRANSPARENT,
391            gap: 0,
392            rounded: 0,
393            border_width: 0,
394            flex_flags: 0,
395        }
396    }
397
398    /// 设置水平主轴 `Row`。
399    #[inline(always)]
400    pub fn set_row(&mut self) {
401        self.flex_flags &= !0b0000_0001;
402    }
403
404    /// 设置垂直主轴 `Col`。
405    #[inline(always)]
406    pub fn set_col(&mut self) {
407        self.flex_flags |= 0b0000_0001;
408    }
409
410    /// 读取主轴方向。
411    #[inline(always)]
412    pub const fn flex_dir(&self) -> FlexDir {
413        if (self.flex_flags & 0b0000_0001) != 0 {
414            FlexDir::Col
415        } else {
416            FlexDir::Row
417        }
418    }
419
420    /// 设置主轴对齐方式。
421    #[inline(always)]
422    pub fn set_justify(&mut self, justify: Justify) {
423        self.flex_flags = (self.flex_flags & !0b0000_1110) | ((justify as u8 & 0b111) << 1);
424    }
425
426    /// 设置主轴居中对齐。
427    #[inline(always)]
428    pub fn set_justify_center(&mut self) {
429        self.set_justify(Justify::Center);
430    }
431
432    /// 设置主轴两端对齐。
433    #[inline(always)]
434    pub fn set_justify_between(&mut self) {
435        self.set_justify(Justify::Between);
436    }
437
438    /// 读取主轴对齐方式。
439    #[inline(always)]
440    pub const fn justify(&self) -> Justify {
441        match (self.flex_flags >> 1) & 0b111 {
442            1 => Justify::Center,
443            2 => Justify::End,
444            3 => Justify::Between,
445            4 => Justify::Around,
446            _ => Justify::Start,
447        }
448    }
449
450    /// 设置交叉轴对齐方式。
451    #[inline(always)]
452    pub fn set_items_align(&mut self, align: AlignItems) {
453        self.flex_flags = (self.flex_flags & !0b0011_0000) | ((align as u8 & 0b11) << 4);
454    }
455
456    /// 设置交叉轴居中对齐。
457    #[inline(always)]
458    pub fn set_items_center(&mut self) {
459        self.set_items_align(AlignItems::Center);
460    }
461
462    /// 读取交叉轴对齐方式。
463    #[inline(always)]
464    pub const fn items_align(&self) -> AlignItems {
465        match (self.flex_flags >> 4) & 0b11 {
466            1 => AlignItems::Center,
467            2 => AlignItems::Start,
468            3 => AlignItems::End,
469            _ => AlignItems::Stretch,
470        }
471    }
472
473    /// 设置弹性拉伸权重(`0..=3`)。
474    #[inline(always)]
475    pub fn set_grow(&mut self, weight: u8) {
476        let w = if weight > 3 { 3 } else { weight };
477        self.flex_flags = (self.flex_flags & !0b1100_0000) | (w << 6);
478    }
479
480    /// 读取弹性拉伸权重(`0..=3`)。
481    #[inline(always)]
482    pub const fn flex_grow(&self) -> u8 {
483        (self.flex_flags >> 6) & 0b11
484    }
485
486    /// 读取圆角半径(`0..=127px`,剥离最高位 `flex_wrap` 标志)。
487    #[inline(always)]
488    pub const fn rounded_radius(&self) -> u8 {
489        self.rounded & 0x7F
490    }
491
492    /// 设置圆角半径(`0..=127px`,保留最高位 `flex_wrap` 标志)。
493    #[inline(always)]
494    pub fn set_rounded(&mut self, radius: u8) {
495        self.rounded = (self.rounded & 0x80) | (radius.min(127) & 0x7F);
496    }
497
498    /// 是否启用多行自动折行(`flex_wrap`,存储在 `rounded` 的第 7 位)。
499    #[inline(always)]
500    pub const fn flex_wrap(&self) -> bool {
501        (self.rounded & 0x80) != 0
502    }
503
504    /// 设置多行自动折行(`flex_wrap`)。
505    #[inline(always)]
506    pub fn set_flex_wrap(&mut self, wrap: bool) {
507        if wrap {
508            self.rounded |= 0x80;
509        } else {
510            self.rounded &= 0x7F;
511        }
512    }
513
514    /// 读取边框宽度(`0..=15px`,存储在 `border_width` 低 4 位)。
515    #[inline(always)]
516    pub const fn border_px(&self) -> u8 {
517        self.border_width & 0x0F
518    }
519
520    /// 设置边框宽度(`0..=15px`)。
521    #[inline(always)]
522    pub fn set_border_px(&mut self, width: u8) {
523        self.border_width = (self.border_width & 0xF0) | (width.min(15) & 0x0F);
524    }
525
526    /// 读取四边统一外边距(`0..=15px`,存储在 `border_width` 高 4 位)。
527    #[inline(always)]
528    pub const fn margin_px(&self) -> i8 {
529        ((self.border_width >> 4) & 0x0F) as i8
530    }
531
532    /// 设置四边统一外边距(`0..=15px`)。
533    #[inline(always)]
534    pub fn set_margin_px(&mut self, px: i8) {
535        let m = px.clamp(0, 15) as u8;
536        self.border_width = (self.border_width & 0x0F) | (m << 4);
537    }
538}
539
540/// GPUI 风格像素单位辅助函数(四舍五入转换为 `i16`,兼容 `.w(px(250.))` 与 `.w(250)`)。
541#[inline(always)]
542pub const fn px(val: f32) -> i16 {
543    if val >= 0.0 {
544        (val + 0.5) as i16
545    } else {
546        (val - 0.5) as i16
547    }
548}
549
550/// GPUI 风格 24 位十六进制 RGB 颜色构造函数(如 `rgb(0xd4d4d4)`)。
551#[inline(always)]
552pub const fn rgb(hex: u32) -> Color {
553    Color::hex(hex)
554}
555
556/// GPUI 风格 32 位十六进制 `0xRRGGBBAA` 颜色构造函数(如 `rgba(0x171717cc)`)。
557#[inline(always)]
558pub const fn rgba(hex: u32) -> Color {
559    Color::hex_alpha(hex)
560}
561
562/// GPUI 风格条件链式构建 Trait(对所有 `Sized` 类型自动实现,零运行时开销)。
563///
564/// 支持在任意 `Div`、`Text`、组件或 `StyleRefinement` 上直接使用 `.when(...)` / `.when_some(...)`:
565/// ```ignore
566/// item.size_8()
567///     .when(state.is_active(), |s| s.bg(rgb(0x171717)).text_color(rgb(0xffffff)))
568///     .when(!state.is_disabled(), |s| s.hover(|h| h.bg(rgb(0xf5f5f5))))
569/// ```
570pub trait FluentBuilder: Sized {
571    /// 当 `condition` 为 `true` 时执行闭包修饰自身,否则原样返回。
572    #[inline(always)]
573    fn when(self, condition: bool, then: impl FnOnce(Self) -> Self) -> Self {
574        if condition {
575            then(self)
576        } else {
577            self
578        }
579    }
580
581    /// 根据 `condition` 在两个修饰分支之间二选一。
582    #[inline(always)]
583    fn when_else(
584        self,
585        condition: bool,
586        then: impl FnOnce(Self) -> Self,
587        else_fn: impl FnOnce(Self) -> Self,
588    ) -> Self {
589        if condition {
590            then(self)
591        } else {
592            else_fn(self)
593        }
594    }
595
596    /// 当 `option` 为 `Some(value)` 时执行闭包修饰自身,否则原样返回。
597    #[inline(always)]
598    fn when_some<O>(self, option: Option<O>, then: impl FnOnce(Self, O) -> Self) -> Self {
599        match option {
600            Some(value) => then(self, value),
601            None => self,
602        }
603    }
604
605    /// 当 `option` 为 `None` 时执行闭包修饰自身,否则原样返回。
606    #[inline(always)]
607    fn when_none<O>(self, option: &Option<O>, then: impl FnOnce(Self) -> Self) -> Self {
608        if option.is_none() {
609            then(self)
610        } else {
611            self
612        }
613    }
614
615    /// 通用管道映射变换(避免与 `Iterator::map` / `Option::map` 重名)。
616    #[inline(always)]
617    fn apply<U>(self, f: impl FnOnce(Self) -> U) -> U {
618        f(self)
619    }
620}
621
622impl<T: Sized> FluentBuilder for T {}
623
624/// 交互态样式覆写增量(供 `Div::hover(|s| ...)`、`Div::active(|s| ...)`、`Div::focus(|s| ...)` 使用,零堆分配)。
625#[derive(Copy, Clone, PartialEq, Eq, Debug, Default)]
626pub struct StyleRefinement {
627    pub bg: Option<Color>,
628    pub border_width: Option<u8>,
629    pub border_color: Option<Color>,
630    pub text_color: Option<Color>,
631    pub opacity: Option<u8>,
632    pub rounded: Option<u8>,
633}
634
635impl StyleRefinement {
636    /// 创建空的交互态样式增量。
637    #[inline(always)]
638    pub const fn new() -> Self {
639        Self {
640            bg: None,
641            border_width: None,
642            border_color: None,
643            text_color: None,
644            opacity: None,
645            rounded: None,
646        }
647    }
648
649    /// 是否未配置任何视觉覆写。
650    #[inline(always)]
651    pub const fn is_empty(&self) -> bool {
652        self.bg.is_none()
653            && self.border_width.is_none()
654            && self.border_color.is_none()
655            && self.text_color.is_none()
656            && self.opacity.is_none()
657            && self.rounded.is_none()
658    }
659
660    /// 是否仅覆写了背景色(可直接走 `DivNode` 内联零分配快速路径)。
661    #[inline(always)]
662    pub const fn is_bg_only(&self) -> bool {
663        self.bg.is_some()
664            && self.border_width.is_none()
665            && self.border_color.is_none()
666            && self.text_color.is_none()
667            && self.opacity.is_none()
668            && self.rounded.is_none()
669    }
670
671    #[inline(always)]
672    pub const fn bg(mut self, color: Color) -> Self {
673        self.bg = Some(color);
674        self
675    }
676
677    #[inline(always)]
678    pub const fn border(mut self, width: u8, color: Color) -> Self {
679        self.border_width = Some(width);
680        self.border_color = Some(color);
681        self
682    }
683
684    #[inline(always)]
685    pub const fn border_0(mut self) -> Self {
686        self.border_width = Some(0);
687        self
688    }
689
690    #[inline(always)]
691    pub const fn border_1(mut self) -> Self {
692        self.border_width = Some(1);
693        self
694    }
695
696    #[inline(always)]
697    pub const fn border_2(mut self) -> Self {
698        self.border_width = Some(2);
699        self
700    }
701
702    #[inline(always)]
703    pub const fn border_4(mut self) -> Self {
704        self.border_width = Some(4);
705        self
706    }
707
708    #[inline(always)]
709    pub const fn border_color(mut self, color: Color) -> Self {
710        self.border_color = Some(color);
711        self
712    }
713
714    #[inline(always)]
715    pub const fn text_color(mut self, color: Color) -> Self {
716        self.text_color = Some(color);
717        self
718    }
719
720    #[inline(always)]
721    pub const fn opacity(mut self, alpha: u8) -> Self {
722        self.opacity = Some(alpha);
723        self
724    }
725
726    #[inline(always)]
727    pub const fn opacity_f(mut self, alpha: f32) -> Self {
728        let clamped = if alpha <= 0.0 {
729            0.0
730        } else if alpha >= 1.0 {
731            1.0
732        } else {
733            alpha
734        };
735        self.opacity = Some((clamped * 255.0 + 0.5) as u8);
736        self
737    }
738
739    #[inline(always)]
740    pub const fn rounded(mut self, radius: u8) -> Self {
741        self.rounded = Some(radius);
742        self
743    }
744
745    #[inline(always)]
746    pub const fn rounded_none(self) -> Self {
747        self.rounded(0)
748    }
749
750    #[inline(always)]
751    pub const fn rounded_sm(self) -> Self {
752        self.rounded(4)
753    }
754
755    #[inline(always)]
756    pub const fn rounded_md(self) -> Self {
757        self.rounded(6)
758    }
759
760    #[inline(always)]
761    pub const fn rounded_lg(self) -> Self {
762        self.rounded(8)
763    }
764
765    #[inline(always)]
766    pub const fn rounded_xl(self) -> Self {
767        self.rounded(12)
768    }
769
770    #[inline(always)]
771    pub const fn rounded_full(self) -> Self {
772        self.rounded(127)
773    }
774}
775
776/// 统一的 Tailwind 风格链式修饰符 Trait,`Div` 与自定义组件均可实现。
777pub trait Styled: Sized {
778    /// 获取内部 `Style` 的可变引用。
779    fn style_mut(&mut self) -> &mut Style;
780
781    /// 开启弹性布局(等价 CSS `display: flex`,默认水平主轴 `Row`)。
782    #[inline(always)]
783    fn flex(mut self) -> Self {
784        self.style_mut().set_row();
785        self
786    }
787
788    #[inline(always)]
789    fn flex_row(mut self) -> Self {
790        self.style_mut().set_row();
791        self
792    }
793
794    #[inline(always)]
795    fn flex_col(mut self) -> Self {
796        self.style_mut().set_col();
797        self
798    }
799
800    #[inline(always)]
801    fn flex_wrap(mut self) -> Self {
802        self.style_mut().set_flex_wrap(true);
803        self
804    }
805
806    #[inline(always)]
807    fn flex_nowrap(mut self) -> Self {
808        self.style_mut().set_flex_wrap(false);
809        self
810    }
811
812    #[inline(always)]
813    fn flex_1(mut self) -> Self {
814        self.style_mut().set_grow(1);
815        self
816    }
817
818    #[inline(always)]
819    fn flex_none(mut self) -> Self {
820        self.style_mut().set_grow(0);
821        self
822    }
823
824    #[inline(always)]
825    fn size_full(mut self) -> Self {
826        self.style_mut().width = Length::Full;
827        self.style_mut().height = Length::Full;
828        self
829    }
830
831    /// 同时设置等宽高正方形尺寸(像素)。
832    #[inline(always)]
833    fn size(mut self, px: i16) -> Self {
834        let s = self.style_mut();
835        s.width = Length::Px(px);
836        s.height = Length::Px(px);
837        self
838    }
839
840    #[inline(always)]
841    fn w_full(mut self) -> Self {
842        self.style_mut().width = Length::Full;
843        self
844    }
845
846    #[inline(always)]
847    fn h_full(mut self) -> Self {
848        self.style_mut().height = Length::Full;
849        self
850    }
851
852    #[inline(always)]
853    fn w_auto(mut self) -> Self {
854        self.style_mut().width = Length::Auto;
855        self
856    }
857
858    #[inline(always)]
859    fn h_auto(mut self) -> Self {
860        self.style_mut().height = Length::Auto;
861        self
862    }
863
864    #[inline(always)]
865    fn w(mut self, px: i16) -> Self {
866        self.style_mut().width = Length::Px(px);
867        self
868    }
869
870    #[inline(always)]
871    fn h(mut self, px: i16) -> Self {
872        self.style_mut().height = Length::Px(px);
873        self
874    }
875
876    /// 设置宽度占父容器可用宽度的百分比(`0..=100`)。
877    #[inline(always)]
878    fn w_pct(mut self, pct: i16) -> Self {
879        self.style_mut().width = Length::Pct(pct.clamp(0, 100));
880        self
881    }
882
883    /// 设置高度占父容器可用高度的百分比(`0..=100`)。
884    #[inline(always)]
885    fn h_pct(mut self, pct: i16) -> Self {
886        self.style_mut().height = Length::Pct(pct.clamp(0, 100));
887        self
888    }
889
890    #[inline(always)]
891    fn w_1_2(self) -> Self { self.w_pct(50) }
892    #[inline(always)]
893    fn w_1_3(self) -> Self { self.w_pct(33) }
894    #[inline(always)]
895    fn w_2_3(self) -> Self { self.w_pct(67) }
896    #[inline(always)]
897    fn w_1_4(self) -> Self { self.w_pct(25) }
898    #[inline(always)]
899    fn w_3_4(self) -> Self { self.w_pct(75) }
900    #[inline(always)]
901    fn h_1_2(self) -> Self { self.h_pct(50) }
902
903    // --- Tailwind 尺寸档位简写(1 unit = 4px) ---
904    #[inline(always)] fn size_0(self) -> Self { self.size(0) }
905    #[inline(always)] fn size_0_5(self) -> Self { self.size(2) }
906    #[inline(always)] fn size_1(self) -> Self { self.size(4) }
907    #[inline(always)] fn size_1_5(self) -> Self { self.size(6) }
908    #[inline(always)] fn size_2(self) -> Self { self.size(8) }
909    #[inline(always)] fn size_2_5(self) -> Self { self.size(10) }
910    #[inline(always)] fn size_3(self) -> Self { self.size(12) }
911    #[inline(always)] fn size_3_5(self) -> Self { self.size(14) }
912    #[inline(always)] fn size_4(self) -> Self { self.size(16) }
913    #[inline(always)] fn size_5(self) -> Self { self.size(20) }
914    #[inline(always)] fn size_6(self) -> Self { self.size(24) }
915    #[inline(always)] fn size_7(self) -> Self { self.size(28) }
916    #[inline(always)] fn size_8(self) -> Self { self.size(32) }
917    #[inline(always)] fn size_9(self) -> Self { self.size(36) }
918    #[inline(always)] fn size_10(self) -> Self { self.size(40) }
919    #[inline(always)] fn size_11(self) -> Self { self.size(44) }
920    #[inline(always)] fn size_12(self) -> Self { self.size(48) }
921    #[inline(always)] fn size_14(self) -> Self { self.size(56) }
922    #[inline(always)] fn size_16(self) -> Self { self.size(64) }
923    #[inline(always)] fn size_20(self) -> Self { self.size(80) }
924    #[inline(always)] fn size_24(self) -> Self { self.size(96) }
925    #[inline(always)] fn size_32(self) -> Self { self.size(128) }
926
927    #[inline(always)] fn w_0(self) -> Self { self.w(0) }
928    #[inline(always)] fn w_0_5(self) -> Self { self.w(2) }
929    #[inline(always)] fn w_1(self) -> Self { self.w(4) }
930    #[inline(always)] fn w_1_5(self) -> Self { self.w(6) }
931    #[inline(always)] fn w_2(self) -> Self { self.w(8) }
932    #[inline(always)] fn w_2_5(self) -> Self { self.w(10) }
933    #[inline(always)] fn w_3(self) -> Self { self.w(12) }
934    #[inline(always)] fn w_3_5(self) -> Self { self.w(14) }
935    #[inline(always)] fn w_4(self) -> Self { self.w(16) }
936    #[inline(always)] fn w_5(self) -> Self { self.w(20) }
937    #[inline(always)] fn w_6(self) -> Self { self.w(24) }
938    #[inline(always)] fn w_7(self) -> Self { self.w(28) }
939    #[inline(always)] fn w_8(self) -> Self { self.w(32) }
940    #[inline(always)] fn w_9(self) -> Self { self.w(36) }
941    #[inline(always)] fn w_10(self) -> Self { self.w(40) }
942    #[inline(always)] fn w_11(self) -> Self { self.w(44) }
943    #[inline(always)] fn w_12(self) -> Self { self.w(48) }
944    #[inline(always)] fn w_14(self) -> Self { self.w(56) }
945    #[inline(always)] fn w_16(self) -> Self { self.w(64) }
946    #[inline(always)] fn w_20(self) -> Self { self.w(80) }
947    #[inline(always)] fn w_24(self) -> Self { self.w(96) }
948    #[inline(always)] fn w_28(self) -> Self { self.w(112) }
949    #[inline(always)] fn w_32(self) -> Self { self.w(128) }
950    #[inline(always)] fn w_36(self) -> Self { self.w(144) }
951    #[inline(always)] fn w_40(self) -> Self { self.w(160) }
952    #[inline(always)] fn w_44(self) -> Self { self.w(176) }
953    #[inline(always)] fn w_48(self) -> Self { self.w(192) }
954    #[inline(always)] fn w_52(self) -> Self { self.w(208) }
955    #[inline(always)] fn w_56(self) -> Self { self.w(224) }
956    #[inline(always)] fn w_60(self) -> Self { self.w(240) }
957    #[inline(always)] fn w_64(self) -> Self { self.w(256) }
958    #[inline(always)] fn w_72(self) -> Self { self.w(288) }
959    #[inline(always)] fn w_80(self) -> Self { self.w(320) }
960    #[inline(always)] fn w_96(self) -> Self { self.w(384) }
961
962    #[inline(always)] fn h_0(self) -> Self { self.h(0) }
963    #[inline(always)] fn h_0_5(self) -> Self { self.h(2) }
964    #[inline(always)] fn h_1(self) -> Self { self.h(4) }
965    #[inline(always)] fn h_1_5(self) -> Self { self.h(6) }
966    #[inline(always)] fn h_2(self) -> Self { self.h(8) }
967    #[inline(always)] fn h_2_5(self) -> Self { self.h(10) }
968    #[inline(always)] fn h_3(self) -> Self { self.h(12) }
969    #[inline(always)] fn h_3_5(self) -> Self { self.h(14) }
970    #[inline(always)] fn h_4(self) -> Self { self.h(16) }
971    #[inline(always)] fn h_5(self) -> Self { self.h(20) }
972    #[inline(always)] fn h_6(self) -> Self { self.h(24) }
973    #[inline(always)] fn h_7(self) -> Self { self.h(28) }
974    #[inline(always)] fn h_8(self) -> Self { self.h(32) }
975    #[inline(always)] fn h_9(self) -> Self { self.h(36) }
976    #[inline(always)] fn h_10(self) -> Self { self.h(40) }
977    #[inline(always)] fn h_11(self) -> Self { self.h(44) }
978    #[inline(always)] fn h_12(self) -> Self { self.h(48) }
979    #[inline(always)] fn h_14(self) -> Self { self.h(56) }
980    #[inline(always)] fn h_16(self) -> Self { self.h(64) }
981    #[inline(always)] fn h_20(self) -> Self { self.h(80) }
982    #[inline(always)] fn h_24(self) -> Self { self.h(96) }
983    #[inline(always)] fn h_32(self) -> Self { self.h(128) }
984    #[inline(always)] fn h_40(self) -> Self { self.h(160) }
985    #[inline(always)] fn h_48(self) -> Self { self.h(192) }
986    #[inline(always)] fn h_56(self) -> Self { self.h(224) }
987    #[inline(always)] fn h_64(self) -> Self { self.h(256) }
988
989    #[inline(always)]
990    fn p(mut self, px: i8) -> Self {
991        self.style_mut().padding = Edges::all(px);
992        self
993    }
994
995    #[inline(always)]
996    fn px(mut self, px: i8) -> Self {
997        let p = &mut self.style_mut().padding;
998        p.left = px;
999        p.right = px;
1000        self
1001    }
1002
1003    #[inline(always)]
1004    fn py(mut self, px: i8) -> Self {
1005        let p = &mut self.style_mut().padding;
1006        p.top = px;
1007        p.bottom = px;
1008        self
1009    }
1010
1011    #[inline(always)]
1012    fn pt(mut self, px: i8) -> Self {
1013        self.style_mut().padding.top = px;
1014        self
1015    }
1016
1017    #[inline(always)]
1018    fn pb(mut self, px: i8) -> Self {
1019        self.style_mut().padding.bottom = px;
1020        self
1021    }
1022
1023    #[inline(always)]
1024    fn pl(mut self, px: i8) -> Self {
1025        self.style_mut().padding.left = px;
1026        self
1027    }
1028
1029    #[inline(always)]
1030    fn pr(mut self, px: i8) -> Self {
1031        self.style_mut().padding.right = px;
1032        self
1033    }
1034
1035    // --- Tailwind 内边距档位简写 ---
1036    #[inline(always)] fn p_0(self) -> Self { self.p(0) }
1037    #[inline(always)] fn p_0p5(self) -> Self { self.p(2) }
1038    #[inline(always)] fn p_0_5(self) -> Self { self.p(2) }
1039    #[inline(always)] fn p_1(self) -> Self { self.p(4) }
1040    #[inline(always)] fn p_1p5(self) -> Self { self.p(6) }
1041    #[inline(always)] fn p_1_5(self) -> Self { self.p(6) }
1042    #[inline(always)] fn p_2(self) -> Self { self.p(8) }
1043    #[inline(always)] fn p_2p5(self) -> Self { self.p(10) }
1044    #[inline(always)] fn p_2_5(self) -> Self { self.p(10) }
1045    #[inline(always)] fn p_3(self) -> Self { self.p(12) }
1046    #[inline(always)] fn p_3p5(self) -> Self { self.p(14) }
1047    #[inline(always)] fn p_3_5(self) -> Self { self.p(14) }
1048    #[inline(always)] fn p_4(self) -> Self { self.p(16) }
1049    #[inline(always)] fn p_5(self) -> Self { self.p(20) }
1050    #[inline(always)] fn p_6(self) -> Self { self.p(24) }
1051    #[inline(always)] fn p_8(self) -> Self { self.p(32) }
1052    #[inline(always)] fn p_10(self) -> Self { self.p(40) }
1053    #[inline(always)] fn p_12(self) -> Self { self.p(48) }
1054
1055    #[inline(always)] fn px_0(self) -> Self { self.px(0) }
1056    #[inline(always)] fn px_0p5(self) -> Self { self.px(2) }
1057    #[inline(always)] fn px_0_5(self) -> Self { self.px(2) }
1058    #[inline(always)] fn px_1(self) -> Self { self.px(4) }
1059    #[inline(always)] fn px_1p5(self) -> Self { self.px(6) }
1060    #[inline(always)] fn px_1_5(self) -> Self { self.px(6) }
1061    #[inline(always)] fn px_2(self) -> Self { self.px(8) }
1062    #[inline(always)] fn px_2p5(self) -> Self { self.px(10) }
1063    #[inline(always)] fn px_2_5(self) -> Self { self.px(10) }
1064    #[inline(always)] fn px_3(self) -> Self { self.px(12) }
1065    #[inline(always)] fn px_3p5(self) -> Self { self.px(14) }
1066    #[inline(always)] fn px_3_5(self) -> Self { self.px(14) }
1067    #[inline(always)] fn px_4(self) -> Self { self.px(16) }
1068    #[inline(always)] fn px_5(self) -> Self { self.px(20) }
1069    #[inline(always)] fn px_6(self) -> Self { self.px(24) }
1070    #[inline(always)] fn px_8(self) -> Self { self.px(32) }
1071
1072    #[inline(always)] fn py_0(self) -> Self { self.py(0) }
1073    #[inline(always)] fn py_0p5(self) -> Self { self.py(2) }
1074    #[inline(always)] fn py_0_5(self) -> Self { self.py(2) }
1075    #[inline(always)] fn py_1(self) -> Self { self.py(4) }
1076    #[inline(always)] fn py_1p5(self) -> Self { self.py(6) }
1077    #[inline(always)] fn py_1_5(self) -> Self { self.py(6) }
1078    #[inline(always)] fn py_2(self) -> Self { self.py(8) }
1079    #[inline(always)] fn py_2p5(self) -> Self { self.py(10) }
1080    #[inline(always)] fn py_2_5(self) -> Self { self.py(10) }
1081    #[inline(always)] fn py_3(self) -> Self { self.py(12) }
1082    #[inline(always)] fn py_3p5(self) -> Self { self.py(14) }
1083    #[inline(always)] fn py_3_5(self) -> Self { self.py(14) }
1084    #[inline(always)] fn py_4(self) -> Self { self.py(16) }
1085    #[inline(always)] fn py_5(self) -> Self { self.py(20) }
1086    #[inline(always)] fn py_6(self) -> Self { self.py(24) }
1087    #[inline(always)] fn py_8(self) -> Self { self.py(32) }
1088
1089    #[inline(always)] fn pt_0(self) -> Self { self.pt(0) }
1090    #[inline(always)] fn pt_1(self) -> Self { self.pt(4) }
1091    #[inline(always)] fn pt_2(self) -> Self { self.pt(8) }
1092    #[inline(always)] fn pt_3(self) -> Self { self.pt(12) }
1093    #[inline(always)] fn pt_4(self) -> Self { self.pt(16) }
1094    #[inline(always)] fn pb_0(self) -> Self { self.pb(0) }
1095    #[inline(always)] fn pb_1(self) -> Self { self.pb(4) }
1096    #[inline(always)] fn pb_2(self) -> Self { self.pb(8) }
1097    #[inline(always)] fn pb_3(self) -> Self { self.pb(12) }
1098    #[inline(always)] fn pb_4(self) -> Self { self.pb(16) }
1099    #[inline(always)] fn pl_0(self) -> Self { self.pl(0) }
1100    #[inline(always)] fn pl_1(self) -> Self { self.pl(4) }
1101    #[inline(always)] fn pl_2(self) -> Self { self.pl(8) }
1102    #[inline(always)] fn pl_3(self) -> Self { self.pl(12) }
1103    #[inline(always)] fn pl_4(self) -> Self { self.pl(16) }
1104    #[inline(always)] fn pr_0(self) -> Self { self.pr(0) }
1105    #[inline(always)] fn pr_1(self) -> Self { self.pr(4) }
1106    #[inline(always)] fn pr_2(self) -> Self { self.pr(8) }
1107    #[inline(always)] fn pr_3(self) -> Self { self.pr(12) }
1108    #[inline(always)] fn pr_4(self) -> Self { self.pr(16) }
1109
1110    #[inline(always)]
1111    fn m(mut self, px: i8) -> Self {
1112        self.style_mut().set_margin_px(px);
1113        self
1114    }
1115
1116    #[inline(always)] fn m_0(self) -> Self { self.m(0) }
1117    #[inline(always)] fn m_0_5(self) -> Self { self.m(2) }
1118    #[inline(always)] fn m_1(self) -> Self { self.m(4) }
1119    #[inline(always)] fn m_1_5(self) -> Self { self.m(6) }
1120    #[inline(always)] fn m_2(self) -> Self { self.m(8) }
1121    #[inline(always)] fn m_2_5(self) -> Self { self.m(10) }
1122    #[inline(always)] fn m_3(self) -> Self { self.m(12) }
1123    #[inline(always)] fn m_4(self) -> Self { self.m(16) }
1124
1125    #[inline(always)]
1126    fn gap(mut self, px: i8) -> Self {
1127        self.style_mut().gap = px;
1128        self
1129    }
1130
1131    #[inline(always)] fn gap_0(self) -> Self { self.gap(0) }
1132    #[inline(always)] fn gap_0p5(self) -> Self { self.gap(2) }
1133    #[inline(always)] fn gap_0_5(self) -> Self { self.gap(2) }
1134    #[inline(always)] fn gap_1(self) -> Self { self.gap(4) }
1135    #[inline(always)] fn gap_1p5(self) -> Self { self.gap(6) }
1136    #[inline(always)] fn gap_1_5(self) -> Self { self.gap(6) }
1137    #[inline(always)] fn gap_2(self) -> Self { self.gap(8) }
1138    #[inline(always)] fn gap_2p5(self) -> Self { self.gap(10) }
1139    #[inline(always)] fn gap_2_5(self) -> Self { self.gap(10) }
1140    #[inline(always)] fn gap_3(self) -> Self { self.gap(12) }
1141    #[inline(always)] fn gap_3p5(self) -> Self { self.gap(14) }
1142    #[inline(always)] fn gap_3_5(self) -> Self { self.gap(14) }
1143    #[inline(always)] fn gap_4(self) -> Self { self.gap(16) }
1144    #[inline(always)] fn gap_5(self) -> Self { self.gap(20) }
1145    #[inline(always)] fn gap_6(self) -> Self { self.gap(24) }
1146    #[inline(always)] fn gap_8(self) -> Self { self.gap(32) }
1147
1148    #[inline(always)]
1149    fn flex_grow(mut self, weight: u8) -> Self {
1150        self.style_mut().set_grow(weight);
1151        self
1152    }
1153
1154    #[inline(always)]
1155    fn items_center(mut self) -> Self {
1156        self.style_mut().set_items_center();
1157        self
1158    }
1159
1160    #[inline(always)]
1161    fn items_start(mut self) -> Self {
1162        self.style_mut().set_items_align(AlignItems::Start);
1163        self
1164    }
1165
1166    #[inline(always)]
1167    fn items_end(mut self) -> Self {
1168        self.style_mut().set_items_align(AlignItems::End);
1169        self
1170    }
1171
1172    #[inline(always)]
1173    fn items_stretch(mut self) -> Self {
1174        self.style_mut().set_items_align(AlignItems::Stretch);
1175        self
1176    }
1177
1178    #[inline(always)]
1179    fn justify_start(mut self) -> Self {
1180        self.style_mut().set_justify(Justify::Start);
1181        self
1182    }
1183
1184    #[inline(always)]
1185    fn justify_center(mut self) -> Self {
1186        self.style_mut().set_justify_center();
1187        self
1188    }
1189
1190    #[inline(always)]
1191    fn justify_between(mut self) -> Self {
1192        self.style_mut().set_justify_between();
1193        self
1194    }
1195
1196    #[inline(always)]
1197    fn justify_end(mut self) -> Self {
1198        self.style_mut().set_justify(Justify::End);
1199        self
1200    }
1201
1202    #[inline(always)]
1203    fn justify_around(mut self) -> Self {
1204        self.style_mut().set_justify(Justify::Around);
1205        self
1206    }
1207
1208    #[inline(always)]
1209    fn bg(mut self, color: Color) -> Self {
1210        self.style_mut().bg = color;
1211        self
1212    }
1213
1214    #[inline(always)]
1215    fn rounded(mut self, radius: u8) -> Self {
1216        self.style_mut().set_rounded(radius);
1217        self
1218    }
1219
1220    #[inline(always)] fn rounded_none(self) -> Self { self.rounded(0) }
1221    #[inline(always)] fn rounded_xs(self) -> Self { self.rounded(2) }
1222    #[inline(always)] fn rounded_sm(self) -> Self { self.rounded(4) }
1223    #[inline(always)] fn rounded_md(self) -> Self { self.rounded(6) }
1224    #[inline(always)] fn rounded_lg(self) -> Self { self.rounded(8) }
1225    #[inline(always)] fn rounded_xl(self) -> Self { self.rounded(12) }
1226    #[inline(always)] fn rounded_2xl(self) -> Self { self.rounded(16) }
1227    #[inline(always)] fn rounded_3xl(self) -> Self { self.rounded(24) }
1228    #[inline(always)] fn rounded_full(self) -> Self { self.rounded(127) }
1229
1230    #[inline(always)]
1231    fn border(mut self, width: u8, color: Color) -> Self {
1232        let s = self.style_mut();
1233        s.set_border_px(width);
1234        s.border_color = color;
1235        self
1236    }
1237
1238    #[inline(always)]
1239    fn border_0(mut self) -> Self {
1240        self.style_mut().set_border_px(0);
1241        self
1242    }
1243
1244    #[inline(always)]
1245    fn border_1(mut self) -> Self {
1246        self.style_mut().set_border_px(1);
1247        self
1248    }
1249
1250    #[inline(always)]
1251    fn border_2(mut self) -> Self {
1252        self.style_mut().set_border_px(2);
1253        self
1254    }
1255
1256    #[inline(always)]
1257    fn border_4(mut self) -> Self {
1258        self.style_mut().set_border_px(4);
1259        self
1260    }
1261
1262    #[inline(always)]
1263    fn border_8(mut self) -> Self {
1264        self.style_mut().set_border_px(8);
1265        self
1266    }
1267
1268    #[inline(always)]
1269    fn border_color(mut self, color: Color) -> Self {
1270        self.style_mut().border_color = color;
1271        self
1272    }
1273
1274    #[inline(always)]
1275    fn flex_shrink_0(self) -> Self {
1276        self
1277    }
1278}
1279
1280pub use crate::style_ext::{StyleExt, StyledExt};