clicking outside of a menu shouldnt do anything

This commit is contained in:
Dustin Carlino 2019-04-03 15:11:44 +09:00
parent 35d6995a7b
commit 94d08efd61
3 changed files with 22 additions and 17 deletions

View File

@ -27,7 +27,6 @@
- optionally limit canvas scrolling/zooming to some map bounds - optionally limit canvas scrolling/zooming to some map bounds
- top menu doesnt know when we have a more urgent input thing going! - top menu doesnt know when we have a more urgent input thing going!
- cant use G for geom debug mode and contextual polygon debug - cant use G for geom debug mode and contextual polygon debug
- on a menu with preselected thing, clicking ANYWHERE does stuff...
- X on all menus - X on all menus
- when dragging, dont give mouse movement to UI elements - when dragging, dont give mouse movement to UI elements
- start context menu when left click releases and we're not dragging - start context menu when left click releases and we're not dragging

View File

@ -1,5 +1,6 @@
# Demand data # Demand data
- https://en.wikipedia.org/wiki/Transportation_forecasting
- https://data.seattle.gov/Transportation/2016-Traffic-Flow-Counts/f22b-ywut - https://data.seattle.gov/Transportation/2016-Traffic-Flow-Counts/f22b-ywut
- counts per aterial - counts per aterial

View File

@ -7,6 +7,7 @@ pub struct Menu<T: Clone> {
// The bool is whether this choice is active or not // The bool is whether this choice is active or not
choices: Vec<(Option<Key>, String, bool, T)>, choices: Vec<(Option<Key>, String, bool, T)>,
current_idx: Option<usize>, current_idx: Option<usize>,
mouse_in_bounds: bool,
keys_enabled: bool, keys_enabled: bool,
pos: Position, pos: Position,
@ -78,6 +79,8 @@ impl<T: Clone> Menu<T> {
.collect(), .collect(),
current_idx: if keys_enabled { Some(0) } else { None }, current_idx: if keys_enabled { Some(0) } else { None },
keys_enabled, keys_enabled,
// TODO Bit of a hack, but eh.
mouse_in_bounds: !keys_enabled,
pos, pos,
row_height, row_height,
@ -106,7 +109,7 @@ impl<T: Clone> Menu<T> {
if ev == Event::LeftMouseButtonDown { if ev == Event::LeftMouseButtonDown {
if let Some(i) = self.current_idx { if let Some(i) = self.current_idx {
let (_, choice, active, data) = self.choices[i].clone(); let (_, choice, active, data) = self.choices[i].clone();
if active { if active && self.mouse_in_bounds {
return InputResult::Done(choice, data); return InputResult::Done(choice, data);
} else { } else {
return InputResult::StillActive; return InputResult::StillActive;
@ -117,23 +120,25 @@ impl<T: Clone> Menu<T> {
} else if ev == Event::RightMouseButtonDown { } else if ev == Event::RightMouseButtonDown {
return InputResult::Canceled; return InputResult::Canceled;
} else if let Event::MouseMovedTo(pt) = ev { } else if let Event::MouseMovedTo(pt) = ev {
let mut matched = false; if !canvas.is_dragging() {
for i in 0..self.choices.len() { for i in 0..self.choices.len() {
if self.choices[i].2 if self.choices[i].2
&& self && self
.first_choice_row .first_choice_row
.translate(0.0, (i as f64) * self.row_height) .translate(0.0, (i as f64) * self.row_height)
.contains(pt) .contains(pt)
{ {
self.current_idx = Some(i); self.current_idx = Some(i);
matched = true; self.mouse_in_bounds = true;
break; return InputResult::StillActive;
}
} }
self.mouse_in_bounds = false;
if !self.keys_enabled {
self.current_idx = None;
}
return InputResult::StillActive;
} }
if !matched && !self.keys_enabled {
self.current_idx = None;
}
return InputResult::StillActive;
} }
// Handle keys // Handle keys