feat: change to PointingHand when hovering over a button (#3312)

* feat: change to PointingHand when hovering over a button

* feat: make this a togglable option that is off by default

* fix: typo

* feat: use Option<CursorIcon> instead for the option.

* remove superfluous comment

---------

Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
This commit is contained in:
zkldi 2023-09-08 08:37:03 +01:00 committed by GitHub
parent 2338a854f9
commit 523aa6b8ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 1 deletions

View File

@ -2,7 +2,9 @@
#![allow(clippy::if_same_then_else)]
use crate::{ecolor::*, emath::*, FontFamily, FontId, Response, RichText, WidgetText};
use crate::{
ecolor::*, emath::*, ComboBox, CursorIcon, FontFamily, FontId, Response, RichText, WidgetText,
};
use epaint::{Rounding, Shadow, Stroke};
use std::collections::BTreeMap;
@ -544,6 +546,13 @@ pub struct Visuals {
///
/// Enabling this will affect ALL sliders, and can be enabled/disabled per slider with [`Slider::trailing_fill`].
pub slider_trailing_fill: bool,
/// Should the cursor change when the user hovers over an interactive/clickable item?
///
/// This is consistent with a lot of browser-based applications (vscode, github
/// all turn your cursor into [`CursorIcon::PointingHand`] when a button is
/// hovered) but it is inconsistent with native UI toolkits.
pub interact_cursor: Option<CursorIcon>,
}
impl Visuals {
@ -806,6 +815,8 @@ impl Visuals {
striped: false,
slider_trailing_fill: false,
interact_cursor: None,
}
}
@ -1376,6 +1387,7 @@ impl Visuals {
striped,
slider_trailing_fill,
interact_cursor,
} = self;
ui.collapsing("Background Colors", |ui| {
@ -1441,6 +1453,16 @@ impl Visuals {
ui.checkbox(slider_trailing_fill, "Add trailing color to sliders");
ComboBox::from_label("Interact Cursor")
.selected_text(format!("{interact_cursor:?}"))
.show_ui(ui, |ui| {
ui.selectable_value(interact_cursor, None, "None");
for icon in CursorIcon::ALL {
ui.selectable_value(interact_cursor, Some(icon), format!("{icon:?}"));
}
});
ui.vertical_centered(|ui| reset_button(ui, self));
}
}

View File

@ -238,6 +238,12 @@ impl Widget for Button {
}
}
if let Some(cursor) = ui.visuals().interact_cursor {
if response.hovered {
ui.ctx().set_cursor_icon(cursor);
}
}
response
}
}