use std::sync::Arc; use examples_common::Drawing; use rugui::{styles::{Size, Color}, Element, Gui}; use winit::application::ApplicationHandler; extern crate examples_common; extern crate pollster; extern crate rugui; extern crate wgpu; extern crate winit; fn main() { let mut app = App::Loading; let event_loop = winit::event_loop::EventLoop::new().unwrap(); event_loop.run_app(&mut app).unwrap(); } pub enum App { Loading, App(Application), } pub struct Application { gui: Gui<()>, drawing: Drawing, } impl ApplicationHandler for App { fn resumed(&mut self, event_loop: &winit::event_loop::ActiveEventLoop) { let window = Arc::new( event_loop .create_window( winit::window::Window::default_attributes() .with_title("Hello example") .with_visible(false), ) .unwrap(), ); let drawing = pollster::block_on(Drawing::new(window.clone())); window.set_visible(true); let size = window.inner_size(); let mut gui = Gui::new(size.into(), &drawing.device, &drawing.queue); let mut element = Element::new().with_label("hello element"); let styles = &mut element.styles; styles.transfomr_mut().max_width = Size::Percent(50.0); styles.transfomr_mut().max_height = Size::Percent(80.0); *styles.bg_color_mut() = Color::CYAN; let element_key = gui.add_element(element); gui.set_entry(Some(element_key)); *self = App::App(Application { gui, drawing, }); } fn window_event( &mut self, event_loop: &winit::event_loop::ActiveEventLoop, _window_id: winit::window::WindowId, event: winit::event::WindowEvent, ) { let this = match self { App::App(this) => this, App::Loading => return, }; match event { winit::event::WindowEvent::Resized(size) => { if size.width <= 0 || size.height <= 0 { return; } examples_common::resize_event(&mut this.gui, &mut this.drawing, size.into()); } winit::event::WindowEvent::CloseRequested => { event_loop.exit(); } winit::event::WindowEvent::RedrawRequested => { this.gui.update(); this.gui.prepare(&this.drawing.device, &this.drawing.queue); this.drawing.draw(&mut this.gui); } _ => {} } } }