From c9fb3ae28fe491bc55243fb80d8c6be93f37ad99 Mon Sep 17 00:00:00 2001 From: tcmal Date: Sun, 25 Aug 2024 17:44:23 +0100 Subject: feat(render): ui working --- examples/render-bsp/Cargo.toml | 4 ++-- examples/render-bsp/src/main.rs | 32 ++++++++++++++++++++++++-------- 2 files changed, 26 insertions(+), 10 deletions(-) (limited to 'examples') diff --git a/examples/render-bsp/Cargo.toml b/examples/render-bsp/Cargo.toml index 093409e..bdbab89 100644 --- a/examples/render-bsp/Cargo.toml +++ b/examples/render-bsp/Cargo.toml @@ -13,8 +13,8 @@ stockton-levels = { path = "../../stockton-levels" } stockton-contrib = { path = "../../stockton-contrib", features = ["delta_time", "flycam"] } winit = "^0.21" log = "0.4.0" -simple_logger = "^1.11" +simplelog = "^0.10" image = "0.23.2" -egui = "^0.2" +egui = "^0.12" legion = { version = "^0.3" } anyhow = "1.0.40" diff --git a/examples/render-bsp/src/main.rs b/examples/render-bsp/src/main.rs index 543c9fe..fd8e1d5 100644 --- a/examples/render-bsp/src/main.rs +++ b/examples/render-bsp/src/main.rs @@ -11,6 +11,7 @@ use log::warn; use std::collections::BTreeMap; use winit::{event::Event, event_loop::EventLoop, window::WindowBuilder}; +use egui::{containers::CentralPanel, Frame}; use stockton_contrib::delta_time::*; use stockton_contrib::flycam::*; @@ -50,8 +51,11 @@ impl FlycamInput for MovementInputs { #[system] fn hello_world(#[resource] ui: &mut UiState) { - let ui = ui.ui(); - ui.heading("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); + CentralPanel::default() + .frame(Frame::none()) + .show(ui.ctx(), |ui| { + ui.heading("Hello, World!"); + }); } fn main() { @@ -62,10 +66,16 @@ fn main() { fn try_main() -> Result<()> { // Initialise logger - simple_logger::SimpleLogger::new() - .with_level(log::LevelFilter::Debug) - .init() - .context("Error initialising logger")?; + simplelog::TermLogger::init( + log::LevelFilter::Debug, + simplelog::ConfigBuilder::new() + .set_max_level(log::LevelFilter::Debug) + .set_thread_mode(simplelog::ThreadLogMode::Names) + .build(), + simplelog::TerminalMode::Stderr, + simplelog::ColorChoice::Auto, + ) + .context("Error initialising logger")?; // Make a window let event_loop = EventLoop::new(); @@ -87,10 +97,16 @@ fn try_main() -> Result<()> { let bsp: Q3BspFile = bsp.context("Error loading bsp")?; let bsp: Q3BspFile = bsp.swizzle_to(); + // Create the UI State + let mut ui = UiState::new(); + // Create the renderer - let (renderer, tx) = Renderer::new(&window, bsp)?; + let (renderer, tx) = Renderer::new(&window, &mut ui, bsp)?; let new_control_flow = renderer.update_control_flow.clone(); + // Populate the initial UI state + ui.populate_initial_state(&renderer); + // Create the input manager let manager = { use stockton_input::InputMutation::*; @@ -111,7 +127,7 @@ fn try_main() -> Result<()> { // Load everything into the session let mut session = Session::new( move |resources| { - resources.insert(UiState::new(&renderer)); + resources.insert(ui); resources.insert(renderer); resources.insert(manager); resources.insert(Timing::default()); -- cgit v1.2.3