mirror of
https://github.com/griffi-gh/hUI.git
synced 2024-11-21 14:48:42 -06:00
add Alignment2d
, better docs
This commit is contained in:
parent
9ff9b8356d
commit
d6ab6778e8
|
@ -1,10 +1,6 @@
|
|||
use glam::{Vec2, vec2, Vec4};
|
||||
use crate::{
|
||||
layout::{Alignment, LayoutInfo, UiDirection, UiSize},
|
||||
rectangle::{Corners, Sides},
|
||||
draw::{RoundedCorners, UiDrawCommand},
|
||||
element::{MeasureContext, ProcessContext, UiElement},
|
||||
measure::{Hints, Response},
|
||||
draw::{RoundedCorners, UiDrawCommand}, element::{MeasureContext, ProcessContext, UiElement}, layout::{Alignment, Alignment2d, LayoutInfo, UiDirection, UiSize}, measure::{Hints, Response}, rectangle::{Corners, Sides}
|
||||
};
|
||||
|
||||
pub struct Border {
|
||||
|
@ -21,12 +17,12 @@ pub struct Container {
|
|||
pub gap: f32,
|
||||
pub padding: Sides<f32>,
|
||||
///Primary/secondary axis
|
||||
pub align: (Alignment, Alignment),
|
||||
pub align: Alignment2d,
|
||||
pub background: Option<Vec4>,
|
||||
pub borders: Sides<Option<Border>>,
|
||||
pub corner_radius: Option<Corners<f32>>,
|
||||
//pub clip: bool, //TODO clip children
|
||||
pub elements: Vec<Box<dyn UiElement>>,
|
||||
pub corner_radius: Option<Corners<f32>>,
|
||||
}
|
||||
|
||||
impl Default for Container {
|
||||
|
@ -39,7 +35,7 @@ impl Default for Container {
|
|||
//reverse: false,
|
||||
gap: 0.,
|
||||
padding: Sides::all(0.),
|
||||
align: (Alignment::Begin, Alignment::Begin),
|
||||
align: Alignment2d::default(),
|
||||
background: Default::default(),
|
||||
borders: Default::default(),
|
||||
elements: Vec::new(),
|
||||
|
|
|
@ -2,14 +2,68 @@
|
|||
|
||||
use glam::Vec2;
|
||||
|
||||
/// Alignment along a single axis
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Debug, Default, PartialOrd, Ord)]
|
||||
pub enum Alignment {
|
||||
/// Put the element at the beginning of the axis\
|
||||
/// (left for horizontal, top for vertical alignment)
|
||||
#[default]
|
||||
Begin = 0,
|
||||
/// Put the element in the center of the axis
|
||||
Center = 1,
|
||||
/// Put the element at the end of the axis\
|
||||
/// (right for horizontal, bottom for vertical alignment)
|
||||
End = 2,
|
||||
}
|
||||
|
||||
/// Represents alignment in 2D space
|
||||
///
|
||||
/// - `horizontal` - alignment *along* x-axis (horizontal)\
|
||||
/// - `vertical` - alignment *along* y-axis (vertical)
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Debug, Default, PartialOrd, Ord)]
|
||||
pub struct Alignment2d {
|
||||
/// Alignment *along* horizontal axis (X)
|
||||
///
|
||||
/// ```text
|
||||
/// ├───────[ ]──────┤
|
||||
/// ↑↑ ↑↑ ↑↑
|
||||
/// Begin Center End
|
||||
/// ```
|
||||
pub horizontal: Alignment,
|
||||
|
||||
/// Alignment *along* vertical axis (Y)
|
||||
///
|
||||
/// ```text
|
||||
/// ┬ ←─ Begin
|
||||
/// │
|
||||
/// [ ] ←─ Center
|
||||
/// │
|
||||
/// ┴ ←─ End
|
||||
/// ```
|
||||
pub vertical: Alignment,
|
||||
}
|
||||
|
||||
impl From<(Alignment, Alignment)> for Alignment2d {
|
||||
fn from((horizontal, vertical): (Alignment, Alignment)) -> Self {
|
||||
Self { horizontal, vertical }
|
||||
}
|
||||
}
|
||||
|
||||
impl From<[Alignment; 2]> for Alignment2d {
|
||||
fn from([horizontal, vertical]: [Alignment; 2]) -> Self {
|
||||
Self { horizontal, vertical }
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Alignment> for Alignment2d {
|
||||
fn from(alignment: Alignment) -> Self {
|
||||
Self {
|
||||
horizontal: alignment,
|
||||
vertical: alignment,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, Clone, Copy)]
|
||||
pub enum UiSize {
|
||||
#[default]
|
||||
|
|
Loading…
Reference in a new issue