mirror of
https://github.com/griffi-gh/hUI.git
synced 2024-11-21 22:58:42 -06:00
rename border_radius
to corner_radius
add it to mom downloader example
This commit is contained in:
parent
ff448ed393
commit
73fde36c8a
|
@ -66,7 +66,7 @@ fn main() {
|
||||||
elements: vec![
|
elements: vec![
|
||||||
Box::new(ProgressBar {
|
Box::new(ProgressBar {
|
||||||
value: z,
|
value: z,
|
||||||
border_radius: Corners::all(0.25 * ProgressBar::DEFAULT_HEIGHT),
|
corner_radius: Corners::all(0.25 * ProgressBar::DEFAULT_HEIGHT),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}),
|
}),
|
||||||
Box::new(Container {
|
Box::new(Container {
|
||||||
|
@ -81,7 +81,10 @@ fn main() {
|
||||||
}),
|
}),
|
||||||
Box::new(Rect {
|
Box::new(Rect {
|
||||||
size: (UiSize::Fraction(z / 2. + 0.5), UiSize::Static(30.)),
|
size: (UiSize::Fraction(z / 2. + 0.5), UiSize::Static(30.)),
|
||||||
color: vec4(0., 0.75, 0., 1.).into()
|
color: Corners::left_right(
|
||||||
|
vec4(1., 0., 0., 1.),
|
||||||
|
vec4(0., 1., 0., 1.)
|
||||||
|
).into()
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
..Default::default()
|
..Default::default()
|
||||||
|
|
|
@ -67,6 +67,7 @@ fn main() {
|
||||||
});
|
});
|
||||||
el.add(ProgressBar {
|
el.add(ProgressBar {
|
||||||
value: mom_ratio,
|
value: mom_ratio,
|
||||||
|
corner_radius: Corners::all(0.125 * ProgressBar::DEFAULT_HEIGHT),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
});
|
});
|
||||||
el.add(Container {
|
el.add(Container {
|
||||||
|
|
|
@ -38,45 +38,91 @@ fn main() {
|
||||||
hui.begin();
|
hui.begin();
|
||||||
|
|
||||||
hui.add(Container {
|
hui.add(Container {
|
||||||
|
gap: 10.,
|
||||||
align: Alignment::Center.into(),
|
align: Alignment::Center.into(),
|
||||||
size: (UiSize::Fraction(1.), UiSize::Fraction(1.)),
|
size: (UiSize::Fraction(1.), UiSize::Fraction(1.)),
|
||||||
elements: vec![Box::new(Container {
|
elements: vec![
|
||||||
align: Alignment::Center.into(),
|
Box::new(Container {
|
||||||
size: (UiSize::Fraction(0.5), UiSize::Fraction(0.5)),
|
align: Alignment::Center.into(),
|
||||||
background: vec4(1., 0., 0., 1.).into(),
|
size: (UiSize::Fraction(0.5), UiSize::Fraction(0.5)),
|
||||||
corner_radius: Corners {
|
background: vec4(1., 0., 0., 1.).into(),
|
||||||
top_left: 10.,
|
corner_radius: Corners {
|
||||||
top_right: 20.,
|
top_left: 10.,
|
||||||
bottom_left: 50.,
|
top_right: 20.,
|
||||||
bottom_right: 80.
|
bottom_left: 50.,
|
||||||
},
|
bottom_right: 80.
|
||||||
elements: vec![
|
},
|
||||||
Box::new(Container {
|
elements: vec![
|
||||||
padding: Sides::all(20.),
|
Box::new(Container {
|
||||||
direction: UiDirection::Horizontal,
|
padding: Sides::all(20.),
|
||||||
align: Alignment::Center.into(),
|
direction: UiDirection::Horizontal,
|
||||||
size: (UiSize::Auto, UiSize::Auto),
|
align: Alignment::Center.into(),
|
||||||
background: vec4(0.1, 0.1, 0.1, 0.5).into(),
|
size: (UiSize::Auto, UiSize::Auto),
|
||||||
corner_radius: Corners::all(8.),
|
background: vec4(0.1, 0.1, 0.1, 0.5).into(),
|
||||||
elements: vec![
|
corner_radius: Corners::all(8.),
|
||||||
Box::new(Text {
|
elements: vec![
|
||||||
text: "Corners".into(),
|
Box::new(Text {
|
||||||
text_size: 50,
|
text: "Corners".into(),
|
||||||
color: vec4(1., 1., 1., 1.),
|
text_size: 50,
|
||||||
..Default::default()
|
color: vec4(1., 1., 1., 1.),
|
||||||
}),
|
..Default::default()
|
||||||
Box::new(Text {
|
}),
|
||||||
text: "!".into(),
|
Box::new(Text {
|
||||||
text_size: 50,
|
text: "!".into(),
|
||||||
color: vec4(1., 1., 0., 1.),
|
text_size: 50,
|
||||||
..Default::default()
|
color: vec4(1., 1., 0., 1.),
|
||||||
}),
|
..Default::default()
|
||||||
],
|
}),
|
||||||
..Default::default()
|
],
|
||||||
}),
|
..Default::default()
|
||||||
],
|
}),
|
||||||
..Default::default()
|
],
|
||||||
})],
|
..Default::default()
|
||||||
|
}),
|
||||||
|
Box::new(Container {
|
||||||
|
gap: 10.,
|
||||||
|
direction: UiDirection::Horizontal,
|
||||||
|
elements: vec![
|
||||||
|
Box::new(Container {
|
||||||
|
size: (UiSize::Static(100.), UiSize::Static(100.)),
|
||||||
|
background: Corners::left_right(
|
||||||
|
vec4(1., 0., 0., 1.),
|
||||||
|
vec4(0., 1., 0., 1.)
|
||||||
|
).into(),
|
||||||
|
corner_radius: Corners::all(0.),
|
||||||
|
..Default::default()
|
||||||
|
}),
|
||||||
|
Box::new(Container {
|
||||||
|
size: (UiSize::Static(100.), UiSize::Static(100.)),
|
||||||
|
background: Corners::left_right(
|
||||||
|
vec4(1., 0., 0., 1.),
|
||||||
|
vec4(0., 1., 0., 1.)
|
||||||
|
).into(),
|
||||||
|
corner_radius: Corners::all(10.),
|
||||||
|
..Default::default()
|
||||||
|
}),
|
||||||
|
Box::new(Container {
|
||||||
|
size: (UiSize::Static(100.), UiSize::Static(100.)),
|
||||||
|
background: Corners::left_right(
|
||||||
|
vec4(1., 0., 0., 1.),
|
||||||
|
vec4(0., 1., 0., 1.)
|
||||||
|
).into(),
|
||||||
|
corner_radius: Corners::all(20.),
|
||||||
|
..Default::default()
|
||||||
|
}),
|
||||||
|
Box::new(Container {
|
||||||
|
size: (UiSize::Static(100.), UiSize::Static(100.)),
|
||||||
|
background: Corners::left_right(
|
||||||
|
vec4(1., 0., 0., 1.),
|
||||||
|
vec4(0., 1., 0., 1.)
|
||||||
|
).into(),
|
||||||
|
corner_radius: Corners::all(30.),
|
||||||
|
..Default::default()
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
..Default::default()
|
||||||
|
}),
|
||||||
|
],
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}, resolution);
|
}, resolution);
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use glam::Vec4;
|
use glam::{vec4, Vec3, Vec4};
|
||||||
use crate::rectangle::Corners;
|
use crate::rectangle::Corners;
|
||||||
|
|
||||||
// #[derive(Clone, Copy, PartialEq, Eq, Debug)]
|
// #[derive(Clone, Copy, PartialEq, Eq, Debug)]
|
||||||
|
@ -17,9 +17,15 @@ pub enum Background {
|
||||||
Gradient(Corners<Vec4>),
|
Gradient(Corners<Vec4>),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<Vec4> for Background {
|
impl From<(f32, f32, f32, f32)> for Background {
|
||||||
fn from(color: Vec4) -> Self {
|
fn from(color: (f32, f32, f32, f32)) -> Self {
|
||||||
Self::Solid(color)
|
Self::Solid(vec4(color.0, color.1, color.2, color.3))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<Corners<Vec4>> for Background {
|
||||||
|
fn from(corners: Corners<Vec4>) -> Self {
|
||||||
|
Self::Gradient(corners)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,6 +38,44 @@ impl From<Option<Vec4>> for Background {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<Vec4> for Background {
|
||||||
|
fn from(color: Vec4) -> Self {
|
||||||
|
Self::Solid(color)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<(f32, f32, f32)> for Background {
|
||||||
|
fn from(color: (f32, f32, f32)) -> Self {
|
||||||
|
Self::Solid(vec4(color.0, color.1, color.2, 1.))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<Corners<Vec3>> for Background {
|
||||||
|
fn from(corners: Corners<Vec3>) -> Self {
|
||||||
|
Self::Gradient(Corners {
|
||||||
|
top_left: corners.top_left.extend(1.),
|
||||||
|
top_right: corners.top_right.extend(1.),
|
||||||
|
bottom_left: corners.bottom_left.extend(1.),
|
||||||
|
bottom_right: corners.bottom_right.extend(1.),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<Option<Vec3>> for Background {
|
||||||
|
fn from(color: Option<Vec3>) -> Self {
|
||||||
|
match color {
|
||||||
|
Some(color) => Self::Solid(color.extend(1.)),
|
||||||
|
None => Self::Transparent,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<Vec3> for Background {
|
||||||
|
fn from(color: Vec3) -> Self {
|
||||||
|
Self::Solid(color.extend(1.))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Background {
|
impl Background {
|
||||||
/// Currently, never returns None.\
|
/// Currently, never returns None.\
|
||||||
/// `Option` has been added in preparation for future changes.\
|
/// `Option` has been added in preparation for future changes.\
|
||||||
|
|
|
@ -9,7 +9,7 @@ pub struct ProgressBar {
|
||||||
pub value: f32,
|
pub value: f32,
|
||||||
pub color_foreground: Vec4,
|
pub color_foreground: Vec4,
|
||||||
pub color_background: Vec4,
|
pub color_background: Vec4,
|
||||||
pub border_radius: Corners<f32>,
|
pub corner_radius: Corners<f32>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ProgressBar {
|
impl ProgressBar {
|
||||||
|
@ -23,7 +23,7 @@ impl Default for ProgressBar {
|
||||||
value: 0.,
|
value: 0.,
|
||||||
color_foreground: vec4(0.0, 0.0, 1.0, 1.0),
|
color_foreground: vec4(0.0, 0.0, 1.0, 1.0),
|
||||||
color_background: vec4(0.0, 0.0, 0.0, 1.0),
|
color_background: vec4(0.0, 0.0, 0.0, 1.0),
|
||||||
border_radius: Corners::all(0.),
|
corner_radius: Corners::all(0.),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -53,9 +53,9 @@ impl UiElement for ProgressBar {
|
||||||
fn process(&self, ctx: ProcessContext) {
|
fn process(&self, ctx: ProcessContext) {
|
||||||
let value = self.value.clamp(0., 1.);
|
let value = self.value.clamp(0., 1.);
|
||||||
let rounded_corners =
|
let rounded_corners =
|
||||||
(self.border_radius.max_f32() > 0.).then_some({
|
(self.corner_radius.max_f32() > 0.).then_some({
|
||||||
//HACK: fix clipping issues; //todo: get rid of this
|
//HACK: fix clipping issues; //todo: get rid of this
|
||||||
let mut radii = self.border_radius;
|
let mut radii = self.corner_radius;
|
||||||
let width = ctx.measure.size.x * value;
|
let width = ctx.measure.size.x * value;
|
||||||
if width <= radii.max_f32() * 2. {
|
if width <= radii.max_f32() * 2. {
|
||||||
radii.bottom_right = 0.;
|
radii.bottom_right = 0.;
|
||||||
|
|
Loading…
Reference in a new issue