mirror of
https://github.com/griffi-gh/hUI.git
synced 2024-12-22 12:28:19 -06:00
update stuff to new api, rename examples
This commit is contained in:
parent
d6ab6778e8
commit
f02a28ee31
|
@ -47,7 +47,7 @@ fn main() {
|
|||
hui.add(Container {
|
||||
gap: 5.,
|
||||
padding: Sides::all(5.),
|
||||
align: (Alignment::Begin, Alignment::Center),
|
||||
align: (Alignment::Begin, Alignment::Center).into(),
|
||||
size: (UiSize::Fraction(1.), UiSize::Fraction(1.)),
|
||||
elements: vec![
|
||||
Box::new(ProgressBar {
|
||||
|
@ -61,7 +61,7 @@ fn main() {
|
|||
hui.add(Container {
|
||||
gap: 5.,
|
||||
padding: Sides::all(5.),
|
||||
align: (Alignment::End, Alignment::Center),
|
||||
align: (Alignment::End, Alignment::Center).into(),
|
||||
size: (UiSize::Fraction(1.), UiSize::Fraction(1.)),
|
||||
elements: vec![
|
||||
Box::new(ProgressBar {
|
||||
|
@ -70,7 +70,7 @@ fn main() {
|
|||
}),
|
||||
Box::new(Container {
|
||||
size: (UiSize::Fraction(1.), UiSize::Auto),
|
||||
align: (Alignment::Center, Alignment::End),
|
||||
align: (Alignment::Center, Alignment::End).into(),
|
||||
padding: Sides::all(5.),
|
||||
gap: 10.,
|
||||
elements: vec![
|
||||
|
@ -131,7 +131,7 @@ fn main() {
|
|||
}),
|
||||
],
|
||||
..Default::default()
|
||||
})
|
||||
}),
|
||||
],
|
||||
..Default::default()
|
||||
}, resolution);
|
|
@ -48,13 +48,12 @@ fn main() {
|
|||
let mom_ratio = (instant.elapsed().as_secs_f32() / 60.).powf(0.5);
|
||||
|
||||
hui.add(Container {
|
||||
align: (Alignment::Center, Alignment::Center),
|
||||
align: Alignment::Center.into(),
|
||||
size: (UiSize::Fraction(1.), UiSize::Fraction(1.)),
|
||||
background: Some(vec4(0.1, 0.1, 0.1, 1.)),
|
||||
elements: vec![Box::new(Container {
|
||||
gap: 5.,
|
||||
padding: Sides::all(10.),
|
||||
align: (Alignment::Begin, Alignment::Begin),
|
||||
size: (UiSize::Static(450.), UiSize::Auto),
|
||||
background: Some(vec4(0.2, 0.2, 0.5, 1.)),
|
||||
corner_radius: Some(Corners::all(8.)),
|
||||
|
@ -72,7 +71,7 @@ fn main() {
|
|||
});
|
||||
el.add(Container {
|
||||
direction: UiDirection::Horizontal,
|
||||
align: (Alignment::End, Alignment::Center),
|
||||
align: (Alignment::End, Alignment::Center).into(),
|
||||
size: (UiSize::Fraction(1.), UiSize::Auto),
|
||||
elements: vec![Box::new(Text {
|
||||
text: format!("{:.2}% ({:.1} GB)", mom_ratio * 100., mom_ratio * 10000.).into(),
|
||||
|
|
|
@ -38,10 +38,10 @@ fn main() {
|
|||
hui.begin();
|
||||
|
||||
hui.add(Container {
|
||||
align: (Alignment::Center, Alignment::Center),
|
||||
align: Alignment::Center.into(),
|
||||
size: (UiSize::Fraction(1.), UiSize::Fraction(1.)),
|
||||
elements: vec![Box::new(Container {
|
||||
align: (Alignment::Center, Alignment::Center),
|
||||
align: Alignment::Center.into(),
|
||||
size: (UiSize::Fraction(0.5), UiSize::Fraction(0.5)),
|
||||
background: Some(vec4(1., 0., 0., 1.)),
|
||||
corner_radius: Some(Corners {
|
||||
|
@ -54,7 +54,7 @@ fn main() {
|
|||
Box::new(Container {
|
||||
padding: Sides::all(20.),
|
||||
direction: UiDirection::Horizontal,
|
||||
align: (Alignment::Center, Alignment::Center),
|
||||
align: Alignment::Center.into(),
|
||||
size: (UiSize::Auto, UiSize::Auto),
|
||||
background: Some(vec4(0.1, 0.1, 0.1, 0.5)),
|
||||
corner_radius: Some(Corners::all(8.)),
|
|
@ -40,7 +40,7 @@ fn main() {
|
|||
hui.add(Container {
|
||||
gap: 5.,
|
||||
padding: Sides::all(5.),
|
||||
align: (Alignment::Center, Alignment::Center),
|
||||
align: Alignment::Center.into(),
|
||||
size: (UiSize::Fraction(1.), UiSize::Fraction(1.)),
|
||||
elements: vec![
|
||||
Box::new(Text {
|
|
@ -137,8 +137,15 @@ impl UiElement for Container {
|
|||
//padding
|
||||
position += vec2(self.padding.left, self.padding.top);
|
||||
|
||||
//convert alignment to pri/sec axis based
|
||||
//.0 = primary, .1 = secondary
|
||||
let pri_sec_align = match self.direction {
|
||||
UiDirection::Horizontal => (self.align.horizontal, self.align.vertical),
|
||||
UiDirection::Vertical => (self.align.horizontal, self.align.vertical),
|
||||
};
|
||||
|
||||
//alignment
|
||||
match (self.align.0, self.direction) {
|
||||
match (pri_sec_align.0, self.direction) {
|
||||
(Alignment::Begin, _) => (),
|
||||
(Alignment::Center, UiDirection::Horizontal) => {
|
||||
position.x += (ctx.measure.size.x - ctx.measure.hints.inner_content_size.unwrap().x) / 2. - self.padding.left;
|
||||
|
@ -171,7 +178,7 @@ impl UiElement for Container {
|
|||
});
|
||||
|
||||
//align (on sec. axis)
|
||||
match (self.align.1, self.direction) {
|
||||
match (pri_sec_align.1, self.direction) {
|
||||
(Alignment::Begin, _) => (),
|
||||
(Alignment::Center, UiDirection::Horizontal) => {
|
||||
el_layout.position.y += (ctx.measure.size.y - self.padding.bottom - self.padding.top - el_measure.size.y) / 2.;
|
||||
|
|
|
@ -9,8 +9,10 @@ pub enum Alignment {
|
|||
/// (left for horizontal, top for vertical alignment)
|
||||
#[default]
|
||||
Begin = 0,
|
||||
/// Put the element in the center of the axis
|
||||
|
||||
/// Put the element in the center
|
||||
Center = 1,
|
||||
|
||||
/// Put the element at the end of the axis\
|
||||
/// (right for horizontal, bottom for vertical alignment)
|
||||
End = 2,
|
||||
|
@ -43,24 +45,34 @@ pub struct Alignment2d {
|
|||
pub vertical: Alignment,
|
||||
}
|
||||
|
||||
impl Alignment2d {
|
||||
#[inline]
|
||||
pub const fn all(alignment: Alignment) -> Self {
|
||||
Self {
|
||||
horizontal: alignment,
|
||||
vertical: alignment,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<(Alignment, Alignment)> for Alignment2d {
|
||||
#[inline]
|
||||
fn from((horizontal, vertical): (Alignment, Alignment)) -> Self {
|
||||
Self { horizontal, vertical }
|
||||
}
|
||||
}
|
||||
|
||||
impl From<[Alignment; 2]> for Alignment2d {
|
||||
#[inline]
|
||||
fn from([horizontal, vertical]: [Alignment; 2]) -> Self {
|
||||
Self { horizontal, vertical }
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Alignment> for Alignment2d {
|
||||
#[inline]
|
||||
fn from(alignment: Alignment) -> Self {
|
||||
Self {
|
||||
horizontal: alignment,
|
||||
vertical: alignment,
|
||||
}
|
||||
Self::all(alignment)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue