fix(dock): keep auto-hiding panels shown while the pointer is on their dropdowns

iced gives the layer under an overlay a levitating cursor, so the dock
edge's mouse_area read the pointer on any dropdown or combo list in a
pallet as leaving, and auto-hide collapsed the panel mid-pick. Track
enter/leave with a small hover_zone wrapper that lands the cursor before
its bounds test, on docked edges and floating pallets alike.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_014ihuqzxdUhd9UbioPn5MGu
This commit is contained in:
Claude committed 2026-10-15 18:30:37 +00:00
1 parent 33433b8924
commit c74dca4f32
4 files changed
+196 -15

No files matched your search

+6 -6
View File
@@ -207,12 +207,12 @@ impl OpenCADStudio {
Some(HoverPending::Hide)
if self.dock_peek.is_some_and(|id| self.dock.auto_hides(id)) =>
{
// A dropdown or the colour window opened from the
// panel draws as an overlay, which the edge's
// mouse area reads as the pointer leaving. Keep
// the panel out until it closes, so a pick can
// still land; then hide unless the pointer is
// back (its re-entry cancels this).
// The edge's hover zone keeps a dropdown inside
// it from reading as a leave; a colour popup can
// still reach past it (or be the Select Color
// window). Keep the panel out until it closes, so
// a pick can still land; then hide unless the
// pointer is back (its re-entry cancels this).
if self.dock_popup_open() {
return self.dock_hover_arm(HoverPending::Hide);
}
+14 -9
View File
@@ -164,12 +164,13 @@ impl OpenCADStudio {
children.push(strip);
}
}
Some(
mouse_area(row(children).height(Fill))
.on_enter(Message::Dock(crate::ui::dock::DockMsg::HoverStay))
.on_exit(Message::Dock(crate::ui::dock::DockMsg::HoverExit))
.into(),
)
// Not a `mouse_area`: the pointer on one of the pallet's own
// dropdowns must not read as leaving the edge.
Some(crate::ui::hover_zone::hover_zone(
row(children).height(Fill),
Message::Dock(crate::ui::dock::DockMsg::HoverStay),
Message::Dock(crate::ui::dock::DockMsg::HoverExit),
))
}
/// An edge's vertical icon strip: per group its open pallets' icons in a
@@ -555,10 +556,14 @@ impl OpenCADStudio {
// on its empty areas don't fall through to the drawing below.
let panel = mouse_area(framed)
.on_press(Message::Dock(DockMsg::FloatRaise(f.id)))
.on_enter(Message::Dock(DockMsg::Hover(f.id)))
.on_exit(Message::Dock(DockMsg::HoverExit))
.interaction(iced::mouse::Interaction::Idle);
place_at(panel.into(), x, y)
// Enter / leave as on a docked edge: its dropdowns keep it shown.
let panel = crate::ui::hover_zone::hover_zone(
panel,
Message::Dock(DockMsg::Hover(f.id)),
Message::Dock(DockMsg::HoverExit),
);
place_at(panel, x, y)
}
/// Where floating panel `f` draws.
+175
View File
@@ -0,0 +1,175 @@
//! A pointer-enter / leave area that keeps counting the pointer as inside
//! while it rests on an overlay (a dropdown, a combo box list) drawn over
//! its bounds.
//!
//! `mouse_area` reads such a pointer as gone: iced hands the layer below an
//! overlay a levitating cursor, which has no position. An auto-hiding dock
//! edge then hides as soon as one of its own dropdowns opens under the
//! pointer, taking the dropdown with it. Here the cursor is landed before the
//! bounds test, so only a pointer that really leaves the area exits it.
use iced::advanced::layout::{self, Layout};
use iced::advanced::widget::{self, tree, Tree, Widget};
use iced::advanced::{mouse, overlay, renderer, Shell};
use iced::{Element, Event, Length, Rectangle, Renderer, Size, Theme, Vector};
use crate::app::Message;
/// Wrap `content`, publishing `on_enter` / `on_exit` as the pointer enters
/// and leaves its bounds, overlays drawn over them included.
pub fn hover_zone<'a>(
content: impl Into<Element<'a, Message>>,
on_enter: Message,
on_exit: Message,
) -> Element<'a, Message> {
Element::new(HoverZone {
content: content.into(),
on_enter,
on_exit,
})
}
struct HoverZone<'a> {
content: Element<'a, Message>,
on_enter: Message,
on_exit: Message,
}
#[derive(Default)]
struct State {
hovered: bool,
}
impl Widget<Message, Theme, Renderer> for HoverZone<'_> {
fn tag(&self) -> tree::Tag {
tree::Tag::of::<State>()
}
fn state(&self) -> tree::State {
tree::State::new(State::default())
}
fn children(&self) -> Vec<Tree> {
vec![Tree::new(&self.content)]
}
fn diff(&mut self, tree: &mut Tree) {
tree.diff_children(std::slice::from_mut(&mut self.content));
}
fn size(&self) -> Size<Length> {
self.content.as_widget().size()
}
fn layout(
&mut self,
tree: &mut Tree,
renderer: &Renderer,
limits: &layout::Limits,
) -> layout::Node {
self.content
.as_widget_mut()
.layout(&mut tree.children[0], renderer, limits)
}
fn operate(
&mut self,
tree: &mut Tree,
layout: Layout<'_>,
renderer: &Renderer,
operation: &mut dyn widget::Operation,
) {
self.content
.as_widget_mut()
.operate(&mut tree.children[0], layout, renderer, operation);
}
fn update(
&mut self,
tree: &mut Tree,
event: &Event,
layout: Layout<'_>,
cursor: mouse::Cursor,
renderer: &Renderer,
shell: &mut Shell<'_, Message>,
viewport: &Rectangle,
) {
self.content.as_widget_mut().update(
&mut tree.children[0],
event,
layout,
cursor,
renderer,
shell,
viewport,
);
// Unlike `mouse_area`, this runs for captured events too: a pointer
// move over a dropdown is captured by the dropdown but must still
// not read as leaving.
let hovered = cursor.land().is_over(layout.bounds());
let state = tree.state.downcast_mut::<State>();
if hovered != state.hovered {
state.hovered = hovered;
shell.publish(if hovered {
self.on_enter.clone()
} else {
self.on_exit.clone()
});
}
}
fn mouse_interaction(
&self,
tree: &Tree,
layout: Layout<'_>,
cursor: mouse::Cursor,
viewport: &Rectangle,
renderer: &Renderer,
) -> mouse::Interaction {
self.content.as_widget().mouse_interaction(
&tree.children[0],
layout,
cursor,
viewport,
renderer,
)
}
fn draw(
&self,
tree: &Tree,
renderer: &mut Renderer,
theme: &Theme,
style: &renderer::Style,
layout: Layout<'_>,
cursor: mouse::Cursor,
viewport: &Rectangle,
) {
self.content.as_widget().draw(
&tree.children[0],
renderer,
theme,
style,
layout,
cursor,
viewport,
);
}
fn overlay<'b>(
&'b mut self,
tree: &'b mut Tree,
layout: Layout<'b>,
renderer: &Renderer,
viewport: &Rectangle,
translation: Vector,
) -> Option<overlay::Element<'b, Message, Theme, Renderer>> {
self.content.as_widget_mut().overlay(
&mut tree.children[0],
layout,
renderer,
viewport,
translation,
)
}
}
+1
View File
@@ -5,6 +5,7 @@ pub const ROW_H: f32 = 26.0;
pub mod color_select;
pub mod command_line;
pub mod dock;
pub mod hover_zone;
pub mod icons;
pub mod menu_bar;
pub mod modal;