mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-26 02:09:00 +00:00
TitleRow::icon_ink; a dialog's title icon is drawn in the accent (trial the_title_lock_is_drawn_in_the_accent_colour, seen failing)
This commit is contained in:
@@ -144,7 +144,7 @@ pub struct FooterHost<'s, 'a> {
|
||||
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));
|
||||
row = row.icon(IconSpec::svg(icon.clone())).icon_ink(Ink::Accent);
|
||||
}
|
||||
if let Some(note) = note {
|
||||
row = row.note(note.clone());
|
||||
|
||||
@@ -186,6 +186,10 @@ pub struct TitleRow<'a> {
|
||||
/// An icon before the title, painted in the style's icon colour unless the spec names another.
|
||||
#[prop]
|
||||
icon: Option<IconSpec<'a>>,
|
||||
/// The ink of that icon: the accent for a dialog's lock or warning mark.
|
||||
#[style_key]
|
||||
#[prop]
|
||||
icon_ink: Ink,
|
||||
/// Whether the row takes the whole width offered, so its actions sit at the end edge; off, it is as wide as its
|
||||
/// parts.
|
||||
#[prop]
|
||||
@@ -231,6 +235,7 @@ impl<'a> TitleRow<'a> {
|
||||
note: None,
|
||||
subtitle: None,
|
||||
icon: None,
|
||||
icon_ink: Ink::OnPanel,
|
||||
fill: true,
|
||||
lead_name: None,
|
||||
handle: false,
|
||||
@@ -341,7 +346,7 @@ impl Component for TitleRow<'_> {
|
||||
HeaderStrength::Caption => (cx.control().height, TypeRole::Label, text.faint),
|
||||
};
|
||||
let shade = key.tone.map_or_else(|| cx.color(shade), |tone| cx.tone_on_fill(tone));
|
||||
let (ink, disabled) = (cx.ink(Ink::OnPanel), cx.color(text.disabled));
|
||||
let (ink, disabled) = (cx.ink(key.icon_ink), cx.color(text.disabled));
|
||||
TitleRowStyle {
|
||||
metrics: Metrics::new().min_size(Vec2::new(0.0, height)).gap(cx.control().gap),
|
||||
text: TextLook::new(role, Stateful::new(shade).off(States::new(shade, shade, shade, disabled))),
|
||||
|
||||
@@ -134,3 +134,27 @@ fn the_lock_icon_stands_by_the_title_not_the_message() {
|
||||
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:?}");
|
||||
}
|
||||
|
||||
/// The lock before the title is in the accent colour, as production's is.
|
||||
#[trial]
|
||||
fn the_title_lock_is_drawn_in_the_accent_colour() {
|
||||
let mut fixture = Fixture::new(|ui| {
|
||||
let _ = PasswordDialog::new(PasswordPurpose::open("poster.pdf")).show(ui);
|
||||
});
|
||||
fixture.idle(30);
|
||||
let title = fixture.texts().iter().find(|run| run.text.starts_with("Password required")).map(|run| run.rect).expect("the title");
|
||||
let colours: Vec<egui::Color32> = fixture
|
||||
.frame_shapes()
|
||||
.iter()
|
||||
.filter_map(|shape| match shape {
|
||||
egui::Shape::Mesh(mesh) if mesh.calc_bounds().max.x <= title.left() + 1.0 && (mesh.calc_bounds().center().y - title.center().y).abs() < 8.0 => {
|
||||
mesh.vertices.first().map(|v| v.color)
|
||||
}
|
||||
_ => None,
|
||||
})
|
||||
.collect();
|
||||
let accent = craft_ui::testing::style::tokens(craft_theme::Mode::Light, craft_theme::Contrast::Standard).color.accent.text;
|
||||
assert!(!colours.is_empty(), "the lock is drawn before the title");
|
||||
let accent = egui::Color32::from_rgb(accent.0[0], accent.0[1], accent.0[2]);
|
||||
assert!(colours.contains(&accent), "the lock is {colours:?}, not the accent {accent:?}");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user