Rename Sense::nothing() to Sense::hover()

This commit is contained in:
Emil Ernerfeldt 2020-12-26 02:09:32 +01:00
parent b65e6327ab
commit a2ab35bab8
12 changed files with 23 additions and 17 deletions

View file

@ -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. * Combo boxes has scroll bars when needed.
* Expand `Window` + `Resize` containers to be large enough for last frames content * Expand `Window` + `Resize` containers to be large enough for last frames content
* `ui.columns`: Columns now defaults to justified top-to-down layouts. * `ui.columns`: Columns now defaults to justified top-to-down layouts.
* Rename `Sense::nothing()` to `Sense::hover()`.
### Fixed 🐛 ### Fixed 🐛

View file

@ -213,7 +213,7 @@ impl CtxRef {
.map(|id| self.memory().lost_kb_focus(id)) .map(|id| self.memory().lost_kb_focus(id))
.unwrap_or(false); .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: // Not interested or allowed input:
return Response { return Response {
ctx: self.clone(), ctx: self.clone(),

View file

@ -110,7 +110,7 @@ impl FrameHistory {
// TODO: we should not use `slider_width` as default graph width. // TODO: we should not use `slider_width` as default graph width.
let height = ui.style().spacing.slider_width; let height = ui.style().spacing.slider_width;
let (id, rect) = ui.allocate_space(vec2(ui.available_size_before_wrap_finite().x, height)); 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 style = ui.style().noninteractive();
let mut cmds = vec![PaintCmd::Rect { let mut cmds = vec![PaintCmd::Rect {

View file

@ -268,7 +268,7 @@ impl ColorTest {
fn vertex_gradient(ui: &mut Ui, bg_fill: Srgba, gradient: &Gradient) -> Response { fn vertex_gradient(ui: &mut Ui, bg_fill: Srgba, gradient: &Gradient) -> Response {
use crate::paint::*; use crate::paint::*;
let (id, rect) = ui.allocate_space(GRADIENT_SIZE); 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() { if bg_fill != Default::default() {
let mut triangles = Triangles::default(); let mut triangles = Triangles::default();
triangles.add_colored_rect(rect, bg_fill); triangles.add_colored_rect(rect, bg_fill);

View file

@ -19,7 +19,7 @@ impl Texture {
size *= ui.available_width() / size.x; size *= ui.available_width() / size.x;
} }
let (id, rect) = ui.allocate_space(size); 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(); let mut triangles = Triangles::default();
triangles.add_rect_with_uv(rect, [pos2(0.0, 0.0), pos2(1.0, 1.0)].into(), WHITE); triangles.add_rect_with_uv(rect, [pos2(0.0, 0.0), pos2(1.0, 1.0)].into(), WHITE);
ui.painter().add(PaintCmd::triangles(triangles)); ui.painter().add(PaintCmd::triangles(triangles));

View file

@ -188,7 +188,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::nothing() { } else if response.sense == Sense::hover() {
&self.disabled &self.disabled
} else if response.hovered { } else if response.hovered {
&self.hovered &self.hovered

View file

@ -203,14 +203,19 @@ pub struct Sense {
} }
impl Sense { impl Sense {
/// Senses no clicks or drags (but everything senses mouse hover). /// Senses no clicks or drags. Only senses mouse hover.
pub fn nothing() -> Self { pub fn hover() -> Self {
Self { Self {
click: false, click: false,
drag: false, drag: false,
} }
} }
#[deprecated = "Use hover()"]
pub fn nothing() -> Self {
Sense::hover()
}
pub fn click() -> Self { pub fn click() -> Self {
Self { Self {
click: true, click: true,

View file

@ -398,7 +398,7 @@ impl Ui {
self.style().spacing.item_spacing, self.style().spacing.item_spacing,
rect, rect,
None, None,
Sense::nothing(), Sense::hover(),
) )
} }
@ -787,7 +787,7 @@ impl Ui {
let ret = add_contents(&mut child_ui); let ret = add_contents(&mut child_ui);
let size = child_ui.min_size(); let size = child_ui.min_size();
let (id, rect) = self.allocate_space(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. /// Redirect paint commands to another paint layer.
@ -851,7 +851,7 @@ impl Ui {
); );
let (id, rect) = self.allocate_space(indent + size); let (id, rect) = self.allocate_space(indent + size);
(ret, self.interact(rect, id, Sense::nothing())) (ret, self.interact(rect, id, Sense::hover()))
} }
#[deprecated] #[deprecated]

View file

@ -44,7 +44,7 @@ pub fn show_color(ui: &mut Ui, color: impl Into<Srgba>, desired_size: Vec2) -> R
fn show_srgba(ui: &mut Ui, srgba: Srgba, desired_size: Vec2) -> Response { fn show_srgba(ui: &mut Ui, srgba: Srgba, desired_size: Vec2) -> Response {
let (id, rect) = ui.allocate_space(desired_size); 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); background_checkers(ui.painter(), rect);
ui.painter().add(PaintCmd::Rect { ui.painter().add(PaintCmd::Rect {
rect, rect,

View file

@ -74,6 +74,6 @@ impl Widget for Image {
fn ui(self, ui: &mut Ui) -> Response { fn ui(self, ui: &mut Ui) -> Response {
let (id, rect) = ui.allocate_space(self.desired_size); let (id, rect) = ui.allocate_space(self.desired_size);
self.paint_at(ui, rect); self.paint_at(ui, rect);
ui.interact(rect, id, Sense::nothing()) ui.interact(rect, id, Sense::hover())
} }
} }

View file

@ -187,7 +187,7 @@ impl Widget for Label {
} else { } else {
let galley = self.layout(ui); let galley = self.layout(ui);
let (id, rect) = ui.allocate_space(galley.size); 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); let rect = ui.layout().align_size_within_rect(galley.size, rect);
self.paint_galley(ui, rect.min, galley); self.paint_galley(ui, rect.min, galley);
response response
@ -365,10 +365,10 @@ impl Button {
} }
/// If you set this to `false`, the button will be grayed out and un-clickable. /// 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 { pub fn enabled(mut self, enabled: bool) -> Self {
if !enabled { if !enabled {
self.sense = Sense::nothing(); self.sense = Sense::hover();
} }
self self
} }
@ -737,6 +737,6 @@ impl Widget for Separator {
}; };
let stroke = ui.style().visuals.widgets.noninteractive.bg_stroke; let stroke = ui.style().visuals.widgets.noninteractive.bg_stroke;
ui.painter().line_segment(points, stroke); ui.painter().line_segment(points, stroke);
ui.interact(rect, id, Sense::nothing()) ui.interact(rect, id, Sense::hover())
} }
} }

View file

@ -255,7 +255,7 @@ impl<'t> Widget for TextEdit<'t> {
let sense = if enabled { let sense = if enabled {
Sense::click_and_drag() Sense::click_and_drag()
} else { } else {
Sense::nothing() Sense::hover()
}; };
let response = ui.interact(rect, id, sense); let response = ui.interact(rect, id, sense);