From 42c06cba332acb8c9843681728be0a08b0946d59 Mon Sep 17 00:00:00 2001 From: griffi-gh Date: Thu, 2 May 2024 02:20:54 +0200 Subject: [PATCH] integrate `hui-winit` --- Cargo.lock | 12 ++++++++++++ kubi/Cargo.toml | 1 + kubi/src/hui_integration.rs | 7 +++++++ kubi/src/lib.rs | 3 +++ kubi/src/ui/settings_ui.rs | 13 +++++++++++-- 5 files changed, 34 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index cb940b7..d207f43 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -960,6 +960,17 @@ dependencies = [ "log", ] +[[package]] +name = "hui-winit" +version = "0.1.0-alpha.4" +source = "git+https://github.com/griffi-gh/hui?rev=dd5af8b9e2#dd5af8b9e2dc4cb2beb0b130d82167258ea2bd4e" +dependencies = [ + "glam", + "hui", + "log", + "winit", +] + [[package]] name = "humantime" version = "2.1.0" @@ -1148,6 +1159,7 @@ dependencies = [ "hashbrown 0.14.3", "hui", "hui-glium", + "hui-winit", "image", "kubi-logging", "kubi-shared", diff --git a/kubi/Cargo.toml b/kubi/Cargo.toml index 227c237..5b54d87 100644 --- a/kubi/Cargo.toml +++ b/kubi/Cargo.toml @@ -13,6 +13,7 @@ kubi-shared = { path = "../kubi-shared" } kubi-logging = { path = "../kubi-logging" } hui = { version = "0.1.0-alpha.4", git = "https://github.com/griffi-gh/hui", rev = "dd5af8b9e2" } hui-glium = { version = "0.1.0-alpha.4", git = "https://github.com/griffi-gh/hui", rev = "dd5af8b9e2" } +hui-winit = { version = "0.1.0-alpha.4", git = "https://github.com/griffi-gh/hui", rev = "dd5af8b9e2" } log = "0.4" glium = { git = "https://github.com/glium/glium", rev = "a352c667" } glutin = "0.31" diff --git a/kubi/src/hui_integration.rs b/kubi/src/hui_integration.rs index 8eebc62..28a8583 100644 --- a/kubi/src/hui_integration.rs +++ b/kubi/src/hui_integration.rs @@ -41,3 +41,10 @@ pub fn kubi_ui_draw( ) { ui.renderer.draw(&mut target.0, size.0.as_vec2()); } + +pub fn hui_process_winit_events( + event: &winit::event::Event<()>, + mut ui: NonSendSync>, +) { + hui_winit::handle_winit_event(&mut ui.hui, event); +} diff --git a/kubi/src/lib.rs b/kubi/src/lib.rs index f90f5ec..feaf313 100644 --- a/kubi/src/lib.rs +++ b/kubi/src/lib.rs @@ -95,6 +95,8 @@ use chat::init_chat_manager; use crosshair_ui::{init_crosshair_image, draw_crosshair}; use settings_ui::render_settings_ui; +use crate::hui_integration::hui_process_winit_events; + /// stuff required to init the renderer and other basic systems fn pre_startup() -> Workload { ( @@ -280,6 +282,7 @@ pub fn kubi_main( window_target.set_control_flow(ControlFlow::Poll); + world.run_with_data(hui_process_winit_events, &event); process_winit_events(&mut world, &event); #[allow(clippy::collapsible_match, clippy::single_match)] diff --git a/kubi/src/ui/settings_ui.rs b/kubi/src/ui/settings_ui.rs index 3824d87..68923ab 100644 --- a/kubi/src/ui/settings_ui.rs +++ b/kubi/src/ui/settings_ui.rs @@ -1,4 +1,9 @@ -use hui::{color, element::{br::Break, container::Container, slider::Slider, text::Text, UiElementExt}, layout::{Alignment, Direction}, signal::Signal, size}; +use hui::{ + element::{br::Break, container::Container, slider::Slider, text::Text, UiElementExt}, + layout::{Alignment, Direction}, + signal::Signal, + frame_rect, size, +}; use shipyard::{NonSendSync, UniqueView, UniqueViewMut}; use winit::keyboard::KeyCode; use crate::{hui_integration::UiState, input::RawKbmInputState, rendering::WindowSize, settings::GameSettings}; @@ -20,10 +25,14 @@ pub fn render_settings_ui( } Container::default() .with_size(size!(100%)) + .with_background((0., 0., 0., 0.5)) .with_align(Alignment::Center) .with_children(|ui| { Container::default() - .with_background(color::BLACK) + .with_background(frame_rect! { + color: (0.2, 0.2, 0.2), + corner_radius: 8. + }) .with_size(size!(50%, 50%)) .with_direction(Direction::Horizontal) .with_gap(10.)