diff options
author | tcmal <me@aria.rip> | 2024-08-25 17:44:23 +0100 |
---|---|---|
committer | tcmal <me@aria.rip> | 2024-08-25 17:44:23 +0100 |
commit | 13d1d5214d7d7043f22dee0837fd6600aaa50797 (patch) | |
tree | d2adedb0c5a0986bab28855b10aa54e8575357d8 /stockton-passes/src/window.rs | |
parent | 6ab13f2d0cb345795f761181a06777ade61ff09c (diff) |
refactor(all): various cleanup
Diffstat (limited to 'stockton-passes/src/window.rs')
-rw-r--r-- | stockton-passes/src/window.rs | 46 |
1 files changed, 33 insertions, 13 deletions
diff --git a/stockton-passes/src/window.rs b/stockton-passes/src/window.rs index c806fa0..46ba1a1 100644 --- a/stockton-passes/src/window.rs +++ b/stockton-passes/src/window.rs @@ -84,17 +84,7 @@ pub struct UiState { } impl UiState { - pub fn new() -> Self { - UiState { - ctx: CtxRef::default(), - raw_input: RawInput::default(), - frame_active: false, - modifiers: Default::default(), - pointer_pos: Pos2::new(0.0, 0.0), - } - } - - pub fn populate_initial_state<'a, T: DrawPass>(&mut self, renderer: &Renderer<T>) { + pub fn populate_initial_state<T: DrawPass>(&mut self, renderer: &Renderer<T>) { let props = &renderer.context().target_chain().properties(); self.set_dimensions(props.extent.width, props.extent.height); self.set_pixels_per_point(Some(renderer.context().pixels_per_point())); @@ -163,19 +153,49 @@ impl UiState { fn handle_action(&mut self, action: KBAction) { // TODO match action { - KBAction::MousePress(stockton_input::MouseButton::Left) => { + KBAction::MousePress(btn) => { self.raw_input.events.push(Event::PointerButton { pos: self.pointer_pos, - button: egui::PointerButton::Primary, + button: match btn { + stockton_input::MouseButton::Left => egui::PointerButton::Primary, + stockton_input::MouseButton::Right => egui::PointerButton::Secondary, + stockton_input::MouseButton::Middle => egui::PointerButton::Middle, + stockton_input::MouseButton::Other(_) => todo!(), + }, pressed: true, modifiers: self.modifiers, }); } + KBAction::MouseRelease(btn) => { + self.raw_input.events.push(Event::PointerButton { + pos: self.pointer_pos, + button: match btn { + stockton_input::MouseButton::Left => egui::PointerButton::Primary, + stockton_input::MouseButton::Right => egui::PointerButton::Secondary, + stockton_input::MouseButton::Middle => egui::PointerButton::Middle, + stockton_input::MouseButton::Other(_) => todo!(), + }, + pressed: false, + modifiers: self.modifiers, + }); + } _ => (), } } } +impl Default for UiState { + fn default() -> Self { + UiState { + ctx: CtxRef::default(), + raw_input: RawInput::default(), + frame_active: false, + modifiers: Default::default(), + pointer_pos: Pos2::new(0.0, 0.0), + } + } +} + pub struct WindowFlow { window_events: Receiver<WindowEvent>, update_control_flow: Arc<RwLock<ControlFlow>>, |