diff --git a/crates/ui-contract/src/runtime/commands/mod.rs b/crates/ui-contract/src/runtime/commands/mod.rs index 6c676315b3..bc4d2fe087 100644 --- a/crates/ui-contract/src/runtime/commands/mod.rs +++ b/crates/ui-contract/src/runtime/commands/mod.rs @@ -139,7 +139,7 @@ impl CommandState { } /// Whether the command's content has something to show, such as comments on a panel. A rail marks the command's - /// button; the marker's description is the command's `hint`. + /// button while the command is not checked (the panel is closed); the marker's description is the command's `hint`. #[must_use] pub fn marked(mut self, marked: bool) -> Self { self.marked = marked; diff --git a/crates/ui-panels/src/rails/panel_rail.rs b/crates/ui-panels/src/rails/panel_rail.rs index 69228eac0b..02c80d9fa1 100644 --- a/crates/ui-panels/src/rails/panel_rail.rs +++ b/crates/ui-panels/src/rails/panel_rail.rs @@ -46,6 +46,9 @@ pub struct PanelRailOutput

{ pub response: Response, /// The panel the user asked to open or close this pass. Its command has run. pub request: Option>, + /// Each icon's response, in order, so the host can hang a context menu on an icon or start a dock drag from it. + /// The rail does neither. + pub items: Vec<(P, Response)>, } impl Outcome for PanelRailOutput

{ @@ -61,7 +64,7 @@ type FooterFn<'a> = Box; /// The rail of icons that open panels, as a side panel at one edge of the window, with a rule along the edge that faces /// the canvas (the inner edge of its pane). A panel is a toggle command: its /// label, icon, chord and enabled state come from the command, the icon shows the on look while the command is -/// checked (the panel is open), and the command's `marked` state and `hint` tell that the closed panel has content +/// checked (the panel is open), and the command's `marked` state and `hint` mark a closed panel that has content /// to show. A click runs the command and reports the request that matches the panel's state. The icons are one /// roving group: Up and Down move between them, Enter and Space toggle. The host's footer stays in view under the /// icons, which scroll when the window is short. @@ -98,7 +101,9 @@ impl<'a, P: Value + 'static> PanelRail<'a, P> { self.footer = Some(Box::new(footer)); let panels = self.panels; let mut request = None; + let mut items = Vec::new(); let shown = self.show(ui, |ui, _| { + items.clear(); let ctx = ui.ctx().clone(); for (at, panel) in panels.iter().enumerate() { let open = commands::resolve(&ctx, panel.command.clone()).checked.unwrap_or(false); @@ -106,9 +111,10 @@ impl<'a, P: Value + 'static> PanelRail<'a, P> { if button.select.is_some() { request = Some(if open { PanelRailRequest::Close(panel.id.clone()) } else { PanelRailRequest::Open(panel.id.clone()) }); } + items.push((panel.id.clone(), button.response)); } }); - PanelRailOutput { request, ..shown.output } + PanelRailOutput { request, items, ..shown.output } } } @@ -136,7 +142,7 @@ impl Component for PanelRail<'_, P> { } fn finish(self, cx: Cx<'_, Self>) -> PanelRailOutput

{ - PanelRailOutput { response: cx.response.clone(), request: None } + PanelRailOutput { response: cx.response.clone(), request: None, items: Vec::new() } } } diff --git a/crates/ui-panels/src/rails/panel_rail/trials.rs b/crates/ui-panels/src/rails/panel_rail/trials.rs index 422984ba3d..deb1312a5e 100644 --- a/crates/ui-panels/src/rails/panel_rail/trials.rs +++ b/crates/ui-panels/src/rails/panel_rail/trials.rs @@ -1,12 +1,15 @@ -//! Trials of `PanelRail` in a short window. +//! Trials of `PanelRail`: a short window, the content mark and the icons' responses. use super::PanelRail; use crate::buttons::Button; use crate::contract::Show as _; -use crate::rails::tool::stories::tools; +use crate::rails::tool::stories::{StoryTools, tools}; +use crate::runtime::commands::CommandState; use crate::testing::pointer::{moved, wheel}; use crate::testing::{Fixture, trial}; -use egui::{Rect, Vec2}; +use egui::{Rect, Shape, Vec2}; +use std::cell::Cell; +use std::rc::Rc; /// The bounds of the node labelled `label`. fn rect(fixture: &Fixture, label: &str) -> Rect { @@ -42,3 +45,29 @@ fn in_a_short_window_the_icons_scroll_above_the_footer_that_stays_in_view() { assert_eq!(rect(&fixture, "Foot"), foot, "{height}: the footer stays put"); } } + +/// The dots painted inside the Move icon while its panel's command is marked and `open` or closed, and how many item +/// responses the rail reported. +fn marked_move(open: bool) -> (usize, usize) { + let items = Rc::new(Cell::new(0)); + let reported = Rc::clone(&items); + let mut fixture = Fixture::new(move |ui| { + let panels = tools(&[0, 1, 2]); + let out = PanelRail::new("Panels", &panels).show_rail(ui, |_| {}); + reported.set(out.items.len()); + }); + fixture.command_state(StoryTools::Move, CommandState::new().marked(true).checked(open)).room(Vec2::new(48.0, 200.0)).settle(); + let icon = rect(&fixture, "Move"); + let dots = fixture.frame_shapes().iter().filter(|shape| matches!(shape, Shape::Circle(dot) if icon.contains(dot.center))).count(); + (dots, items.get()) +} + +/// A marked panel's icon shows the mark while the panel is closed, not while it is open, and the rail reports one +/// response per icon for the host's menus and drags. +#[trial] +fn a_marked_panel_icon_shows_its_mark_only_while_the_panel_is_closed_and_each_icon_reports_its_response() { + let (closed, items) = marked_move(false); + let (open, _) = marked_move(true); + assert!(closed > open, "the mark shows while the panel is closed ({closed}) and not while open ({open})"); + assert_eq!(items, 3, "one response per icon"); +} diff --git a/crates/ui-widgets/src/buttons/icon_button.rs b/crates/ui-widgets/src/buttons/icon_button.rs index 81690d9807..ab1b0682b8 100644 --- a/crates/ui-widgets/src/buttons/icon_button.rs +++ b/crates/ui-widgets/src/buttons/icon_button.rs @@ -136,7 +136,9 @@ impl Component for IconButton<'_> { let triangle = PaintShape::Polygon(vec![corner, Pos2::new(end, bottom - cx.style.mark), Pos2::new(end + reach, bottom)]); draw.fill(&triangle, cx.style.mark_color); } - let marked = cx.command.as_ref().is_some_and(|command| command.marked); + // A mark tells that the command's content has something to show, so it shows while that content is not + // shown: a rail's panel that is closed. + let marked = cx.command.as_ref().is_some_and(|command| command.marked && command.checked != Some(true)); if self.badge.is_some() || marked { let radius = cx.style.marker / 2.0; let x = if cx.flow.is_rtl() { glyph.left() + radius } else { glyph.right() - radius };