From f12a59fd31f582bbea88898a0fd7c5f50589604b Mon Sep 17 00:00:00 2001 From: griffi-gh Date: Tue, 20 Feb 2024 20:24:36 +0100 Subject: [PATCH] uwu --- .../examples/{align.rs => align_test.rs} | 1 + hui-winit/src/lib.rs | 4 ++-- hui/src/draw.rs | 2 +- hui/src/element/builtin/container.rs | 2 +- hui/src/element/builtin/progress_bar.rs | 21 +++++++++++++++---- 5 files changed, 22 insertions(+), 8 deletions(-) rename hui-examples/examples/{align.rs => align_test.rs} (95%) diff --git a/hui-examples/examples/align.rs b/hui-examples/examples/align_test.rs similarity index 95% rename from hui-examples/examples/align.rs rename to hui-examples/examples/align_test.rs index fdeced3..f52431d 100644 --- a/hui-examples/examples/align.rs +++ b/hui-examples/examples/align_test.rs @@ -66,6 +66,7 @@ fn main() { elements: vec![ Box::new(ProgressBar { value: z, + border_radius: Corners::all(0.25 * ProgressBar::DEFAULT_HEIGHT), ..Default::default() }), Box::new(Container { diff --git a/hui-winit/src/lib.rs b/hui-winit/src/lib.rs index 08a74ae..4ec6b8d 100644 --- a/hui-winit/src/lib.rs +++ b/hui-winit/src/lib.rs @@ -2,7 +2,7 @@ use glam::vec2; use hui::{event::UiEvent, UiInstance}; use winit::event::{Event, WindowEvent}; -//TODO: window id +//TODO: check window id pub fn handle_winit_event(ui: &mut UiInstance, event: &Event) { if let Event::WindowEvent { event, .. } = event { match event { @@ -24,7 +24,7 @@ pub fn handle_winit_event(ui: &mut UiInstance, event: &Event) { }, }) }, - //TODO keyboard + //TODO: translate keyboard input _ => (), } } diff --git a/hui/src/draw.rs b/hui/src/draw.rs index 7b00f93..51d82b4 100644 --- a/hui/src/draw.rs +++ b/hui/src/draw.rs @@ -185,7 +185,7 @@ impl UiDrawPlan { 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; for i in 0..rounded_corner_verts { let cratio = i as f32 / rounded_corner_verts as f32; diff --git a/hui/src/element/builtin/container.rs b/hui/src/element/builtin/container.rs index d9c0d2f..82348c4 100644 --- a/hui/src/element/builtin/container.rs +++ b/hui/src/element/builtin/container.rs @@ -21,7 +21,7 @@ pub struct Container { pub background: Vec4, pub borders: Sides>, pub corner_radius: Corners, - //pub clip: bool, //TODO clip children + //pub clip: bool, //TODO: clip children pub elements: Vec>, } diff --git a/hui/src/element/builtin/progress_bar.rs b/hui/src/element/builtin/progress_bar.rs index e0d3cc1..840138e 100644 --- a/hui/src/element/builtin/progress_bar.rs +++ b/hui/src/element/builtin/progress_bar.rs @@ -12,6 +12,10 @@ pub struct ProgressBar { pub border_radius: Corners, } +impl ProgressBar { + pub const DEFAULT_HEIGHT: f32 = 20.0; +} + impl Default for ProgressBar { fn default() -> Self { Self { @@ -24,8 +28,6 @@ impl Default for ProgressBar { } } -const BAR_HEIGHT: f32 = 20.0; - impl UiElement for ProgressBar { fn name(&self) -> &'static str { "Progress bar" } @@ -38,7 +40,7 @@ impl UiElement for ProgressBar { UiSize::Static(p) => p, }, match self.size.1 { - UiSize::Auto => BAR_HEIGHT, + UiSize::Auto => Self::DEFAULT_HEIGHT, UiSize::Fraction(p) => ctx.layout.max_size.y * p, UiSize::Static(p) => p, } @@ -52,7 +54,18 @@ impl UiElement for ProgressBar { let value = self.value.clamp(0., 1.); let rounded_corners = (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. { ctx.draw.add(UiDrawCommand::Rectangle {