diff --git a/hui-examples/examples/rounded.rs b/hui-examples/examples/rounded.rs index 449c2d8..46e2e3c 100644 --- a/hui-examples/examples/rounded.rs +++ b/hui-examples/examples/rounded.rs @@ -6,7 +6,10 @@ use winit::{ }; use hui::{ UiInstance, UiSize, - element::container::{Alignment, Container, Sides} + element::{ + container::{Alignment, Container}, + text::Text + }, }; use hui_glium::GliumUiRenderer; @@ -33,12 +36,23 @@ fn main() { hui.begin(); hui.add(Container { - gap: 5., - padding: Sides::all(5.), align: (Alignment::Center, Alignment::Center), size: (UiSize::Fraction(1.), UiSize::Fraction(1.)), - background: Some(vec4(0.1, 0.1, 0.1, 1.)), - corner_radius: Some(10.), + elements: vec![Box::new(Container { + align: (Alignment::Center, Alignment::Center), + size: (UiSize::Fraction(0.5), UiSize::Fraction(0.5)), + background: Some(vec4(1., 0.1, 0.1, 1.)), + corner_radius: Some(30.), + elements: vec![ + Box::new(Text { + text: "You tried".into(), + text_size: 50, + color: vec4(1., 1., 1., 1.), + ..Default::default() + }), + ], + ..Default::default() + })], ..Default::default() }, resolution); diff --git a/hui/src/draw.rs b/hui/src/draw.rs index 10f472c..2a8329a 100644 --- a/hui/src/draw.rs +++ b/hui/src/draw.rs @@ -56,7 +56,7 @@ pub enum BindTexture { //UserDefined(usize), } -#[derive(Clone, Copy, Debug, PartialEq)] +#[derive(Clone, Copy, Debug, PartialEq, Default)] pub struct UiVertex { pub position: Vec2, pub color: Vec4, @@ -136,10 +136,15 @@ impl UiDrawPlan { let corner_radius = corner_radius.unwrap_or(0.0); let vidx = swapper.current().vertices.len() as u32; if corner_radius > 0.0 { - let mut vidx_ctr = vidx; - todo!("rounded corners are not implemented"); - //TODO vtx-based rounded corners - //swapper.current_mut().indices.extend(); + //this code is stupid as fuck + + //Random vert in the center for no reason + //lol + swapper.current_mut().vertices.push(UiVertex { + position: *position + *size * vec2(0.5, 0.5), + color: *color, + uv: vec2(0., 0.), + }); //TODO: make this configurable or compute dynamically let rounded_corner_verts = 4; @@ -150,29 +155,62 @@ impl UiDrawPlan { let y = angle.cos(); //Top-right corner swapper.current_mut().vertices.push(UiVertex { - position: *position + vec2(x, 1. - y) * corner_radius + *size - vec2(corner_radius, 0.), - color: *color, - uv: vec2(0.0, 0.0), - }); - //Top-left corner - swapper.current_mut().vertices.push(UiVertex { - position: *position + vec2(x, y), - color: *color, - uv: vec2(0.0, 0.0), - }); - //Bottom-left corner - swapper.current_mut().vertices.push(UiVertex { - position: *position + vec2(x, y), + position: *position + vec2(x, 1. - y) * corner_radius + vec2(size.x - corner_radius, 0.), color: *color, uv: vec2(0.0, 0.0), }); //Bottom-right corner swapper.current_mut().vertices.push(UiVertex { - position: *position + vec2(x, y), + position: *position + vec2(x - 1., y) * corner_radius + vec2(size.x, size.y - corner_radius), color: *color, uv: vec2(0.0, 0.0), }); + //Bottom-left corner + swapper.current_mut().vertices.push(UiVertex { + position: *position + vec2(1. - x, y) * corner_radius + vec2(0., size.y - corner_radius), + color: *color, + uv: vec2(0.0, 0.0), + }); + //Top-left corner + swapper.current_mut().vertices.push(UiVertex { + position: *position + vec2(1. - x, 1. - y) * corner_radius, + color: *color, + uv: vec2(0.0, 0.0), + }); + // mental illness: + if i > 0 { + swapper.current_mut().indices.extend([ + //Top-right corner + vidx, + vidx + 1 + (i - 1) * 4, + vidx + 1 + i * 4, + //Bottom-right corner + vidx, + vidx + 1 + (i - 1) * 4 + 1, + vidx + 1 + i * 4 + 1, + //Bottom-left corner + vidx, + vidx + 1 + (i - 1) * 4 + 2, + vidx + 1 + i * 4 + 2, + //Top-left corner + vidx, + vidx + 1 + (i - 1) * 4 + 3, + vidx + 1 + i * 4 + 3, + ]); + } } + //Fill in the rest + //mental illness 2: + // swapper.current_mut().indices.extend([ + // //Top + // // vidx, + // // vidx + 1 + (rounded_corner_verts - 1), + // // vidx + 1, + // //Right?, i think + // vidx, + // vidx + 1 + (rounded_corner_verts - 1) * 4 + 1, + // vidx + 1 + 1, + // ]); } else { swapper.current_mut().indices.extend([vidx, vidx + 1, vidx + 2, vidx, vidx + 2, vidx + 3]); swapper.current_mut().vertices.extend([