mirror of
https://github.com/griffi-gh/hUI.git
synced 2024-11-22 07:08: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 glam::{Vec2, vec2, Vec4};
|
||||||
use crate::{
|
use crate::{
|
||||||
layout::{Alignment, LayoutInfo, UiDirection, UiSize},
|
draw::{RoundedCorners, UiDrawCommand}, element::{MeasureContext, ProcessContext, UiElement}, layout::{Alignment, Alignment2d, LayoutInfo, UiDirection, UiSize}, measure::{Hints, Response}, rectangle::{Corners, Sides}
|
||||||
rectangle::{Corners, Sides},
|
|
||||||
draw::{RoundedCorners, UiDrawCommand},
|
|
||||||
element::{MeasureContext, ProcessContext, UiElement},
|
|
||||||
measure::{Hints, Response},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
pub struct Border {
|
pub struct Border {
|
||||||
|
@ -21,12 +17,12 @@ pub struct Container {
|
||||||
pub gap: f32,
|
pub gap: f32,
|
||||||
pub padding: Sides<f32>,
|
pub padding: Sides<f32>,
|
||||||
///Primary/secondary axis
|
///Primary/secondary axis
|
||||||
pub align: (Alignment, Alignment),
|
pub align: Alignment2d,
|
||||||
pub background: Option<Vec4>,
|
pub background: Option<Vec4>,
|
||||||
pub borders: Sides<Option<Border>>,
|
pub borders: Sides<Option<Border>>,
|
||||||
|
pub corner_radius: Option<Corners<f32>>,
|
||||||
//pub clip: bool, //TODO clip children
|
//pub clip: bool, //TODO clip children
|
||||||
pub elements: Vec<Box<dyn UiElement>>,
|
pub elements: Vec<Box<dyn UiElement>>,
|
||||||
pub corner_radius: Option<Corners<f32>>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Container {
|
impl Default for Container {
|
||||||
|
@ -39,7 +35,7 @@ impl Default for Container {
|
||||||
//reverse: false,
|
//reverse: false,
|
||||||
gap: 0.,
|
gap: 0.,
|
||||||
padding: Sides::all(0.),
|
padding: Sides::all(0.),
|
||||||
align: (Alignment::Begin, Alignment::Begin),
|
align: Alignment2d::default(),
|
||||||
background: Default::default(),
|
background: Default::default(),
|
||||||
borders: Default::default(),
|
borders: Default::default(),
|
||||||
elements: Vec::new(),
|
elements: Vec::new(),
|
||||||
|
|
|
@ -2,14 +2,68 @@
|
||||||
|
|
||||||
use glam::Vec2;
|
use glam::Vec2;
|
||||||
|
|
||||||
|
/// Alignment along a single axis
|
||||||
#[derive(Clone, Copy, PartialEq, Eq, Debug, Default, PartialOrd, Ord)]
|
#[derive(Clone, Copy, PartialEq, Eq, Debug, Default, PartialOrd, Ord)]
|
||||||
pub enum Alignment {
|
pub enum Alignment {
|
||||||
|
/// Put the element at the beginning of the axis\
|
||||||
|
/// (left for horizontal, top for vertical alignment)
|
||||||
#[default]
|
#[default]
|
||||||
Begin = 0,
|
Begin = 0,
|
||||||
|
/// Put the element in the center of the axis
|
||||||
Center = 1,
|
Center = 1,
|
||||||
|
/// Put the element at the end of the axis\
|
||||||
|
/// (right for horizontal, bottom for vertical alignment)
|
||||||
End = 2,
|
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)]
|
#[derive(Default, Debug, Clone, Copy)]
|
||||||
pub enum UiSize {
|
pub enum UiSize {
|
||||||
#[default]
|
#[default]
|
||||||
|
|
Loading…
Reference in a new issue