Page hex field: an 8-digit hex asking for opaque sets 100%

Review follow-up on #1770: the typed colour keeps the page opacity only when the text carries no alpha (not 4 or 8 hex digits); FF0000FF on a translucent page now sets 100%. Test extended.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
Trevor BrownandClaude Fable 5.1 committed 2026-11-01 00:20:29 -04:00
1 parent 40534ddf14
commit 16b13919aa
2 files changed
+14 -5

No files matched your search

+9 -2
View File
@@ -1231,7 +1231,14 @@ fn the_page_background_opacity_field_sets_the_page_colour_alpha() {
key(&mut u, Key::Enter, Modifiers::NONE);
let c = page_bg(&u);
assert!(near(c.g, 1.0) && near(c.a, 128.0 / 255.0), "{c:?}");
assert_eq!(undo_steps(&u), steps + 3);
// Eight digits asking for opaque set 100 %: an alpha of 1 in the text is not "no alpha".
let at = hex(&mut u);
click(&mut u, at);
u.frame(vec![Event::Text("0000FFFF".into())]);
key(&mut u, Key::Enter, Modifiers::NONE);
let c = page_bg(&u);
assert!(near(c.b, 1.0) && near(c.a, 1.0), "{c:?}");
assert_eq!(undo_steps(&u), steps + 4);
u.app.run("edit.undo", json!({}));
assert!(near(page_bg(&u).r, 1.0) && near(page_bg(&u).a, 0.5), "undo takes back the last colour alone");
assert!(near(page_bg(&u).g, 1.0) && near(page_bg(&u).a, 128.0 / 255.0), "undo takes back the last colour alone");
}
+5 -3
View File
@@ -323,12 +323,14 @@ fn page_section(app: &mut FigApp, ui: &mut Ui, doc: &Document) {
let p = Paint::solid(bg);
let sw = widgets::swatch(ui, &p, 16.0);
app.picker_control(crate::colorpicker::PickerTarget::PageBackground, &sw);
// A typed colour keeps the page's opacity unless it carries one (`FF000080`), as the
// colour picker's hex field does.
// A typed colour keeps the page's opacity unless it carries one: 4 or 8 hex digits
// (`FF000080`; `FF0000FF` asks for opaque).
if let Some(h) = widgets::text_field(ui, Id::unique("pagebg"), &bg.to_hex(), 96.0, "")
&& let Some(c) = figcraft_color::Color::from_hex_or_name(&h)
{
new_color = Some((c.with_alpha(if c.a < 1.0 { c.a } else { bg.a }), None));
let digits = h.trim().trim_start_matches('#');
let carries_alpha = matches!(digits.len(), 4 | 8) && digits.chars().all(|ch| ch.is_ascii_hexdigit());
new_color = Some((if carries_alpha { c } else { c.with_alpha(bg.a) }, None));
}
// The opacity: a field like every other opacity field, not a label (#1748).
let alpha = |v: f64| bg.with_alpha((v / 100.0).clamp(0.0, 1.0) as f32);