cotis_defaults/element_configs/style/sizing.rs
1#[cfg(feature = "serde")]
2use serde::{Deserialize, Serialize};
3use std::fmt::Debug;
4
5/// Top-level sizing model used by default element configs.
6#[derive(Debug, Copy, Clone)]
7#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8pub enum Sizing {
9 /// Width/height are configured independently.
10 DoubleAxis(DoubleAxisSizing),
11}
12
13/// Width/height sizing pair.
14#[derive(Debug, Copy, Clone)]
15#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
16pub struct DoubleAxisSizing {
17 /// Horizontal sizing behavior.
18 pub width: AxisSizing,
19 /// Vertical sizing behavior.
20 pub height: AxisSizing,
21}
22
23/// Sizing modes for one axis.
24#[derive(Copy, Clone, Debug)]
25#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
26pub enum AxisSizing {
27 /// Fits the element’s width/height within a min and max constraint.
28 Fit(f32, f32),
29 /// Expands the element to fill available space within min/max constraints.
30 Grow(f32, f32),
31 /// Sets a fixed width/height.
32 Fixed(f32),
33 /// Sets width/height as a percentage of its parent. Value should be between `0.0` and `Inf`.
34 Percent(f32),
35 /// Sets width/height as a percentage of its parent minus its padding. Value should be between `0.0` and `1.0`.
36 InnerPercent(f32),
37}