mirror of
https://github.com/griffi-gh/hUI.git
synced 2024-11-21 14:48:42 -06:00
uwu
This commit is contained in:
parent
92b7f6890f
commit
65bd1c1b38
|
@ -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 {
|
|
@ -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<T>(ui: &mut UiInstance, event: &Event<T>) {
|
||||
if let Event::WindowEvent { event, .. } = 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.),
|
||||
});
|
||||
|
||||
//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;
|
||||
|
|
|
@ -21,7 +21,7 @@ pub struct Container {
|
|||
pub background: Vec4,
|
||||
pub borders: Sides<Option<Border>>,
|
||||
pub corner_radius: Corners<f32>,
|
||||
//pub clip: bool, //TODO clip children
|
||||
//pub clip: bool, //TODO: clip children
|
||||
pub elements: Vec<Box<dyn UiElement>>,
|
||||
}
|
||||
|
||||
|
|
|
@ -12,6 +12,10 @@ pub struct ProgressBar {
|
|||
pub border_radius: Corners<f32>,
|
||||
}
|
||||
|
||||
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 {
|
||||
|
|
Loading…
Reference in a new issue