mirror of
https://github.com/griffi-gh/hUI.git
synced 2024-11-25 08:28:42 -06:00
uwu
This commit is contained in:
parent
2fdc075f3a
commit
f12a59fd31
|
@ -66,6 +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),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}),
|
}),
|
||||||
Box::new(Container {
|
Box::new(Container {
|
|
@ -2,7 +2,7 @@ use glam::vec2;
|
||||||
use hui::{event::UiEvent, UiInstance};
|
use hui::{event::UiEvent, UiInstance};
|
||||||
use winit::event::{Event, WindowEvent};
|
use winit::event::{Event, WindowEvent};
|
||||||
|
|
||||||
//TODO: window id
|
//TODO: check window id
|
||||||
pub fn handle_winit_event<T>(ui: &mut UiInstance, event: &Event<T>) {
|
pub fn handle_winit_event<T>(ui: &mut UiInstance, event: &Event<T>) {
|
||||||
if let Event::WindowEvent { event, .. } = event {
|
if let Event::WindowEvent { event, .. } = event {
|
||||||
match event {
|
match event {
|
||||||
|
@ -24,7 +24,7 @@ pub fn handle_winit_event<T>(ui: &mut UiInstance, event: &Event<T>) {
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
//TODO keyboard
|
//TODO: translate keyboard input
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -185,7 +185,7 @@ impl UiDrawPlan {
|
||||||
uv: vec2(0., 0.),
|
uv: vec2(0., 0.),
|
||||||
});
|
});
|
||||||
|
|
||||||
//TODO: fix some corners tris being invisible (close enough lol)
|
//TODO: fix some corners tris being invisible (but it's already close enough lol)
|
||||||
let rounded_corner_verts = corner.point_count.get() as u32;
|
let rounded_corner_verts = corner.point_count.get() as u32;
|
||||||
for i in 0..rounded_corner_verts {
|
for i in 0..rounded_corner_verts {
|
||||||
let cratio = i as f32 / rounded_corner_verts as f32;
|
let cratio = i as f32 / rounded_corner_verts as f32;
|
||||||
|
|
|
@ -21,7 +21,7 @@ pub struct Container {
|
||||||
pub background: Vec4,
|
pub background: Vec4,
|
||||||
pub borders: Sides<Option<Border>>,
|
pub borders: Sides<Option<Border>>,
|
||||||
pub corner_radius: Corners<f32>,
|
pub corner_radius: 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>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,10 @@ pub struct ProgressBar {
|
||||||
pub border_radius: Corners<f32>,
|
pub border_radius: Corners<f32>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl ProgressBar {
|
||||||
|
pub const DEFAULT_HEIGHT: f32 = 20.0;
|
||||||
|
}
|
||||||
|
|
||||||
impl Default for ProgressBar {
|
impl Default for ProgressBar {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
@ -24,8 +28,6 @@ impl Default for ProgressBar {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const BAR_HEIGHT: f32 = 20.0;
|
|
||||||
|
|
||||||
impl UiElement for ProgressBar {
|
impl UiElement for ProgressBar {
|
||||||
fn name(&self) -> &'static str { "Progress bar" }
|
fn name(&self) -> &'static str { "Progress bar" }
|
||||||
|
|
||||||
|
@ -38,7 +40,7 @@ impl UiElement for ProgressBar {
|
||||||
UiSize::Static(p) => p,
|
UiSize::Static(p) => p,
|
||||||
},
|
},
|
||||||
match self.size.1 {
|
match self.size.1 {
|
||||||
UiSize::Auto => BAR_HEIGHT,
|
UiSize::Auto => Self::DEFAULT_HEIGHT,
|
||||||
UiSize::Fraction(p) => ctx.layout.max_size.y * p,
|
UiSize::Fraction(p) => ctx.layout.max_size.y * p,
|
||||||
UiSize::Static(p) => p,
|
UiSize::Static(p) => p,
|
||||||
}
|
}
|
||||||
|
@ -52,7 +54,18 @@ impl UiElement for ProgressBar {
|
||||||
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.border_radius.max_f32() > 0.).then_some({
|
||||||
RoundedCorners::from_radius(self.border_radius)
|
//HACK: fix clipping issues; //todo: get rid of this
|
||||||
|
let mut radii = self.border_radius;
|
||||||
|
let width = ctx.measure.size.x * value;
|
||||||
|
if width <= radii.max_f32() * 2. {
|
||||||
|
radii.bottom_right = 0.;
|
||||||
|
radii.top_right = 0.;
|
||||||
|
}
|
||||||
|
if width <= radii.max_f32() {
|
||||||
|
radii.bottom_left = 0.;
|
||||||
|
radii.top_left = 0.;
|
||||||
|
}
|
||||||
|
RoundedCorners::from_radius(radii)
|
||||||
});
|
});
|
||||||
if value < 1. {
|
if value < 1. {
|
||||||
ctx.draw.add(UiDrawCommand::Rectangle {
|
ctx.draw.add(UiDrawCommand::Rectangle {
|
||||||
|
|
Loading…
Reference in a new issue