diff --git a/crates/egui/src/style.rs b/crates/egui/src/style.rs index 3c7da1b1..e7a2c76e 100644 --- a/crates/egui/src/style.rs +++ b/crates/egui/src/style.rs @@ -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, } 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)); } } diff --git a/crates/egui/src/widgets/button.rs b/crates/egui/src/widgets/button.rs index 932918ab..fd3f4ecc 100644 --- a/crates/egui/src/widgets/button.rs +++ b/crates/egui/src/widgets/button.rs @@ -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 } }