Skip to content

Commit

Permalink
do not move cursor if last navigation was caused by scroll
Browse files Browse the repository at this point in the history
  • Loading branch information
griffi-gh committed Oct 2, 2023
1 parent f2f6129 commit 8e8a422
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions yarge-frontend-sdl/src/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ pub struct Menu {
schedule_save: bool,
theme: UiTheme,
mouse_navigation: Option<i32>,
last_navigation_was_mouse_scroll: bool,
}
impl Menu {
pub fn new(config: &Configuration) -> Self {
Expand All @@ -133,6 +134,7 @@ impl Menu {
schedule_save: false,
theme: config.theme.resolve(),
mouse_navigation: None,
last_navigation_was_mouse_scroll: false,
}
}
pub fn is_active(&self) -> bool {
Expand Down Expand Up @@ -176,24 +178,34 @@ impl Menu {
},
Event::KeyDown { keycode: Some(Keycode::Down), .. } if self.active => {
self.cursor += 1;
self.last_navigation_was_mouse_scroll = false;
},
Event::KeyDown { keycode: Some(Keycode::Up), .. } if self.active => {
self.cursor -= 1;
self.last_navigation_was_mouse_scroll = false;
},
Event::MouseWheel { y, .. } if self.active => {
//self.scroll -= *y * MENU_ITEM_HEIGHT as i32 / 2;
self.cursor -= *y as isize;
self.last_navigation_was_mouse_scroll = true;
},
Event::MouseMotion { y, .. } |
Event::MouseButtonDown { mouse_btn: MouseButton::Left, y, .. } if self.active => {
Event::MouseMotion { y, .. } if self.active => {
self.mouse_navigation = Some(*y);
self.last_navigation_was_mouse_scroll = false;
},
Event::MouseButtonUp { mouse_btn: MouseButton::Left, y, .. } if self.active => {
Event::MouseButtonDown { mouse_btn: MouseButton::Left, y, .. } if self.active && !self.last_navigation_was_mouse_scroll => {
self.mouse_navigation = Some(*y);
},
Event::MouseButtonUp { mouse_btn: MouseButton::Left, y, .. } if self.active => {
if !self.last_navigation_was_mouse_scroll {
self.mouse_navigation = Some(*y);
}
self.clicked = true;
self.last_navigation_was_mouse_scroll = false;
}
Event::KeyDown { keycode: Some(Keycode::Return | Keycode::Return2), repeat: false, .. } if self.active => {
self.clicked = true;
self.last_navigation_was_mouse_scroll = false;
},
_ => ()
}
Expand Down

0 comments on commit 8e8a422

Please sign in to comment.