diff --git a/hui/src/draw.rs b/hui/src/draw.rs index c80243c..67a12f4 100644 --- a/hui/src/draw.rs +++ b/hui/src/draw.rs @@ -14,6 +14,9 @@ pub enum UiDrawCommand { size: Vec2, ///Color (RGBA) color: Vec4, + //TODO: rounded corners per side + ///Rounded corners + corner_radius: Option, }, Text { ///Position in pixels @@ -129,31 +132,38 @@ impl UiDrawPlan { } match command { - UiDrawCommand::Rectangle { position, size, color } => { + UiDrawCommand::Rectangle { position, size, color, corner_radius } => { + let corner_radius = corner_radius.unwrap_or(0.0); let vidx = swapper.current().vertices.len() as u32; - swapper.current_mut().indices.extend([vidx, vidx + 1, vidx + 2, vidx, vidx + 2, vidx + 3]); - swapper.current_mut().vertices.extend([ - UiVertex { - position: *position, - color: *color, - uv: vec2(0.0, 0.0), - }, - UiVertex { - position: *position + vec2(size.x, 0.0), - color: *color, - uv: vec2(1.0, 0.0), - }, - UiVertex { - position: *position + *size, - color: *color, - uv: vec2(1.0, 1.0), - }, - UiVertex { - position: *position + vec2(0.0, size.y), - color: *color, - uv: vec2(0.0, 1.0), - }, - ]); + if corner_radius > 0.0 { + todo!("rounded corners are not implemented"); + //TODO vtx-based rounded corners + //swapper.current_mut().indices.extend(); + } else { + swapper.current_mut().indices.extend([vidx, vidx + 1, vidx + 2, vidx, vidx + 2, vidx + 3]); + swapper.current_mut().vertices.extend([ + UiVertex { + position: *position, + color: *color, + uv: vec2(0.0, 0.0), + }, + UiVertex { + position: *position + vec2(size.x, 0.0), + color: *color, + uv: vec2(1.0, 0.0), + }, + UiVertex { + position: *position + *size, + color: *color, + uv: vec2(1.0, 1.0), + }, + UiVertex { + position: *position + vec2(0.0, size.y), + color: *color, + uv: vec2(0.0, 1.0), + }, + ]); + } }, UiDrawCommand::Text { position, size, color, text, font } => { //XXX: should we be doing this every time? diff --git a/hui/src/element/builtin/container.rs b/hui/src/element/builtin/container.rs index e1f4ae8..32734b6 100644 --- a/hui/src/element/builtin/container.rs +++ b/hui/src/element/builtin/container.rs @@ -62,6 +62,7 @@ pub struct Container { pub borders: Sides>, pub clip: bool, pub elements: Vec>, + pub corner_radius: Option, } impl Default for Container { @@ -79,6 +80,7 @@ impl Default for Container { borders: Default::default(), clip: Default::default(), elements: Vec::new(), + corner_radius: None, } } } @@ -168,7 +170,8 @@ impl UiElement for Container { ctx.draw.add(UiDrawCommand::Rectangle { position, size: ctx.measure.size, - color + color, + corner_radius: self.corner_radius, }); } diff --git a/hui/src/element/builtin/progress_bar.rs b/hui/src/element/builtin/progress_bar.rs index 720dc7c..06d5eea 100644 --- a/hui/src/element/builtin/progress_bar.rs +++ b/hui/src/element/builtin/progress_bar.rs @@ -55,14 +55,16 @@ impl UiElement for ProgressBar { ctx.draw.add(UiDrawCommand::Rectangle { position: ctx.layout.position, size: ctx.measure.size, - color: self.color_background + color: self.color_background, + corner_radius: None, }); } if value > 0. { ctx.draw.add(UiDrawCommand::Rectangle { position: ctx.layout.position, size: ctx.measure.size * vec2(value, 1.0), - color: self.color_foreground + color: self.color_foreground, + corner_radius: None, }); } } diff --git a/hui/src/element/builtin/rect.rs b/hui/src/element/builtin/rect.rs index 554f90d..30f6846 100644 --- a/hui/src/element/builtin/rect.rs +++ b/hui/src/element/builtin/rect.rs @@ -46,6 +46,7 @@ impl UiElement for Rect { position: ctx.layout.position, size: ctx.measure.size, color, + corner_radius: None, }); } }