mirror of
https://github.com/griffi-gh/hUI.git
synced 2024-11-22 07:08:42 -06:00
wip
This commit is contained in:
parent
4828500c45
commit
c50333805b
55
hui-examples/examples/rounded.rs
Normal file
55
hui-examples/examples/rounded.rs
Normal file
|
@ -0,0 +1,55 @@
|
|||
use glam::{vec4, UVec2};
|
||||
use glium::{backend::glutin::SimpleWindowBuilder, Surface};
|
||||
use winit::{
|
||||
event::{Event, WindowEvent},
|
||||
event_loop::{EventLoopBuilder, ControlFlow}
|
||||
};
|
||||
use hui::{
|
||||
UiInstance, UiSize,
|
||||
element::container::{Alignment, Container, Sides}
|
||||
};
|
||||
use hui_glium::GliumUiRenderer;
|
||||
|
||||
fn main() {
|
||||
kubi_logging::init();
|
||||
|
||||
let event_loop = EventLoopBuilder::new().build().unwrap();
|
||||
let (_window, display) = SimpleWindowBuilder::new().build(&event_loop);
|
||||
|
||||
let mut hui = UiInstance::new();
|
||||
let mut backend = GliumUiRenderer::new(&display);
|
||||
event_loop.run(|event, window_target| {
|
||||
window_target.set_control_flow(ControlFlow::Poll);
|
||||
match event {
|
||||
Event::WindowEvent { event: WindowEvent::CloseRequested, .. } => {
|
||||
window_target.exit();
|
||||
},
|
||||
Event::AboutToWait => {
|
||||
let mut frame = display.draw();
|
||||
frame.clear_color_srgb(0.5, 0.5, 0.5, 0.);
|
||||
|
||||
let resolution = UVec2::from(display.get_framebuffer_dimensions()).as_vec2();
|
||||
|
||||
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.),
|
||||
..Default::default()
|
||||
}, resolution);
|
||||
|
||||
hui.end();
|
||||
|
||||
backend.update(&hui);
|
||||
backend.draw(&mut frame, resolution);
|
||||
|
||||
frame.finish().unwrap();
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
}).unwrap();
|
||||
}
|
|
@ -136,9 +136,43 @@ 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();
|
||||
|
||||
//TODO: make this configurable or compute dynamically
|
||||
let rounded_corner_verts = 4;
|
||||
for i in 0..rounded_corner_verts {
|
||||
let cratio = i as f32 / rounded_corner_verts as f32;
|
||||
let angle = cratio * std::f32::consts::PI * 0.5;
|
||||
let x = angle.sin();
|
||||
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),
|
||||
color: *color,
|
||||
uv: vec2(0.0, 0.0),
|
||||
});
|
||||
//Bottom-right corner
|
||||
swapper.current_mut().vertices.push(UiVertex {
|
||||
position: *position + vec2(x, y),
|
||||
color: *color,
|
||||
uv: vec2(0.0, 0.0),
|
||||
});
|
||||
}
|
||||
} else {
|
||||
swapper.current_mut().indices.extend([vidx, vidx + 1, vidx + 2, vidx, vidx + 2, vidx + 3]);
|
||||
swapper.current_mut().vertices.extend([
|
||||
|
|
Loading…
Reference in a new issue