From d5b79934175e927cc04cb79885f2a1e893f4e2f6 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Sun, 22 Nov 2026 18:59:23 -0500 Subject: [PATCH] Note pop-up: the title band runs under Close (trial the_title_band_runs_under_the_close_control) --- crates/review/src/ui/thread/note_popup.rs | 32 +++++++++++++---------- crates/review/tests/it/note_popup.rs | 29 ++++++++++++++++++++ 2 files changed, 47 insertions(+), 14 deletions(-) diff --git a/crates/review/src/ui/thread/note_popup.rs b/crates/review/src/ui/thread/note_popup.rs index 2fa119409..60e1c7b50 100644 --- a/crates/review/src/ui/thread/note_popup.rs +++ b/crates/review/src/ui/thread/note_popup.rs @@ -9,7 +9,7 @@ use craft_ui::buttons::{Button, IconButton, PressFocus}; use craft_ui::contract::overlay::{PlacementChange, PlacementKind, ResizeEdges}; use craft_ui::contract::{ Bind, BindMut, BodyCx, Common, Component, Container, ContainerProps, Cx, DragBand, HeaderRegion, MeasureCx, Mount, NoValue, Outcome, Overlay, - Pad, PaintUi, Pattern, Props as _, Role, Show as _, ShowContainer as _, SizeLimits, ThemeScope, clicked, + Gap, Pad, PaintUi, Pattern, Props as _, Role, Show as _, ShowContainer as _, SizeLimits, Sizing, ThemeScope, clicked, }; use craft_ui::display::{Shade, Text}; use craft_ui::layout_components::{Row, Stack}; @@ -517,7 +517,7 @@ impl NoteWindow { let props = ContainerProps::new() .mount(Mount::Layer(overlay)) .surface(SurfaceKind::Floating) - .header(HeaderRegion::new().band(DragBand::Move).trailing(true)); + .header(HeaderRegion::new().band(DragBand::Move)); NoteWindow { common: Common::new(), props, @@ -574,20 +574,24 @@ impl Container for NoteWindow { Some(self.open.reborrow()) } - /// The title band: the note's kind and author and its age, on the note's colour. + /// The title band: the note's kind and author and its age, with Close at its end, all on the note's colour. Close + /// is the band's own control, which needs the document to allow commenting, as closing changes the note. fn header(&mut self, ui: &mut Ui, _: &mut BodyCx<'_>) { let look = self.look.clone(); - let _ = NoteTitle { common: Common::new(), look: look.clone() }.label(look.title).show(ui); - } - - /// Close, which needs the document to allow commenting, as closing changes the note. - fn controls(&mut self, ui: &mut Ui, _: &mut BodyCx<'_>) { - let close = IconButton::new(IconSpec::svg(IconId::new("close"))) - .label(self.close_label.clone()) - .enabled(self.allowed) - .press_focus(PressFocus::Keep) - .show(ui); - self.close |= clicked(&close); + let band = ui.painter().add(egui::Shape::Noop); + let shown = Row::new().fill_width().gap(Gap::None).show(ui, |ui, _| { + let _ = NoteTitle { common: Common::new(), look: look.clone() }.label(look.title.clone()).sizing(Sizing::FillWidth).show(ui); + let close = IconButton::new(IconSpec::svg(IconId::new("close"))) + .label(self.close_label.clone()) + .enabled(self.allowed) + .press_focus(PressFocus::Keep) + .show(ui); + self.close |= clicked(&close); + }); + let radius = UiTokens::corner(Env::of(ui).tokens.shape.radius.surface); + let radius = CornerRadius { sw: 0, se: 0, ..radius }; + let DataColor(fill) = look.fill; + ui.painter().set(band, egui::Shape::rect_filled(shown.output.rect, radius, fill)); } fn closed(&mut self, _: CloseReason) { diff --git a/crates/review/tests/it/note_popup.rs b/crates/review/tests/it/note_popup.rs index 5dc16b12f..e419bd44a 100644 --- a/crates/review/tests/it/note_popup.rs +++ b/crates/review/tests/it/note_popup.rs @@ -280,3 +280,32 @@ fn the_reply_button_sits_at_the_end_edge_of_the_window() { assert!(window.right() - reply.rect.right() < 24.0, "Reply ends near the window's end edge: {:?} in {window:?}", reply.rect); assert!(reply.rect.left() > window.center().x, "Reply sits in the end half: {:?} in {window:?}", reply.rect); } + +/// The title band is the note's colour across the window's whole width, Close included, as production's. +#[trial] +fn the_title_band_runs_under_the_close_control() { + use craft_ui::testing::{Frames, install_spec}; + let mut frames = Frames::uninstalled(); + craft_ui::install(&frames.ctx, install_spec()).expect("the runtime installs"); + frames.record_paint(); + let mut drafts = NoteDrafts::default(); + let rect = Rect::from_min_size(pos2(100.0, 100.0), vec2(320.0, 200.0)); + for _ in 0..4 { + frames.frame(vec![], |ui| { + let _ = NotePopup::new(1, "Note", rect, &NOTE, &mut drafts).color(Some([10, 20, 200])).show(ui); + }); + } + let mut paint = frames.take_paint().expect("paint is recorded"); + paint.textures_delta.clear(); + fn band(shape: &egui::Shape, out: &mut Vec) { + match shape { + egui::Shape::Rect(r) if r.fill == egui::Color32::from_rgb(10, 20, 200) => out.push(r.rect), + egui::Shape::Vec(shapes) => shapes.iter().for_each(|s| band(s, out)), + _ => {} + } + } + let mut bands = Vec::new(); + paint.shapes.iter().for_each(|clipped| band(&clipped.shape, &mut bands)); + let widest = bands.iter().map(|r| r.width()).fold(0.0, f32::max); + assert!((widest - rect.width()).abs() < 1.5, "the band covers the window's width, close control included: {bands:?}"); +}