Dialog::title_icon; the password dialog's lock stands before its title (trial the_lock_icon_stands_by_the_title_not_the_message, seen failing)

This commit is contained in:
Dylan M. Taylor
2026-11-22 08:14:55 -05:00
parent 0ba9cb07cf
commit f61a28ff00
5 changed files with 37 additions and 9 deletions
+1 -1
View File
@@ -278,7 +278,7 @@ impl Container for FullWindowDialog<'_> {
if self.props.outer_edit {
outer::keep(ui.ctx(), cx);
}
frame::header(ui, cx, frame::close_action(self.closable), None);
frame::header(ui, cx, frame::close_action(self.closable), None, None);
}
fn end(&mut self, ui: &mut Ui, cx: &mut BodyCx<'_>) {
+7 -2
View File
@@ -7,7 +7,9 @@ use crate::contract::{
Show as _, ShowContainer as _, WordSetCx as _, WrapWidth,
};
use crate::contract::{NoValue, Outcome};
use crate::primitives::IconSpec;
use crate::runtime::env::Label;
use crate::style::Ink;
use crate::runtime::overlay::CloseReason;
use crate::sections::{DialogRole, FooterBar, FooterButton, HeaderAction, HeaderStrength, TitleRow};
use crate::style::{ComponentStyle, StyleCx, SurfaceKind};
@@ -139,8 +141,11 @@ pub struct FooterHost<'s, 'a> {
/// Fills the header region: the title, the muted `note` after it when there is one and, for a closable shell, the
/// close action.
#[doc(hidden)]
pub fn header(ui: &mut Ui, cx: &mut BodyCx<'_>, actions: &[HeaderAction], note: Option<&Label>) {
pub fn header(ui: &mut Ui, cx: &mut BodyCx<'_>, actions: &[HeaderAction], note: Option<&Label>, icon: Option<&craft_behavior::IconId>) {
let mut row = TitleRow::new(cx.label()).strength(HeaderStrength::Heading).level(TITLE_LEVEL);
if let Some(icon) = icon {
row = row.icon(IconSpec::svg(icon.clone()).ink(Ink::Accent));
}
if let Some(note) = note {
row = row.note(note.clone());
}
@@ -323,7 +328,7 @@ impl Component for DialogFrame<'_> {
impl Container for DialogFrame<'_> {
fn header(&mut self, ui: &mut Ui, cx: &mut BodyCx<'_>) {
header(ui, cx, close_action(self.closable), None);
header(ui, cx, close_action(self.closable), None, None);
}
fn footer(&mut self, ui: &mut Ui, cx: &mut BodyCx<'_>) {
+11 -1
View File
@@ -82,6 +82,8 @@ pub struct Dialog<'a> {
/// A muted note after the title.
#[prop(into)]
title_note: Option<Label>,
/// An icon of the catalog before the title, in the accent ink.
title_icon: Option<craft_behavior::IconId>,
/// The footer stands in a column at the end edge, beside the whole body.
side: bool,
/// While the body reports its fields unchanged ([`Dialog::report_changed`]), a Close button stands in place of the
@@ -125,6 +127,7 @@ impl<'a> Dialog<'a> {
enter: false,
closable: true,
title_note: None,
title_icon: None,
side: false,
close_unchanged: false,
closed: None,
@@ -247,6 +250,13 @@ impl<'a> Dialog<'a> {
self
}
/// An icon of the catalog before the title, in the accent ink (a lock before "Password required").
#[must_use]
pub fn title_icon(mut self, icon: craft_behavior::IconId) -> Self {
self.title_icon = Some(icon);
self
}
/// The dialog buttons in the footer, in the platform's order for their roles. A click closes the dialog: `Cancel`
/// as `CloseReason::Requested`, every other role as `CloseReason::Activated` unless the button `stays_open`;
/// `DialogOutput::picked` says which.
@@ -483,7 +493,7 @@ impl Container for Dialog<'_> {
if self.holds_outer_gesture() {
outer::keep(ui.ctx(), cx);
}
frame::header(ui, cx, frame::close_action(self.closable), self.title_note.as_ref());
frame::header(ui, cx, frame::close_action(self.closable), self.title_note.as_ref(), self.title_icon.as_ref());
self.keep_window_draggable(ui);
}
@@ -461,6 +461,7 @@ impl<'a> PasswordDialog<'a> {
PasswordPurpose::Set => (words.set_title.clone(), None, common.ok.clone()),
};
let mut dialog = Dialog::new(title)
.title_icon(IconId::new("lock"))
.buttons([FooterButton::new(ok, DialogRole::Accept), FooterButton::new(common.cancel.clone(), DialogRole::Cancel)])
.close_on_enter(true)
.close_guard(move |_, cx| {
@@ -491,10 +492,7 @@ impl<'a> PasswordDialog<'a> {
let mut entries = cx.memory::<Entries>().clone();
Stack::new().show(ui, |ui, _| {
if let Some(message) = &message {
Row::new().show(ui, |ui, _| {
Icon::new(IconSpec::svg(IconId::new("lock"))).show(ui);
Text::new(message.clone()).show(ui);
});
Text::new(message.clone()).show(ui);
}
if let Some(note) = &note {
Text::new(note.clone()).shade(Shade::Muted).show(ui);
@@ -116,6 +116,21 @@ fn an_open_prompt_waits_for_a_typed_password_in_a_bare_field() {
fixture.click(&open).idle(4);
assert!(answers.borrow().is_empty(), "Open does not answer an empty password: {:?}", answers.borrow());
let field = fixture.by_label("Password").expect("the password field");
let title = fixture.texts().iter().find(|run| run.text == "Password required").map(|run| run.rect.min.x).expect("the title");
// The lock stands before the title, so the message (the content's first line) marks where the content starts.
let title = fixture.texts().iter().find(|run| run.text.contains("poster.pdf")).map(|run| run.rect.min.x).expect("the message");
assert!((field.rect.min.x - title).abs() < 6.0, "the field {:?} starts where the dialog's content does ({title})", field.rect);
}
/// The lock stands by the title, as production's does; the message under it starts at the content's edge.
#[trial]
fn the_lock_icon_stands_by_the_title_not_the_message() {
let mut fixture = Fixture::new(|ui| {
let _ = PasswordDialog::new(PasswordPurpose::open("poster.pdf")).show(ui);
});
fixture.idle(30);
let at = |starts: &str| fixture.texts().iter().find(|run| run.text.starts_with(starts)).map(|run| run.rect).unwrap_or(egui::Rect::NOTHING);
let (title, message) = (at("Password required"), at("\u{201c}poster.pdf"));
let message = if message.is_positive() { message } else { at("poster.pdf") };
assert!(title.is_positive() && message.is_positive(), "both texts are painted: {title:?} {message:?}");
assert!(title.left() > message.left() + 8.0, "the title starts after the lock: {title:?} vs the message {message:?}");
}