From a293b5914a1a568001b09dba2035841d831afc0e Mon Sep 17 00:00:00 2001 From: Kenny Levinsen Date: Wed, 31 Jul 2019 17:37:15 +0200 Subject: [PATCH] Fix input offsets --- src/main.rs | 11 +++++------ src/module.rs | 9 +++++++++ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/main.rs b/src/main.rs index a0d5500..e546018 100644 --- a/src/main.rs +++ b/src/main.rs @@ -432,12 +432,11 @@ fn main() { app.flush_display(); } Cmd::Input { pos, input } => { - if pos.0 >= 20 || pos.1 >= 20 { - // We need to deal with our margin. - if let Some(m) = app.get_module(pos) { - m.input(input); - q.lock().unwrap().push_back(Cmd::Draw); - } + if let Some(m) = app.get_module(pos) { + let bounds = m.get_bounds(); + let input = input.offset((bounds.0, bounds.1)); + m.input(input); + q.lock().unwrap().push_back(Cmd::Draw); } } Cmd::Exit => { diff --git a/src/module.rs b/src/module.rs index 5963f41..eef2815 100644 --- a/src/module.rs +++ b/src/module.rs @@ -10,6 +10,15 @@ pub enum Input { Scroll { pos: (u32, u32), x: f64, y: f64 }, } +impl Input { + pub fn offset(&self, offset: (u32, u32)) -> Input{ + match self { + Input::Click{pos, button} => Input::Click{pos: (pos.0 - offset.0, pos.1 - offset.1), button: *button}, + Input::Scroll{pos, x, y} => Input::Scroll{pos: (pos.0 - offset.0, pos.1 - offset.1), x: *x, y: *y}, + } + } +} + pub trait ModuleImpl { fn draw( &self,