Move Response and Sense to own files
This commit is contained in:
parent
53d0114d3c
commit
67c0fbdd01
5 changed files with 67 additions and 67 deletions
|
@ -69,7 +69,7 @@ impl ScrollArea {
|
||||||
/// Set the vertical scroll offset position.
|
/// Set the vertical scroll offset position.
|
||||||
///
|
///
|
||||||
/// See also: [`Ui::scroll_to_cursor`](crate::ui::Ui::scroll_to_cursor) and
|
/// 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 {
|
pub fn scroll_offset(mut self, offset: f32) -> Self {
|
||||||
self.offset = Some(Vec2::new(0.0, offset));
|
self.offset = Some(Vec2::new(0.0, offset));
|
||||||
self
|
self
|
||||||
|
|
|
@ -92,8 +92,9 @@ mod memory;
|
||||||
pub mod menu;
|
pub mod menu;
|
||||||
mod painter;
|
mod painter;
|
||||||
pub(crate) mod placer;
|
pub(crate) mod placer;
|
||||||
|
mod response;
|
||||||
|
mod sense;
|
||||||
pub mod style;
|
pub mod style;
|
||||||
mod types;
|
|
||||||
mod ui;
|
mod ui;
|
||||||
pub mod util;
|
pub mod util;
|
||||||
pub mod widgets;
|
pub mod widgets;
|
||||||
|
@ -122,8 +123,9 @@ pub use {
|
||||||
layout::*,
|
layout::*,
|
||||||
memory::Memory,
|
memory::Memory,
|
||||||
painter::Painter,
|
painter::Painter,
|
||||||
|
response::Response,
|
||||||
|
sense::Sense,
|
||||||
style::Style,
|
style::Style,
|
||||||
types::*,
|
|
||||||
ui::Ui,
|
ui::Ui,
|
||||||
widgets::*,
|
widgets::*,
|
||||||
};
|
};
|
||||||
|
|
|
@ -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);
|
*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
58
egui/src/sense.rs
Normal 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,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -6,7 +6,7 @@ use crate::{
|
||||||
color::*,
|
color::*,
|
||||||
math::*,
|
math::*,
|
||||||
paint::{Shadow, Stroke, TextStyle},
|
paint::{Shadow, Stroke, TextStyle},
|
||||||
types::*,
|
Response,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Specifies the look and feel of a [`Ui`].
|
/// Specifies the look and feel of a [`Ui`].
|
||||||
|
@ -197,7 +197,7 @@ impl Widgets {
|
||||||
pub fn style(&self, response: &Response) -> &WidgetVisuals {
|
pub fn style(&self, response: &Response) -> &WidgetVisuals {
|
||||||
if response.active || response.has_kb_focus {
|
if response.active || response.has_kb_focus {
|
||||||
&self.active
|
&self.active
|
||||||
} else if response.sense == Sense::hover() {
|
} else if response.sense == crate::Sense::hover() {
|
||||||
&self.disabled
|
&self.disabled
|
||||||
} else if response.hovered {
|
} else if response.hovered {
|
||||||
&self.hovered
|
&self.hovered
|
||||||
|
|
Loading…
Reference in a new issue