From bc5dbd718e53e9cc5183d6037562c03f1d30c8b1 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Tue, 20 Oct 2020 14:52:18 +0200 Subject: [PATCH] Fix: Context::wants_mouse_input() now returns false if a mouse drag started outside of Egui --- TODO.md | 8 ++++++++ egui/src/context.rs | 18 +++++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/TODO.md b/TODO.md index 8d93f84e..557d5828 100644 --- a/TODO.md +++ b/TODO.md @@ -2,6 +2,14 @@ TODO-list for the Egui project. If you looking for something to do, look here. +## Top priority + +* Text input: text selection etc +* Fix `is_mouse_over_area()` for menu bar: + * Probably a good time to create some sort of `ctx.top_panel()` allocation system and refactor paint layers + +## Other + * Widgets * [ ] Tooltips: * [ ] Tooltip widget: Something that looks like this: (?) :that shows text on hover. diff --git a/egui/src/context.rs b/egui/src/context.rs index e98ea981..58847911 100644 --- a/egui/src/context.rs +++ b/egui/src/context.rs @@ -305,6 +305,8 @@ impl Context { pub fn is_mouse_over_area(&self) -> bool { if let Some(mouse_pos) = self.input.mouse.pos { if let Some(layer) = self.layer_at(mouse_pos) { + // TODO: this currently returns false for hovering the menu bar. + // We should probably move the menu bar to its own area to fix this. layer.order != Order::Background } else { false @@ -319,10 +321,13 @@ impl Context { /// or the user is dragging an Egui widget. /// If false, the mouse is outside of any Egui area and so /// you may be interested in what it is doing (e.g. controlling your game). + /// Returns `false` if a drag starts outside of Egui and then moves over an Egui window. pub fn wants_mouse_input(&self) -> bool { - self.is_mouse_over_area() || self.is_using_mouse() + self.is_using_mouse() || (self.is_mouse_over_area() && !self.input().mouse.down) } + /// Is Egui currently using the mouse position (e.g. dragging a slider). + /// NOTE: this will return false if the mouse is just hovering over an Egui window. pub fn is_using_mouse(&self) -> bool { self.memory().interaction.is_using_mouse() } @@ -528,6 +533,17 @@ impl Context { pub fn inspection_ui(&self, ui: &mut Ui) { use crate::containers::*; + ui.label(format!("Is using mouse: {}", self.is_using_mouse())) + .on_hover_text("Is Egui currently using the mouse actively (e.g. dragging a slider)?"); + ui.label(format!("Wants mouse input: {}", self.wants_mouse_input())) + .on_hover_text("Is Egui currently interested in the location of the mouse (either because it is in use, or because it is hovering over a window)."); + ui.label(format!( + "Wants keyboard input: {}", + self.wants_keyboard_input() + )) + .on_hover_text("Is Egui currently listening for text input"); + ui.advance_cursor(16.0); + CollapsingHeader::new("Input") .default_open(true) .show(ui, |ui| ui.input().clone().ui(ui));