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 {
@@ -61,7 +64,7 @@ type FooterFn<'a> = Box {
- 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 };