From 67c0fbdd01e56878793324e7b9b06108aed87467 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Sun, 17 Jan 2021 02:40:14 +0100 Subject: [PATCH] Move Response and Sense to own files --- egui/src/containers/scroll_area.rs | 2 +- egui/src/lib.rs | 6 ++- egui/src/{types.rs => response.rs} | 64 +----------------------------- egui/src/sense.rs | 58 +++++++++++++++++++++++++++ egui/src/style.rs | 4 +- 5 files changed, 67 insertions(+), 67 deletions(-) rename egui/src/{types.rs => response.rs} (81%) create mode 100644 egui/src/sense.rs diff --git a/egui/src/containers/scroll_area.rs b/egui/src/containers/scroll_area.rs index d9a99c18..f30868ac 100644 --- a/egui/src/containers/scroll_area.rs +++ b/egui/src/containers/scroll_area.rs @@ -69,7 +69,7 @@ impl ScrollArea { /// Set the vertical scroll offset position. /// /// See also: [`Ui::scroll_to_cursor`](crate::ui::Ui::scroll_to_cursor) and - /// [`Response::scroll_to_me`](crate::types::Response::scroll_to_me) + /// [`Response::scroll_to_me`](crate::Response::scroll_to_me) pub fn scroll_offset(mut self, offset: f32) -> Self { self.offset = Some(Vec2::new(0.0, offset)); self diff --git a/egui/src/lib.rs b/egui/src/lib.rs index 01162d9b..587e9540 100644 --- a/egui/src/lib.rs +++ b/egui/src/lib.rs @@ -92,8 +92,9 @@ mod memory; pub mod menu; mod painter; pub(crate) mod placer; +mod response; +mod sense; pub mod style; -mod types; mod ui; pub mod util; pub mod widgets; @@ -122,8 +123,9 @@ pub use { layout::*, memory::Memory, painter::Painter, + response::Response, + sense::Sense, style::Style, - types::*, ui::Ui, widgets::*, }; diff --git a/egui/src/types.rs b/egui/src/response.rs similarity index 81% rename from egui/src/types.rs rename to egui/src/response.rs index f919c710..0fab484b 100644 --- a/egui/src/types.rs +++ b/egui/src/response.rs @@ -1,4 +1,5 @@ -use crate::{lerp, math::Rect, Align, CtxRef, Id, LayerId, Ui}; +use crate::math::{lerp, Align, Rect}; +use crate::{CtxRef, Id, LayerId, Sense, Ui}; // ---------------------------------------------------------------------------- @@ -201,64 +202,3 @@ impl std::ops::BitOrAssign for Response { *self = self.union(rhs); } } - -// ---------------------------------------------------------------------------- - -/// What sort of interaction is a widget sensitive to? -#[derive(Clone, Copy, Debug, Eq, PartialEq)] -// #[cfg_attr(feature = "persistence", derive(serde::Serialize))] -pub struct Sense { - /// buttons, sliders, windows ... - pub click: bool, - - /// sliders, windows, scroll bars, scroll areas ... - pub drag: bool, -} - -impl Sense { - /// 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() - } - - /// Sense clicks and hover, but not drags. - pub fn click() -> Self { - Self { - click: true, - drag: false, - } - } - - /// Sense drags and hover, but not clicks. - pub fn drag() -> Self { - Self { - click: false, - drag: true, - } - } - - /// Sense both clicks, drags and hover (e.g. a slider or window). - pub fn click_and_drag() -> Self { - Self { - click: true, - drag: true, - } - } - - /// The logical "or" of two `Sense`s. - #[must_use] - pub fn union(self, other: Self) -> Self { - Self { - click: self.click | other.click, - drag: self.drag | other.drag, - } - } -} diff --git a/egui/src/sense.rs b/egui/src/sense.rs new file mode 100644 index 00000000..42a83386 --- /dev/null +++ b/egui/src/sense.rs @@ -0,0 +1,58 @@ +/// What sort of interaction is a widget sensitive to? +#[derive(Clone, Copy, Debug, Eq, PartialEq)] +// #[cfg_attr(feature = "persistence", derive(serde::Serialize))] +pub struct Sense { + /// buttons, sliders, windows ... + pub click: bool, + + /// sliders, windows, scroll bars, scroll areas ... + pub drag: bool, +} + +impl Sense { + /// 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() + } + + /// Sense clicks and hover, but not drags. + pub fn click() -> Self { + Self { + click: true, + drag: false, + } + } + + /// Sense drags and hover, but not clicks. + pub fn drag() -> Self { + Self { + click: false, + drag: true, + } + } + + /// Sense both clicks, drags and hover (e.g. a slider or window). + pub fn click_and_drag() -> Self { + Self { + click: true, + drag: true, + } + } + + /// The logical "or" of two `Sense`s. + #[must_use] + pub fn union(self, other: Self) -> Self { + Self { + click: self.click | other.click, + drag: self.drag | other.drag, + } + } +} diff --git a/egui/src/style.rs b/egui/src/style.rs index 579261ec..411a2057 100644 --- a/egui/src/style.rs +++ b/egui/src/style.rs @@ -6,7 +6,7 @@ use crate::{ color::*, math::*, paint::{Shadow, Stroke, TextStyle}, - types::*, + Response, }; /// Specifies the look and feel of a [`Ui`]. @@ -197,7 +197,7 @@ impl Widgets { pub fn style(&self, response: &Response) -> &WidgetVisuals { if response.active || response.has_kb_focus { &self.active - } else if response.sense == Sense::hover() { + } else if response.sense == crate::Sense::hover() { &self.disabled } else if response.hovered { &self.hovered