fix: capture mouse motion and mouse interactions in overlay

This commit is contained in:
Ashley Wulber 2026-03-05 15:38:28 -05:00 committed by Michael Murphy
parent 1810bedfa5
commit 1970499459
4 changed files with 417 additions and 407 deletions

View file

@ -135,7 +135,7 @@ impl<'a, S: AsRef<str>, Message: 'a, Item: Clone + PartialEq + 'static>
self.on_selected.as_ref(),
self.selections,
|| tree.state.downcast_mut::<State<Item>>(),
)
);
}
fn mouse_interaction(

View file

@ -585,9 +585,9 @@ impl<'b, Message: Clone + 'static> Menu<'b, Message> {
Cow::Borrowed(_) => panic!(),
Cow::Owned(o) => o.as_mut_slice(),
};
let menu_status = process_menu_events(
process_menu_events(
self,
&event,
event,
view_cursor,
renderer,
clipboard,
@ -629,8 +629,7 @@ impl<'b, Message: Clone + 'static> Menu<'b, Message> {
if !self.is_overlay && !view_cursor.is_over(viewport) {
return None;
}
let (new_root, status) = process_overlay_events(
let new_root = process_overlay_events(
self,
renderer,
viewport_size,
@ -641,6 +640,10 @@ impl<'b, Message: Clone + 'static> Menu<'b, Message> {
shell,
);
if self.is_overlay && view_cursor.is_over(viewport) {
shell.capture_event();
}
return new_root;
}
@ -680,24 +683,23 @@ impl<'b, Message: Clone + 'static> Menu<'b, Message> {
feature = "winit",
feature = "surface-message"
))]
if matches!(WINDOWING_SYSTEM.get(), Some(WindowingSystem::Wayland)) {
if let Some(handler) = self.on_surface_action.as_ref() {
let mut root = self.window_id;
let mut depth = self.depth;
while let Some(parent) =
state.popup_id.iter().find(|(_, v)| **v == root)
{
// parent of root popup is the window, so we stop.
if depth == 0 {
break;
}
root = *parent.0;
depth = depth.saturating_sub(1);
if matches!(WINDOWING_SYSTEM.get(), Some(WindowingSystem::Wayland))
&& let Some(handler) = self.on_surface_action.as_ref()
{
let mut root = self.window_id;
let mut depth = self.depth;
while let Some(parent) =
state.popup_id.iter().find(|(_, v)| **v == root)
{
// parent of root popup is the window, so we stop.
if depth == 0 {
break;
}
shell.publish((handler)(crate::surface::Action::DestroyPopup(
root,
)));
root = *parent.0;
depth = depth.saturating_sub(1);
}
shell
.publish((handler)(crate::surface::Action::DestroyPopup(root)));
}
state.reset();
@ -708,7 +710,7 @@ impl<'b, Message: Clone + 'static> Menu<'b, Message> {
if self.bar_bounds.contains(overlay_cursor) {
state.reset();
}
})
});
}
_ => {}
@ -804,26 +806,25 @@ impl<'b, Message: Clone + 'static> Menu<'b, Message> {
let menu_color = styling.background;
r.fill_quad(menu_quad, menu_color);
// draw path hightlight
if let (true, Some(active)) = (draw_path, ms.index) {
if let Some(active_layout) = children_layout
if let (true, Some(active)) = (draw_path, ms.index)
&& let Some(active_layout) = children_layout
.children()
.nth(active.saturating_sub(start_index))
{
let path_quad = renderer::Quad {
bounds: active_layout
.bounds()
.intersection(&viewport)
.unwrap_or_default(),
border: Border {
radius: styling.menu_border_radius.into(),
..Default::default()
},
shadow: Shadow::default(),
snap: true,
};
{
let path_quad = renderer::Quad {
bounds: active_layout
.bounds()
.intersection(&viewport)
.unwrap_or_default(),
border: Border {
radius: styling.menu_border_radius.into(),
..Default::default()
},
shadow: Shadow::default(),
snap: true,
};
r.fill_quad(path_quad, styling.path);
}
r.fill_quad(path_quad, styling.path);
}
if start_index < menu_roots.len() {
// draw item
@ -894,6 +895,19 @@ impl<Message: Clone + 'static> overlay::Overlay<Message, crate::Theme, crate::Re
) {
self.draw(renderer, theme, style, layout, cursor);
}
fn mouse_interaction(
&self,
layout: Layout<'_>,
cursor: mouse::Cursor,
_renderer: &crate::Renderer,
) -> mouse::Interaction {
if cursor.is_over(layout.bounds()) {
mouse::Interaction::Idle
} else {
mouse::Interaction::None
}
}
}
impl<Message: std::clone::Clone + 'static> Widget<Message, crate::Theme, crate::Renderer>
@ -948,73 +962,74 @@ impl<Message: std::clone::Clone + 'static> Widget<Message, crate::Theme, crate::
feature = "winit",
feature = "surface-message"
))]
if matches!(WINDOWING_SYSTEM.get(), Some(WindowingSystem::Wayland)) {
if let Some((new_root, new_ms)) = new_root {
use iced_runtime::platform_specific::wayland::popup::{
SctkPopupSettings, SctkPositioner,
if matches!(WINDOWING_SYSTEM.get(), Some(WindowingSystem::Wayland))
&& let Some((new_root, new_ms)) = new_root
{
use iced_runtime::platform_specific::wayland::popup::{
SctkPopupSettings, SctkPositioner,
};
let overlay_offset = Point::ORIGIN - viewport.position();
let overlay_cursor = cursor.position().unwrap_or_default() - overlay_offset;
let Some((mut menu, popup_id)) = self.tree.inner.with_data_mut(|state| {
let popup_id = *state
.popup_id
.entry(self.window_id)
.or_insert_with(window::Id::unique);
let active_roots = state
.active_root
.get(self.depth)
.cloned()
.unwrap_or_default();
let root_bounds_list = layout
.children()
.next()
.unwrap()
.children()
.map(|lo| lo.bounds())
.collect();
let mut popup_menu = Menu {
tree: self.tree.clone(),
menu_roots: Cow::Owned(Cow::into_owned(self.menu_roots.clone())),
bounds_expand: self.bounds_expand,
menu_overlays_parent: false,
close_condition: self.close_condition,
item_width: self.item_width,
item_height: self.item_height,
bar_bounds: layout.bounds(),
main_offset: self.main_offset,
cross_offset: self.cross_offset,
root_bounds_list,
path_highlight: self.path_highlight,
style: Cow::Owned(Cow::into_owned(self.style.clone())),
position: Point::new(0., 0.),
is_overlay: false,
window_id: popup_id,
depth: self.depth + 1,
on_surface_action: self.on_surface_action.clone(),
};
let overlay_offset = Point::ORIGIN - viewport.position();
let overlay_cursor = cursor.position().unwrap_or_default() - overlay_offset;
state.active_root.push(new_root);
let Some((mut menu, popup_id)) = self.tree.inner.with_data_mut(|state| {
let popup_id = *state
.popup_id
.entry(self.window_id)
.or_insert_with(window::Id::unique);
let active_roots = state
.active_root
.get(self.depth)
.cloned()
.unwrap_or_default();
let root_bounds_list = layout
.children()
.next()
.unwrap()
.children()
.map(|lo| lo.bounds())
.collect();
let mut popup_menu = Menu {
tree: self.tree.clone(),
menu_roots: Cow::Owned(Cow::into_owned(self.menu_roots.clone())),
bounds_expand: self.bounds_expand,
menu_overlays_parent: false,
close_condition: self.close_condition,
item_width: self.item_width,
item_height: self.item_height,
bar_bounds: layout.bounds(),
main_offset: self.main_offset,
cross_offset: self.cross_offset,
root_bounds_list,
path_highlight: self.path_highlight,
style: Cow::Owned(Cow::into_owned(self.style.clone())),
position: Point::new(0., 0.),
is_overlay: false,
window_id: popup_id,
depth: self.depth + 1,
on_surface_action: self.on_surface_action.clone(),
};
state.active_root.push(new_root);
Some((popup_menu, popup_id))
}) else {
return;
};
// XXX we push a new active root manually instead
init_root_popup_menu(
&mut menu,
renderer,
shell,
cursor.position().unwrap_or_default(),
layout.bounds().size(),
Vector::new(0., 0.),
layout.bounds(),
self.main_offset as f32,
);
let (anchor_rect, gravity) = self.tree.inner.with_data_mut(|state| {
Some((popup_menu, popup_id))
}) else {
return;
};
// XXX we push a new active root manually instead
init_root_popup_menu(
&mut menu,
renderer,
shell,
cursor.position().unwrap_or_default(),
layout.bounds().size(),
Vector::new(0., 0.),
layout.bounds(),
self.main_offset as f32,
);
let (anchor_rect, gravity) = self.tree.inner.with_data_mut(|state| {
(state
.menu_states
.get(self.depth + 1)
@ -1043,51 +1058,63 @@ impl<Message: std::clone::Clone + 'static> Widget<Message, crate::Theme, crate::
})
});
let menu_node = Widget::layout(
&mut menu,
&mut Tree::empty(),
renderer,
&Limits::NONE.min_width(1.).min_height(1.),
);
let menu_node = Widget::layout(
&mut menu,
&mut Tree::empty(),
renderer,
&Limits::NONE.min_width(1.).min_height(1.),
);
let popup_size = menu_node.size();
let mut positioner = SctkPositioner {
size: Some((
popup_size.width.ceil() as u32 + 2,
popup_size.height.ceil() as u32 + 2,
)),
anchor_rect,
anchor:
cctk::wayland_protocols::xdg::shell::client::xdg_positioner::Anchor::TopRight,
gravity,
reactive: true,
..Default::default()
};
// disable slide_x if it is set in the default
positioner.constraint_adjustment &= !(1 << 0);
let parent = self.window_id;
shell.publish((self.on_surface_action.as_ref().unwrap())(
crate::surface::action::simple_popup(
move || SctkPopupSettings {
parent,
id: popup_id,
positioner: positioner.clone(),
parent_size: None,
grab: true,
close_with_children: false,
input_zone: None,
},
Some(move || {
crate::Element::from(
crate::widget::container(menu.clone()).center(Length::Fill),
)
.map(crate::action::app)
}),
),
));
let popup_size = menu_node.size();
let mut positioner = SctkPositioner {
size: Some((
popup_size.width.ceil() as u32 + 2,
popup_size.height.ceil() as u32 + 2,
)),
anchor_rect,
anchor:
cctk::wayland_protocols::xdg::shell::client::xdg_positioner::Anchor::TopRight,
gravity,
reactive: true,
..Default::default()
};
// disable slide_x if it is set in the default
positioner.constraint_adjustment &= !(1 << 0);
let parent = self.window_id;
shell.publish((self.on_surface_action.as_ref().unwrap())(
crate::surface::action::simple_popup(
move || SctkPopupSettings {
parent,
id: popup_id,
positioner: positioner.clone(),
parent_size: None,
grab: true,
close_with_children: false,
input_zone: None,
},
Some(move || {
crate::Element::from(
crate::widget::container(menu.clone()).center(Length::Fill),
)
.map(crate::action::app)
}),
),
));
}
}
return;
}
fn mouse_interaction(
&self,
_tree: &Tree,
layout: Layout<'_>,
cursor: mouse::Cursor,
_viewport: &Rectangle,
_renderer: &crate::Renderer,
) -> mouse::Interaction {
if cursor.is_over(layout.bounds()) {
mouse::Interaction::Idle
} else {
mouse::Interaction::None
}
}
}
@ -1331,7 +1358,7 @@ fn process_menu_events<Message: std::clone::Clone>(
shell,
&Rectangle::default(),
);
})
});
}
#[allow(unused_results, clippy::too_many_lines, clippy::too_many_arguments)]
@ -1343,12 +1370,11 @@ fn process_overlay_events<Message>(
view_cursor: Cursor,
overlay_cursor: Point,
cross_offset: f32,
_shell: &mut Shell<'_, Message>,
) -> (Option<(usize, MenuState)>, event::Status)
shell: &mut Shell<'_, Message>,
) -> Option<(usize, MenuState)>
where
Message: std::clone::Clone,
{
use event::Status::{Captured, Ignored};
/*
if no active root || pressed:
return
@ -1431,8 +1457,8 @@ where
state.open = false;
}
}
return (new_menu_root, Captured);
shell.capture_event();
return new_menu_root;
};
let last_menu_bounds = &last_menu_state.menu_bounds;
@ -1446,7 +1472,8 @@ where
{
last_menu_state.index = None;
return (new_menu_root, Captured);
shell.capture_event();
return new_menu_root;
}
// calc new index
@ -1461,7 +1488,7 @@ where
};
if state.pressed {
return (new_menu_root, Ignored);
return new_menu_root;
}
let roots = active_root.iter().skip(1).fold(
&menu.menu_roots[active_root[0]].children,
@ -1494,7 +1521,7 @@ where
if matches!(WINDOWING_SYSTEM.get(), Some(WindowingSystem::Wayland)) && remove {
if let Some(id) = state.popup_id.remove(&menu.window_id) {
state.active_root.truncate(menu.depth + 1);
_shell.publish((menu.on_surface_action.as_ref().unwrap())({
shell.publish((menu.on_surface_action.as_ref().unwrap())({
crate::surface::action::destroy_popup(id)
}));
}
@ -1555,7 +1582,8 @@ where
state.menu_states.truncate(menu.depth + 1);
}
(new_menu_root, Captured)
shell.capture_event();
new_menu_root
})
}

View file

@ -20,7 +20,7 @@ use iced::clipboard::mime::AllowedMimeTypes;
use iced::touch::Finger;
use iced::{
Alignment, Background, Color, Event, Length, Padding, Rectangle, Size, Task, Vector, alignment,
event, keyboard, mouse, touch, window,
keyboard, mouse, touch, window,
};
use iced_core::mouse::ScrollDelta;
use iced_core::text::{self, Ellipsize, LineHeight, Renderer as TextRenderer, Shaping, Wrapping};
@ -36,7 +36,6 @@ use std::collections::HashSet;
use std::collections::hash_map::DefaultHasher;
use std::hash::{Hash, Hasher};
use std::marker::PhantomData;
use std::mem;
use std::time::{Duration, Instant};
thread_local! {
@ -609,27 +608,26 @@ where
.text
.get(button)
.zip(state.paragraphs.entry(button))
&& !text.is_empty()
{
if !text.is_empty() {
icon_spacing = f32::from(self.button_spacing);
let paragraph = entry.or_insert_with(|| {
crate::Plain::new(Text {
content: text.to_string(), // TODO should we just use String at this point?
size: iced::Pixels(self.font_size),
bounds: Size::INFINITE,
font,
align_x: text::Alignment::Left,
align_y: alignment::Vertical::Center,
shaping: Shaping::Advanced,
wrapping: Wrapping::default(),
ellipsize: Ellipsize::default(),
line_height: self.line_height,
})
});
icon_spacing = f32::from(self.button_spacing);
let paragraph = entry.or_insert_with(|| {
crate::Plain::new(Text {
content: text.to_string(), // TODO should we just use String at this point?
size: iced::Pixels(self.font_size),
bounds: Size::INFINITE,
font,
align_x: text::Alignment::Left,
align_y: alignment::Vertical::Center,
shaping: Shaping::Advanced,
wrapping: Wrapping::default(),
ellipsize: Ellipsize::default(),
line_height: self.line_height,
})
});
let size = paragraph.min_bounds();
width += size.width;
}
let size = paragraph.min_bounds();
width += size.width;
}
// Add indent to measurement if found.
@ -895,10 +893,10 @@ where
}
// Unfocus if another segmented control was focused.
if let Some(f) = state.focused.as_ref() {
if f.updated_at != LAST_FOCUS_UPDATE.with(|f| f.get()) {
state.unfocus();
}
if let Some(f) = state.focused.as_ref()
&& f.updated_at != LAST_FOCUS_UPDATE.with(|f| f.get())
{
state.unfocus();
}
}
@ -1162,6 +1160,9 @@ where
None::<fn(_, _) -> Message>,
on_drop,
);
if matches!(ret, iced::event::Status::Captured) {
shell.capture_event();
}
if let Some(msg) = maybe_msg {
log::trace!(
target: TAB_REORDER_LOG_TARGET,
@ -1200,9 +1201,8 @@ where
}
Event::Touch(touch::Event::FingerLifted { id, .. }) => {
state.fingers_pressed.remove(&id);
state.fingers_pressed.remove(id);
}
_ => (),
}
@ -1301,27 +1301,26 @@ where
Event::Mouse(mouse::Event::ButtonPressed(mouse::Button::Left))
)
&& !over_close_button
&& let Some(position) = cursor_position.position()
{
if let Some(position) = cursor_position.position() {
state.tab_drag_candidate = Some(TabDragCandidate {
entity: key,
bounds,
origin: position,
});
if let Some(tab_drag) = self.tab_drag.as_ref() {
log::trace!(
target: TAB_REORDER_LOG_TARGET,
"tab drag candidate entity={:?} origin=({:.2},{:.2}) bounds=({:.2},{:.2},{:.2},{:.2}) threshold={}",
key,
position.x,
position.y,
bounds.x,
bounds.y,
bounds.width,
bounds.height,
tab_drag.threshold
);
}
state.tab_drag_candidate = Some(TabDragCandidate {
entity: key,
bounds,
origin: position,
});
if let Some(tab_drag) = self.tab_drag.as_ref() {
log::trace!(
target: TAB_REORDER_LOG_TARGET,
"tab drag candidate entity={:?} origin=({:.2},{:.2}) bounds=({:.2},{:.2},{:.2},{:.2}) threshold={}",
key,
position.x,
position.y,
bounds.x,
bounds.y,
bounds.width,
bounds.height,
tab_drag.threshold
);
}
}
@ -1330,40 +1329,35 @@ where
}
if let Some(on_activate) = self.on_activate.as_ref() {
if is_pressed(&event) {
if is_pressed(event) {
state.pressed_item = Some(Item::Tab(key));
} else if is_lifted(&event) {
if self.button_is_pressed(state, key) {
shell.publish(on_activate(key));
state.set_focused();
state.focused_item = Item::Tab(key);
state.pressed_item = None;
shell.capture_event();
return;
}
} else if is_lifted(&event) && self.button_is_pressed(state, key) {
shell.publish(on_activate(key));
state.set_focused();
state.focused_item = Item::Tab(key);
state.pressed_item = None;
shell.capture_event();
return;
}
}
// Present a context menu on a right click event.
if self.context_menu.is_some() {
if let Some(on_context) = self.on_context.as_ref() {
if right_button_released(&event)
|| (touch_lifted(&event) && fingers_pressed == 2)
{
state.show_context = Some(key);
state.context_cursor =
cursor_position.position().unwrap_or_default();
if self.context_menu.is_some()
&& let Some(on_context) = self.on_context.as_ref()
&& (right_button_released(&event)
|| (touch_lifted(&event) && fingers_pressed == 2))
{
state.show_context = Some(key);
state.context_cursor = cursor_position.position().unwrap_or_default();
state.menu_state.inner.with_data_mut(|data| {
data.open = true;
data.view_cursor = cursor_position;
});
state.menu_state.inner.with_data_mut(|data| {
data.open = true;
data.view_cursor = cursor_position;
});
shell.publish(on_context(key));
shell.capture_event();
return;
}
}
shell.publish(on_context(key));
shell.capture_event();
return;
}
if let Event::Mouse(mouse::Event::ButtonPressed(mouse::Button::Middle)) =
@ -1385,57 +1379,56 @@ where
}
}
if self.scrollable_focus {
if let Some(on_activate) = self.on_activate.as_ref() {
if let Event::Mouse(mouse::Event::WheelScrolled { delta }) = event {
let current = Instant::now();
if self.scrollable_focus
&& let Some(on_activate) = self.on_activate.as_ref()
&& let Event::Mouse(mouse::Event::WheelScrolled { delta }) = event
{
let current = Instant::now();
// Permit successive scroll wheel events only after a given delay.
if state.wheel_timestamp.is_none_or(|previous| {
current.duration_since(previous) > Duration::from_millis(250)
}) {
state.wheel_timestamp = Some(current);
// Permit successive scroll wheel events only after a given delay.
if state.wheel_timestamp.is_none_or(|previous| {
current.duration_since(previous) > Duration::from_millis(250)
}) {
state.wheel_timestamp = Some(current);
match delta {
ScrollDelta::Lines { y, .. } | ScrollDelta::Pixels { y, .. } => {
let mut activate_key = None;
match delta {
ScrollDelta::Lines { y, .. } | ScrollDelta::Pixels { y, .. } => {
let mut activate_key = None;
if *y < 0.0 {
let mut prev_key = Entity::null();
if *y < 0.0 {
let mut prev_key = Entity::null();
for key in self.model.order.iter().copied() {
if self.model.is_active(key) && !prev_key.is_null() {
activate_key = Some(prev_key);
}
for key in self.model.order.iter().copied() {
if self.model.is_active(key) && !prev_key.is_null() {
activate_key = Some(prev_key);
}
if self.model.is_enabled(key) {
prev_key = key;
}
}
} else if *y > 0.0 {
let mut buttons = self.model.order.iter().copied();
while let Some(key) = buttons.next() {
if self.model.is_active(key) {
for key in buttons {
if self.model.is_enabled(key) {
prev_key = key;
}
}
} else if *y > 0.0 {
let mut buttons = self.model.order.iter().copied();
while let Some(key) = buttons.next() {
if self.model.is_active(key) {
for key in buttons {
if self.model.is_enabled(key) {
activate_key = Some(key);
break;
}
}
activate_key = Some(key);
break;
}
}
}
if let Some(key) = activate_key {
shell.publish(on_activate(key));
state.set_focused();
state.focused_item = Item::Tab(key);
shell.capture_event();
return;
break;
}
}
}
if let Some(key) = activate_key {
shell.publish(on_activate(key));
state.set_focused();
state.focused_item = Item::Tab(key);
shell.capture_event();
return;
}
}
}
}
@ -1460,31 +1453,27 @@ where
if let (Some(tab_drag), Some(candidate)) =
(self.tab_drag.as_ref(), state.tab_drag_candidate)
&& let Event::Mouse(mouse::Event::CursorMoved { .. }) = event
&& let Some(position) = cursor_position.position()
&& position.distance(candidate.origin) >= tab_drag.threshold
&& let Some(candidate) = state.tab_drag_candidate.take()
{
if let Event::Mouse(mouse::Event::CursorMoved { .. }) = event {
if let Some(position) = cursor_position.position() {
if position.distance(candidate.origin) >= tab_drag.threshold {
if let Some(candidate) = state.tab_drag_candidate.take() {
log::trace!(
target: TAB_REORDER_LOG_TARGET,
"tab drag threshold met entity={:?} distance={:.2} threshold={}",
candidate.entity,
position.distance(candidate.origin),
tab_drag.threshold
);
if self.start_tab_drag(
state,
candidate.entity,
candidate.bounds,
position,
clipboard,
) {
shell.capture_event();
return;
}
}
}
}
log::trace!(
target: TAB_REORDER_LOG_TARGET,
"tab drag threshold met entity={:?} distance={:.2} threshold={}",
candidate.entity,
position.distance(candidate.origin),
tab_drag.threshold
);
if self.start_tab_drag(
state,
candidate.entity,
candidate.bounds,
position,
clipboard,
) {
shell.capture_event();
return;
}
}
@ -1504,55 +1493,53 @@ where
{
state.focused_visible = true;
return if *modifiers == keyboard::Modifiers::SHIFT {
self.focus_previous(state, shell)
self.focus_previous(state, shell);
} else if modifiers.is_empty() {
self.focus_next(state, shell)
self.focus_next(state, shell);
};
}
if let Some(on_activate) = self.on_activate.as_ref() {
if let Event::Keyboard(keyboard::Event::KeyReleased {
if let Some(on_activate) = self.on_activate.as_ref()
&& let Event::Keyboard(keyboard::Event::KeyReleased {
key: keyboard::Key::Named(keyboard::key::Named::Enter),
..
}) = event
{
match state.focused_item {
Item::Tab(entity) => {
shell.publish(on_activate(entity));
}
Item::PrevButton => {
if self.prev_tab_sensitive(state) {
state.buttons_offset -= 1;
// If the change would cause it to be insensitive, focus the first tab.
if !self.prev_tab_sensitive(state) {
if let Some(first) = self.first_tab(state) {
state.focused_item = Item::Tab(first);
}
}
}
}
Item::NextButton => {
if self.next_tab_sensitive(state) {
state.buttons_offset += 1;
// If the change would cause it to be insensitive, focus the last tab.
if !self.next_tab_sensitive(state) {
if let Some(last) = self.last_tab(state) {
state.focused_item = Item::Tab(last);
}
}
}
}
Item::None | Item::Set => (),
{
match state.focused_item {
Item::Tab(entity) => {
shell.publish(on_activate(entity));
}
shell.capture_event();
return;
Item::PrevButton => {
if self.prev_tab_sensitive(state) {
state.buttons_offset -= 1;
// If the change would cause it to be insensitive, focus the first tab.
if !self.prev_tab_sensitive(state)
&& let Some(first) = self.first_tab(state)
{
state.focused_item = Item::Tab(first);
}
}
}
Item::NextButton => {
if self.next_tab_sensitive(state) {
state.buttons_offset += 1;
// If the change would cause it to be insensitive, focus the last tab.
if !self.next_tab_sensitive(state)
&& let Some(last) = self.last_tab(state)
{
state.focused_item = Item::Tab(last);
}
}
}
Item::None | Item::Set => (),
}
shell.capture_event();
}
}
}
@ -1794,22 +1781,22 @@ where
let original_bounds = bounds;
let center_y = bounds.center_y();
if show_drop_hint_marker {
if matches!(
if show_drop_hint_marker
&& matches!(
drop_hint_marker,
Some(DropHint {
entity,
side: DropSide::Before
}) if entity == key
) {
draw_drop_indicator(
renderer,
original_bounds,
DropSide::Before,
Self::VERTICAL,
appearance.active.text_color,
);
}
)
{
draw_drop_indicator(
renderer,
original_bounds,
DropSide::Before,
Self::VERTICAL,
appearance.active.text_color,
);
}
let menu_open = || {
@ -1882,41 +1869,41 @@ where
let mut indent_padding = 0.0;
// Adjust bounds by indent
if let Some(indent) = self.model.indent(key) {
if indent > 0 {
let adjustment = f32::from(indent) * f32::from(self.indent_spacing);
bounds.x += adjustment;
bounds.width -= adjustment;
if let Some(indent) = self.model.indent(key)
&& indent > 0
{
let adjustment = f32::from(indent) * f32::from(self.indent_spacing);
bounds.x += adjustment;
bounds.width -= adjustment;
// Draw indent line
if let crate::theme::SegmentedButton::FileNav = self.style {
if indent > 1 {
indent_padding = 7.0;
// Draw indent line
if let crate::theme::SegmentedButton::FileNav = self.style
&& indent > 1
{
indent_padding = 7.0;
for level in 1..indent {
renderer.fill_quad(
renderer::Quad {
bounds: Rectangle {
x: (level as f32)
.mul_add(-(self.indent_spacing as f32), bounds.x)
+ indent_padding,
width: 1.0,
..bounds
},
border: Border {
radius: rad_0.into(),
..Default::default()
},
shadow: Shadow::default(),
snap: true,
},
divider_background,
);
}
indent_padding += 4.0;
}
for level in 1..indent {
renderer.fill_quad(
renderer::Quad {
bounds: Rectangle {
x: (level as f32)
.mul_add(-(self.indent_spacing as f32), bounds.x)
+ indent_padding,
width: 1.0,
..bounds
},
border: Border {
radius: rad_0.into(),
..Default::default()
},
shadow: Shadow::default(),
snap: true,
},
divider_background,
);
}
indent_padding += 4.0;
}
}
@ -1990,40 +1977,35 @@ where
bounds.x += offset;
} else {
// Draw the selection indicator if widget is a segmented selection, and the item is selected.
if key_is_active {
if let crate::theme::SegmentedButton::Control = self.style {
let mut image_bounds = bounds;
image_bounds.y = center_y - 8.0;
if key_is_active && let crate::theme::SegmentedButton::Control = self.style {
let mut image_bounds = bounds;
image_bounds.y = center_y - 8.0;
draw_icon::<Message>(
renderer,
theme,
style,
cursor,
viewport,
status_appearance.text_color,
Rectangle {
width: 16.0,
height: 16.0,
..image_bounds
},
crate::widget::icon(
match crate::widget::common::object_select().data() {
crate::iced_core::svg::Data::Bytes(bytes) => {
crate::widget::icon::from_svg_bytes(bytes.as_ref())
.symbolic(true)
}
crate::iced_core::svg::Data::Path(path) => {
crate::widget::icon::from_path(path.clone())
}
},
),
);
draw_icon::<Message>(
renderer,
theme,
style,
cursor,
viewport,
status_appearance.text_color,
Rectangle {
width: 16.0,
height: 16.0,
..image_bounds
},
crate::widget::icon(match crate::widget::common::object_select().data() {
crate::iced_core::svg::Data::Bytes(bytes) => {
crate::widget::icon::from_svg_bytes(bytes.as_ref()).symbolic(true)
}
crate::iced_core::svg::Data::Path(path) => {
crate::widget::icon::from_path(path.clone())
}
}),
);
let offset = 16.0 + f32::from(self.button_spacing);
let offset = 16.0 + f32::from(self.button_spacing);
bounds.x += offset;
}
bounds.x += offset;
}
}

View file

@ -248,7 +248,7 @@ where
clipboard,
shell,
&layout.bounds(),
)
);
}
fn mouse_interaction(