Skip to content

Commit

Permalink
feat: change to PointingHand when hovering over a button (#3312)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
zkrising and emilk committed Sep 8, 2023
1 parent 2338a85 commit 523aa6b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
24 changes: 23 additions & 1 deletion crates/egui/src/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -806,6 +815,8 @@ impl Visuals {
striped: false,

slider_trailing_fill: false,

interact_cursor: None,
}
}

Expand Down Expand Up @@ -1376,6 +1387,7 @@ impl Visuals {
striped,

slider_trailing_fill,
interact_cursor,
} = self;

ui.collapsing("Background Colors", |ui| {
Expand Down Expand Up @@ -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));
}
}
Expand Down
6 changes: 6 additions & 0 deletions crates/egui/src/widgets/button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down

0 comments on commit 523aa6b

Please sign in to comment.