IconicColumn: the icon and its name toggle one flyout, which hangs beside the whole row

This commit is contained in:
aiongg
2026-11-12 14:32:46 +00:00
parent 3a25131ca7
commit 7adb7f99a8
5 changed files with 17 additions and 10 deletions
@@ -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;
}
@@ -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()
+7 -1
View File
@@ -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<P: Value + Hash + 'static> 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));
@@ -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()
@@ -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);