diff --git a/crates/ui-contract/src/contract/overlay/toggles.rs b/crates/ui-contract/src/contract/overlay/toggles.rs index 24c97a43e..3118a6c9e 100644 --- a/crates/ui-contract/src/contract/overlay/toggles.rs +++ b/crates/ui-contract/src/contract/overlay/toggles.rs @@ -34,7 +34,8 @@ impl crate::contract::cx::Toggle { impl PartBuilder<'_> { /// The part opens and closes the repeat `index` of the component's popup `popup`: `toggles` for a component with - /// one popup per part. Open one popup at a time: opening the second closes the first. + /// one popup per part. Open one popup at a time: opening the second closes the first. Several parts may toggle the + /// same popup. pub fn toggles_at(self, popup: &'static str, index: usize) -> Self { self.declared.toggles = Some(ToggleDecl::new(popup, index)); self @@ -115,9 +116,11 @@ pub(crate) fn drive_toggles(core: &mut CxCore<'_>, overlays: bool, name: &str) { open.push(toggle.handle(owner).is_open_in(core)); } if let Some(keeper) = opened { - // Opening one popup closes the others. + // Opening one popup closes the others. Several parts may toggle one popup (an icon and the name beside it): + // theirs stays open. + let kept = toggles[keeper].handle(owner).id; for (at, toggle) in toggles.iter().enumerate() { - if at != keeper && open[at] { + if toggle.handle(owner).id != kept && open[at] { toggle.handle(owner).close_in(core); open[at] = false; } diff --git a/crates/ui-panels/src/docking/flyout/stories.rs b/crates/ui-panels/src/docking/flyout/stories.rs index 7058696d4..811ce9fa7 100644 --- a/crates/ui-panels/src/docking/flyout/stories.rs +++ b/crates/ui-panels/src/docking/flyout/stories.rs @@ -22,7 +22,7 @@ fn open_beside_its_column(ui: &mut Ui, _: &mut StoryData) -> StoryOutput { .show_flyouts(ui, |group, at, ui, _| { let GroupAt::Show(rect) = at else { return None }; let title = group.active_panel().map_or_else(String::new, |panel| spec(panel).label.as_str().to_owned()); - Panel::new(title).show_at(ui, rect, |_, _| ()); + Panel::new(title).titled().show_at(ui, rect, |_, _| ()); None }) .into() diff --git a/crates/ui-panels/src/docking/iconic.rs b/crates/ui-panels/src/docking/iconic.rs index 93d283561..d3e71be2b 100644 --- a/crates/ui-panels/src/docking/iconic.rs +++ b/crates/ui-panels/src/docking/iconic.rs @@ -5,6 +5,7 @@ use super::dock_column::{BarRecord, CHEVRON, bar_slots, chevron_name, column_gri use super::flyout; use super::{DockSizes, DockSpot, DockTargets, DockWords, DragUnit, Flyout, GroupAt, PanelKey, PanelSpec, Splitter, start_group_drag}; use crate::buttons::IconButton; +use crate::contract::overlay::Anchor; use crate::contract::{ Access, Bind, BindMut, BodyCx, Common, Component, Container, ContainerProps, Cx, Edit as _, EditResponse, HeaderEdge, HeaderParts, HeaderRegion, MeasureCx, Name, Outcome, OverlayUi, Overlays as _, Pad, PaintUi, PartsCx, Pointer as _, Props as _, Role, ShowContainer as _, Sizing, @@ -486,11 +487,16 @@ impl Component for IconicColumn<'_, P> { }) }) .collect(); + let wide = self.laid.as_ref().is_some_and(|plan| !plan.names.is_empty()); let Some(view) = self.view.as_mut() else { return }; let mut dismissed = false; for (at, group) in groups.into_iter().enumerate() { let Some((group, height)) = group else { continue }; - let anchor = ui.anchor_part(CELL.at(at as u64)); + // In a wide column the flyout hangs beside the whole row, past the name. + let anchor = match (ui.anchor_part(CELL.at(at as u64)), wide.then(|| ui.anchor_part(NAME.at(at as u64)))) { + (Anchor::Rect(icon), Some(Anchor::Rect(name))) => Anchor::Rect(icon.union(name)), + (icon, _) => icon, + }; Flyout::new(edge, Vec2::new(width, height), auto_collapse) .show(ui, popup.at(at), anchor, |ui, body, place| view(&group, place, ui, body)); dismissed |= flyout::dismissed(ui, popup.at(at)); diff --git a/crates/ui-panels/src/docking/iconic/stories.rs b/crates/ui-panels/src/docking/iconic/stories.rs index 4d1ef768c..fc56451c5 100644 --- a/crates/ui-panels/src/docking/iconic/stories.rs +++ b/crates/ui-panels/src/docking/iconic/stories.rs @@ -25,7 +25,7 @@ fn icon_groups(ui: &mut Ui, _: &mut StoryData) -> StoryOutput { .show_flyouts(ui, |group, at, ui, _| { let GroupAt::Show(rect) = at else { return None }; let title = group.active_panel().map_or_else(String::new, |panel| spec(panel).label.as_str().to_owned()); - Panel::new(title).show_at(ui, rect, |_, _| ()); + Panel::new(title).titled().show_at(ui, rect, |_, _| ()); None }) .into() @@ -47,7 +47,7 @@ fn icon_flyout_open(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { .show_flyouts(ui, |group, at, ui, _| { let GroupAt::Show(rect) = at else { return None }; let title = group.active_panel().map_or_else(String::new, |panel| spec(panel).label.as_str().to_owned()); - Panel::new(title).show_at(ui, rect, |_, _| ()); + Panel::new(title).titled().show_at(ui, rect, |_, _| ()); None }) .into() diff --git a/crates/ui-panels/src/docking/iconic/trials.rs b/crates/ui-panels/src/docking/iconic/trials.rs index 4c59dce63..7e29c445d 100644 --- a/crates/ui-panels/src/docking/iconic/trials.rs +++ b/crates/ui-panels/src/docking/iconic/trials.rs @@ -1,6 +1,5 @@ //! Trials of `IconicColumn`: the letter of a panel without an icon, and the names a wide column shows. -use super::CELL; use crate::contract::{Bind, ShowContainer as _}; use crate::docking::{GroupAt, IconicColumn, PanelSpec}; use crate::sections::Panel; @@ -44,8 +43,7 @@ fn an_icon_less_panel_shows_its_initial_and_a_wide_column_shows_names_that_open_ let (mut wide, open) = column(200.0); assert!(painted(&wide, "Brushes") && painted(&wide, "Swatches"), "a wide column shows the names"); - let id = wide.root_id().expect("the column is shown"); - let icon = wide.part(id, CELL.at(1)).expect("the second icon"); + let icon = wide.by_label("Swatches").expect("the Swatches icon"); assert!(icon.rect.width() < 200.0 / 2.0, "the icon keeps its square at the start: {:?}", icon.rect); // The name has no node of its own: the icon is its keyboard stop. Click on it, past the icon. wide.click_at(icon.rect.right_center() + Vec2::new(icon.rect.width(), 0.0)).idle(3);