This commit is contained in:
griffi-gh 2024-02-19 05:36:38 +01:00
parent f2ff2ccfb5
commit fa5b89b3ec
2 changed files with 76 additions and 24 deletions

View file

@ -6,7 +6,10 @@ use winit::{
}; };
use hui::{ use hui::{
UiInstance, UiSize, UiInstance, UiSize,
element::container::{Alignment, Container, Sides} element::{
container::{Alignment, Container},
text::Text
},
}; };
use hui_glium::GliumUiRenderer; use hui_glium::GliumUiRenderer;
@ -33,12 +36,23 @@ fn main() {
hui.begin(); hui.begin();
hui.add(Container { hui.add(Container {
gap: 5.,
padding: Sides::all(5.),
align: (Alignment::Center, Alignment::Center), align: (Alignment::Center, Alignment::Center),
size: (UiSize::Fraction(1.), UiSize::Fraction(1.)), size: (UiSize::Fraction(1.), UiSize::Fraction(1.)),
background: Some(vec4(0.1, 0.1, 0.1, 1.)), elements: vec![Box::new(Container {
corner_radius: Some(10.), 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() ..Default::default()
}, resolution); }, resolution);

View file

@ -56,7 +56,7 @@ pub enum BindTexture {
//UserDefined(usize), //UserDefined(usize),
} }
#[derive(Clone, Copy, Debug, PartialEq)] #[derive(Clone, Copy, Debug, PartialEq, Default)]
pub struct UiVertex { pub struct UiVertex {
pub position: Vec2, pub position: Vec2,
pub color: Vec4, pub color: Vec4,
@ -136,10 +136,15 @@ impl UiDrawPlan {
let corner_radius = corner_radius.unwrap_or(0.0); let corner_radius = corner_radius.unwrap_or(0.0);
let vidx = swapper.current().vertices.len() as u32; let vidx = swapper.current().vertices.len() as u32;
if corner_radius > 0.0 { if corner_radius > 0.0 {
let mut vidx_ctr = vidx; //this code is stupid as fuck
todo!("rounded corners are not implemented");
//TODO vtx-based rounded corners //Random vert in the center for no reason
//swapper.current_mut().indices.extend(); //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 //TODO: make this configurable or compute dynamically
let rounded_corner_verts = 4; let rounded_corner_verts = 4;
@ -150,29 +155,62 @@ impl UiDrawPlan {
let y = angle.cos(); let y = angle.cos();
//Top-right corner //Top-right corner
swapper.current_mut().vertices.push(UiVertex { swapper.current_mut().vertices.push(UiVertex {
position: *position + vec2(x, 1. - y) * corner_radius + *size - vec2(corner_radius, 0.), position: *position + vec2(x, 1. - y) * corner_radius + vec2(size.x - 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),
color: *color, color: *color,
uv: vec2(0.0, 0.0), uv: vec2(0.0, 0.0),
}); });
//Bottom-right corner //Bottom-right corner
swapper.current_mut().vertices.push(UiVertex { 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, color: *color,
uv: vec2(0.0, 0.0), 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 { } else {
swapper.current_mut().indices.extend([vidx, vidx + 1, vidx + 2, vidx, vidx + 2, vidx + 3]); swapper.current_mut().indices.extend([vidx, vidx + 1, vidx + 2, vidx, vidx + 2, vidx + 3]);
swapper.current_mut().vertices.extend([ swapper.current_mut().vertices.extend([