fix(context_menu): pass through the content's overlays, cursor and drop targets
This commit is contained in:
parent
9f634b0ec2
commit
521f3c2baf
1 changed files with 80 additions and 34 deletions
|
|
@ -342,6 +342,38 @@ impl<Message: 'static + Clone> Widget<Message, crate::Theme, crate::Renderer>
|
|||
);
|
||||
}
|
||||
|
||||
fn mouse_interaction(
|
||||
&self,
|
||||
tree: &Tree,
|
||||
layout: iced_core::Layout<'_>,
|
||||
cursor: iced_core::mouse::Cursor,
|
||||
viewport: &iced::Rectangle,
|
||||
renderer: &crate::Renderer,
|
||||
) -> mouse::Interaction {
|
||||
self.content.as_widget().mouse_interaction(
|
||||
&tree.children[0],
|
||||
layout,
|
||||
cursor,
|
||||
viewport,
|
||||
renderer,
|
||||
)
|
||||
}
|
||||
|
||||
fn drag_destinations(
|
||||
&self,
|
||||
tree: &Tree,
|
||||
layout: iced_core::Layout<'_>,
|
||||
renderer: &crate::Renderer,
|
||||
dnd_rectangles: &mut iced_core::clipboard::DndDestinationRectangles,
|
||||
) {
|
||||
self.content.as_widget().drag_destinations(
|
||||
&tree.children[0],
|
||||
layout,
|
||||
renderer,
|
||||
dnd_rectangles,
|
||||
);
|
||||
}
|
||||
|
||||
fn operate(
|
||||
&mut self,
|
||||
tree: &mut Tree,
|
||||
|
|
@ -506,31 +538,39 @@ impl<Message: 'static + Clone> Widget<Message, crate::Theme, crate::Renderer>
|
|||
fn overlay<'b>(
|
||||
&'b mut self,
|
||||
tree: &'b mut Tree,
|
||||
layout: iced_core::Layout<'_>,
|
||||
_renderer: &crate::Renderer,
|
||||
_viewport: &iced::Rectangle,
|
||||
layout: iced_core::Layout<'b>,
|
||||
renderer: &crate::Renderer,
|
||||
viewport: &iced::Rectangle,
|
||||
translation: Vector,
|
||||
) -> Option<iced_core::overlay::Element<'b, Message, crate::Theme, crate::Renderer>> {
|
||||
// The wrapped content's overlays (tooltips, dropdowns, ...) always pass through
|
||||
let content = self.content.as_widget_mut().overlay(
|
||||
&mut tree.children[0],
|
||||
layout,
|
||||
renderer,
|
||||
viewport,
|
||||
translation,
|
||||
);
|
||||
|
||||
#[cfg(wayland_platform)]
|
||||
if matches!(WINDOWING_SYSTEM.get(), Some(WindowingSystem::Wayland))
|
||||
&& self.window_id != window::Id::NONE
|
||||
&& self.on_surface_action.is_some()
|
||||
{
|
||||
return None;
|
||||
return content;
|
||||
}
|
||||
|
||||
let state = tree.state.downcast_ref::<LocalState>();
|
||||
|
||||
let context_menu = self.context_menu.as_mut()?;
|
||||
|
||||
let Some(context_menu) = self.context_menu.as_mut() else {
|
||||
return content;
|
||||
};
|
||||
if !state.menu_bar_state.inner.with_data(|state| state.open) {
|
||||
return None;
|
||||
return content;
|
||||
}
|
||||
|
||||
// Anchor the menu to a 1x1 rectangle at the click, like the popup path does
|
||||
let bounds = iced::Rectangle::new(state.context_cursor, Size::new(1.0, 1.0));
|
||||
Some(
|
||||
crate::widget::menu::Menu {
|
||||
let menu = crate::widget::menu::Menu {
|
||||
tree: state.menu_bar_state.clone(),
|
||||
menu_roots: std::borrow::Cow::Owned(context_menu.clone()),
|
||||
bounds_expand: 16,
|
||||
|
|
@ -554,8 +594,14 @@ impl<Message: 'static + Clone> Widget<Message, crate::Theme, crate::Renderer>
|
|||
depth: 0,
|
||||
on_surface_action: None,
|
||||
}
|
||||
.overlay(),
|
||||
)
|
||||
.overlay();
|
||||
|
||||
Some(match content {
|
||||
Some(content) => {
|
||||
iced_core::overlay::Group::with_children(vec![content, menu]).overlay()
|
||||
}
|
||||
None => menu,
|
||||
})
|
||||
}
|
||||
|
||||
#[cfg(feature = "a11y")]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue