Move Response and Sense to own files

This commit is contained in:
Emil Ernerfeldt 2021-01-17 02:40:14 +01:00
parent 53d0114d3c
commit 67c0fbdd01
5 changed files with 67 additions and 67 deletions

View file

@ -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

View file

@ -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::*,
};

View file

@ -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,
}
}
}

58
egui/src/sense.rs Normal file
View file

@ -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,
}
}
}

View file

@ -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