feat(segmented_button): add scrollable_focus to toggle focus scrolling

This commit is contained in:
Michael Aaron Murphy 2024-02-12 17:44:21 +01:00
parent 072a3d5ca0
commit a11cf79b46
No known key found for this signature in database
GPG key ID: B2732D4240C9212C

View file

@ -63,6 +63,8 @@ where
pub(super) id: Option<Id>, pub(super) id: Option<Id>,
/// The icon used for the close button. /// The icon used for the close button.
pub(super) close_icon: Icon, pub(super) close_icon: Icon,
/// Scrolling switches focus between tabs.
pub(super) scrollable_focus: bool,
/// Show the close icon only when item is hovered. /// Show the close icon only when item is hovered.
pub(super) show_close_icon_on_hover: bool, pub(super) show_close_icon_on_hover: bool,
/// Padding around a button. /// Padding around a button.
@ -115,6 +117,7 @@ where
model, model,
id: None, id: None,
close_icon: icon::from_name("window-close-symbolic").size(16).icon(), close_icon: icon::from_name("window-close-symbolic").size(16).icon(),
scrollable_focus: false,
show_close_icon_on_hover: false, show_close_icon_on_hover: false,
button_padding: [4, 4, 4, 4], button_padding: [4, 4, 4, 4],
button_height: 32, button_height: 32,
@ -541,6 +544,7 @@ where
} }
} }
if self.scrollable_focus {
if let Some(on_activate) = self.on_activate.as_ref() { if let Some(on_activate) = self.on_activate.as_ref() {
if let Event::Mouse(mouse::Event::WheelScrolled { delta }) = event { if let Event::Mouse(mouse::Event::WheelScrolled { delta }) = event {
let current = Instant::now(); let current = Instant::now();
@ -594,6 +598,7 @@ where
} else { } else {
state.hovered = Item::None; state.hovered = Item::None;
} }
}
if state.focused { if state.focused {
if let Event::Keyboard(keyboard::Event::KeyPressed { if let Event::Keyboard(keyboard::Event::KeyPressed {