Skip to main content

mgui_core/layout/
alignment.rs

1//! 公共对齐类型 — Alignment
2
3/// 对齐枚举(Flutter 范式,值在每个轴 0.0..1.0)
4///
5/// `x=0.0` 左边缘,`x=0.5` 水平中心,`x=1.0` 右边缘。
6/// `y=0.0` 顶部,`y=0.5` 垂直中心,`y=1.0` 底部。
7#[derive(Debug, Clone, Copy, PartialEq)]
8pub struct Alignment {
9    pub x: f32,
10    pub y: f32,
11}
12
13impl Alignment {
14    pub const TOP_LEFT: Self = Self { x: 0.0, y: 0.0 };
15    pub const TOP_CENTER: Self = Self { x: 0.5, y: 0.0 };
16    pub const TOP_RIGHT: Self = Self { x: 1.0, y: 0.0 };
17    pub const CENTER_LEFT: Self = Self { x: 0.0, y: 0.5 };
18    pub const CENTER: Self = Self { x: 0.5, y: 0.5 };
19    pub const CENTER_RIGHT: Self = Self { x: 1.0, y: 0.5 };
20    pub const BOTTOM_LEFT: Self = Self { x: 0.0, y: 1.0 };
21    pub const BOTTOM_CENTER: Self = Self { x: 0.5, y: 1.0 };
22    pub const BOTTOM_RIGHT: Self = Self { x: 1.0, y: 1.0 };
23}