aboutsummaryrefslogtreecommitdiff
path: root/stockton-passes/src/window.rs
diff options
context:
space:
mode:
Diffstat (limited to 'stockton-passes/src/window.rs')
-rw-r--r--stockton-passes/src/window.rs46
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>>,