#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Direction {
Inherit,
Ltr,
Rtl,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum FlexDirection {
Row,
RowReverse,
Column,
ColumnReverse,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum FlexWrap {
NoWrap,
Wrap,
WrapReverse,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum FlexAlign {
Auto,
Start,
Center,
End,
Stretch,
Baseline,
SpaceBetween,
SpaceAround,
SpaceEvenly,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum CSSDirection {
Left = 0,
Top = 1,
Right = 2,
Bottom = 3,
Start = 4,
End = 5,
Horizontal = 6,
Vertical = 7,
All = 8,
None = 9,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Dimension {
Width = 0,
Height = 1,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum PositionType {
Relative,
Absolute,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum DisplayType {
Flex,
None,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum NodeType {
Default,
Text,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum MeasureMode {
Undefined,
Exactly,
AtMost,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum LayoutAction {
MeasureWidth = 1,
MeasureHeight = 2,
Layout = 3,
}
#[derive(Debug, Clone, Copy)]
pub struct TaitankSize {
pub width: f32,
pub height: f32,
}
#[derive(Debug, Clone, Copy)]
pub struct SizeMode {
pub width_measure_mode: MeasureMode,
pub height_measure_mode: MeasureMode,
}
#[derive(Debug, Clone)]
pub struct LayoutResult {
pub position: [f32; 4],
pub cached_position: [f32; 4],
pub dim: [f32; 2],
pub margin: [f32; 4],
pub padding: [f32; 4],
pub border: [f32; 4],
pub had_overflow: bool,
pub direction: Direction,
pub flex_base_size: f32,
pub hypothetical_main_axis_margin_boxsize: f32,
pub hypothetical_main_axis_size: f32,
}
impl Default for LayoutResult {
fn default() -> Self {
Self {
position: [0.0; 4],
cached_position: [0.0; 4],
dim: [0.0; 2],
margin: [0.0; 4],
padding: [0.0; 4],
border: [0.0; 4],
had_overflow: false,
direction: Direction::Inherit,
flex_base_size: 0.0,
hypothetical_main_axis_margin_boxsize: 0.0,
hypothetical_main_axis_size: 0.0,
}
}
}
pub const K_AXIS_START: [CSSDirection; 4] = [
CSSDirection::Left,
CSSDirection::Right,
CSSDirection::Top,
CSSDirection::Bottom,
];
pub const K_AXIS_END: [CSSDirection; 4] = [
CSSDirection::Right,
CSSDirection::Left,
CSSDirection::Bottom,
CSSDirection::Top,
];
pub const K_AXIS_DIM: [Dimension; 4] = [
Dimension::Width,
Dimension::Width,
Dimension::Height,
Dimension::Height,
];
pub fn is_row_direction(dir: FlexDirection) -> bool {
matches!(dir, FlexDirection::Row | FlexDirection::RowReverse)
}
pub fn is_column_direction(dir: FlexDirection) -> bool {
matches!(dir, FlexDirection::Column | FlexDirection::ColumnReverse)
}
pub fn is_reverse_direction(dir: FlexDirection) -> bool {
matches!(
dir,
FlexDirection::RowReverse | FlexDirection::ColumnReverse
)
}
pub const VALUE_UNDEFINED: f32 = f32::NAN;
pub const VALUE_AUTO: f32 = f32::NAN;
pub fn is_defined(v: f32) -> bool {
!v.is_nan()
}
pub fn is_undefined(v: f32) -> bool {
v.is_nan()
}
pub fn nan_as_inf(n: f32) -> f32 {
if n.is_nan() { f32::INFINITY } else { n }
}
pub fn float_is_equal(a: f32, b: f32) -> bool {
if is_undefined(a) {
return is_undefined(b);
}
if is_undefined(b) {
return is_undefined(a);
}
(a - b).abs() < 0.0001
}