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:
parent
2338a854f9
commit
523aa6b8ba
|
|
@ -2,7 +2,9 @@
|
||||||
|
|
||||||
#![allow(clippy::if_same_then_else)]
|
#![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 epaint::{Rounding, Shadow, Stroke};
|
||||||
use std::collections::BTreeMap;
|
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`].
|
/// Enabling this will affect ALL sliders, and can be enabled/disabled per slider with [`Slider::trailing_fill`].
|
||||||
pub slider_trailing_fill: bool,
|
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 {
|
impl Visuals {
|
||||||
|
|
@ -806,6 +815,8 @@ impl Visuals {
|
||||||
striped: false,
|
striped: false,
|
||||||
|
|
||||||
slider_trailing_fill: false,
|
slider_trailing_fill: false,
|
||||||
|
|
||||||
|
interact_cursor: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1376,6 +1387,7 @@ impl Visuals {
|
||||||
striped,
|
striped,
|
||||||
|
|
||||||
slider_trailing_fill,
|
slider_trailing_fill,
|
||||||
|
interact_cursor,
|
||||||
} = self;
|
} = self;
|
||||||
|
|
||||||
ui.collapsing("Background Colors", |ui| {
|
ui.collapsing("Background Colors", |ui| {
|
||||||
|
|
@ -1441,6 +1453,16 @@ impl Visuals {
|
||||||
|
|
||||||
ui.checkbox(slider_trailing_fill, "Add trailing color to sliders");
|
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));
|
ui.vertical_centered(|ui| reset_button(ui, self));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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
|
response
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue