From a2ab35bab88a014b753f9037fa2024ee99cdbdc5 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Sat, 26 Dec 2020 02:09:32 +0100 Subject: [PATCH] Rename `Sense::nothing()` to `Sense::hover()` --- CHANGELOG.md | 1 + egui/src/context.rs | 2 +- egui/src/demos/app.rs | 2 +- egui/src/demos/color_test.rs | 2 +- egui/src/introspection.rs | 2 +- egui/src/style.rs | 2 +- egui/src/types.rs | 9 +++++++-- egui/src/ui.rs | 6 +++--- egui/src/widgets/color_picker.rs | 2 +- egui/src/widgets/image.rs | 2 +- egui/src/widgets/mod.rs | 8 ++++---- egui/src/widgets/text_edit.rs | 2 +- 12 files changed, 23 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8668897e..d45649d3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,6 +34,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). * Combo boxes has scroll bars when needed. * Expand `Window` + `Resize` containers to be large enough for last frames content * `ui.columns`: Columns now defaults to justified top-to-down layouts. +* Rename `Sense::nothing()` to `Sense::hover()`. ### Fixed 🐛 diff --git a/egui/src/context.rs b/egui/src/context.rs index e7f941cf..6399a667 100644 --- a/egui/src/context.rs +++ b/egui/src/context.rs @@ -213,7 +213,7 @@ impl CtxRef { .map(|id| self.memory().lost_kb_focus(id)) .unwrap_or(false); - if id.is_none() || sense == Sense::nothing() || !layer_id.allow_interaction() { + if id.is_none() || sense == Sense::hover() || !layer_id.allow_interaction() { // Not interested or allowed input: return Response { ctx: self.clone(), diff --git a/egui/src/demos/app.rs b/egui/src/demos/app.rs index 68ebe59a..ba0d2f46 100644 --- a/egui/src/demos/app.rs +++ b/egui/src/demos/app.rs @@ -110,7 +110,7 @@ impl FrameHistory { // TODO: we should not use `slider_width` as default graph width. let height = ui.style().spacing.slider_width; let (id, rect) = ui.allocate_space(vec2(ui.available_size_before_wrap_finite().x, height)); - let response = ui.interact(rect, id, Sense::nothing()); + let response = ui.interact(rect, id, Sense::hover()); let style = ui.style().noninteractive(); let mut cmds = vec![PaintCmd::Rect { diff --git a/egui/src/demos/color_test.rs b/egui/src/demos/color_test.rs index fbff783c..649601fe 100644 --- a/egui/src/demos/color_test.rs +++ b/egui/src/demos/color_test.rs @@ -268,7 +268,7 @@ impl ColorTest { fn vertex_gradient(ui: &mut Ui, bg_fill: Srgba, gradient: &Gradient) -> Response { use crate::paint::*; let (id, rect) = ui.allocate_space(GRADIENT_SIZE); - let response = ui.interact(rect, id, Sense::nothing()); + let response = ui.interact(rect, id, Sense::hover()); if bg_fill != Default::default() { let mut triangles = Triangles::default(); triangles.add_colored_rect(rect, bg_fill); diff --git a/egui/src/introspection.rs b/egui/src/introspection.rs index f914f576..9a1f4836 100644 --- a/egui/src/introspection.rs +++ b/egui/src/introspection.rs @@ -19,7 +19,7 @@ impl Texture { size *= ui.available_width() / size.x; } let (id, rect) = ui.allocate_space(size); - let response = ui.interact(rect, id, Sense::nothing()); + let response = ui.interact(rect, id, Sense::hover()); let mut triangles = Triangles::default(); triangles.add_rect_with_uv(rect, [pos2(0.0, 0.0), pos2(1.0, 1.0)].into(), WHITE); ui.painter().add(PaintCmd::triangles(triangles)); diff --git a/egui/src/style.rs b/egui/src/style.rs index 3b6e544e..73156b54 100644 --- a/egui/src/style.rs +++ b/egui/src/style.rs @@ -188,7 +188,7 @@ impl Widgets { pub fn style(&self, response: &Response) -> &WidgetVisuals { if response.active || response.has_kb_focus { &self.active - } else if response.sense == Sense::nothing() { + } else if response.sense == Sense::hover() { &self.disabled } else if response.hovered { &self.hovered diff --git a/egui/src/types.rs b/egui/src/types.rs index a7ed462f..10754de5 100644 --- a/egui/src/types.rs +++ b/egui/src/types.rs @@ -203,14 +203,19 @@ pub struct Sense { } impl Sense { - /// Senses no clicks or drags (but everything senses mouse hover). - pub fn nothing() -> Self { + /// Senses no clicks or drags. Only senses mouse hover. + pub fn hover() -> Self { Self { click: false, drag: false, } } + #[deprecated = "Use hover()"] + pub fn nothing() -> Self { + Sense::hover() + } + pub fn click() -> Self { Self { click: true, diff --git a/egui/src/ui.rs b/egui/src/ui.rs index 823aa4bd..258d4249 100644 --- a/egui/src/ui.rs +++ b/egui/src/ui.rs @@ -398,7 +398,7 @@ impl Ui { self.style().spacing.item_spacing, rect, None, - Sense::nothing(), + Sense::hover(), ) } @@ -787,7 +787,7 @@ impl Ui { let ret = add_contents(&mut child_ui); let size = child_ui.min_size(); let (id, rect) = self.allocate_space(size); - (ret, self.interact(rect, id, Sense::nothing())) + (ret, self.interact(rect, id, Sense::hover())) } /// Redirect paint commands to another paint layer. @@ -851,7 +851,7 @@ impl Ui { ); let (id, rect) = self.allocate_space(indent + size); - (ret, self.interact(rect, id, Sense::nothing())) + (ret, self.interact(rect, id, Sense::hover())) } #[deprecated] diff --git a/egui/src/widgets/color_picker.rs b/egui/src/widgets/color_picker.rs index d5350973..f98655e0 100644 --- a/egui/src/widgets/color_picker.rs +++ b/egui/src/widgets/color_picker.rs @@ -44,7 +44,7 @@ pub fn show_color(ui: &mut Ui, color: impl Into, desired_size: Vec2) -> R fn show_srgba(ui: &mut Ui, srgba: Srgba, desired_size: Vec2) -> Response { let (id, rect) = ui.allocate_space(desired_size); - let response = ui.interact(rect, id, Sense::nothing()); + let response = ui.interact(rect, id, Sense::hover()); background_checkers(ui.painter(), rect); ui.painter().add(PaintCmd::Rect { rect, diff --git a/egui/src/widgets/image.rs b/egui/src/widgets/image.rs index 511abb96..acc8418b 100644 --- a/egui/src/widgets/image.rs +++ b/egui/src/widgets/image.rs @@ -74,6 +74,6 @@ impl Widget for Image { fn ui(self, ui: &mut Ui) -> Response { let (id, rect) = ui.allocate_space(self.desired_size); self.paint_at(ui, rect); - ui.interact(rect, id, Sense::nothing()) + ui.interact(rect, id, Sense::hover()) } } diff --git a/egui/src/widgets/mod.rs b/egui/src/widgets/mod.rs index aca6a251..5aef35f8 100644 --- a/egui/src/widgets/mod.rs +++ b/egui/src/widgets/mod.rs @@ -187,7 +187,7 @@ impl Widget for Label { } else { let galley = self.layout(ui); let (id, rect) = ui.allocate_space(galley.size); - let response = ui.interact(rect, id, Sense::nothing()); + let response = ui.interact(rect, id, Sense::hover()); let rect = ui.layout().align_size_within_rect(galley.size, rect); self.paint_galley(ui, rect.min, galley); response @@ -365,10 +365,10 @@ impl Button { } /// If you set this to `false`, the button will be grayed out and un-clickable. - /// `enabled(false)` has the same effect as calling `sense(Sense::nothing())`. + /// `enabled(false)` has the same effect as calling `sense(Sense::hover())`. pub fn enabled(mut self, enabled: bool) -> Self { if !enabled { - self.sense = Sense::nothing(); + self.sense = Sense::hover(); } self } @@ -737,6 +737,6 @@ impl Widget for Separator { }; let stroke = ui.style().visuals.widgets.noninteractive.bg_stroke; ui.painter().line_segment(points, stroke); - ui.interact(rect, id, Sense::nothing()) + ui.interact(rect, id, Sense::hover()) } } diff --git a/egui/src/widgets/text_edit.rs b/egui/src/widgets/text_edit.rs index 8158db8f..a3b0c6bd 100644 --- a/egui/src/widgets/text_edit.rs +++ b/egui/src/widgets/text_edit.rs @@ -255,7 +255,7 @@ impl<'t> Widget for TextEdit<'t> { let sense = if enabled { Sense::click_and_drag() } else { - Sense::nothing() + Sense::hover() }; let response = ui.interact(rect, id, sense);