mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-26 23:58:03 +00:00
Color Wheel: the contrast background chip takes the focus and has a name
The chip takes the keyboard focus and gives screen readers the name Background with its hex value, as the color vision chips do.
This commit is contained in:
@@ -437,11 +437,22 @@ fn contrast_row(app: &mut VectorcraftApp, ui: &mut Ui) {
|
||||
};
|
||||
let resp = ui
|
||||
.horizontal(|ui| {
|
||||
let (rect, _) = ui.allocate_exact_size(vec2(CHIP, CHIP), egui::Sense::hover());
|
||||
// The chip takes the keyboard focus and gives screen readers its name and hex value, as
|
||||
// the color vision chips do.
|
||||
let (rect, chip_resp) = ui.allocate_exact_size(vec2(CHIP, CHIP), Sense::focusable_noninteractive());
|
||||
match chip {
|
||||
Some(c) => widgets::swatch_tile(ui, rect, &Paint::solid(c), false, false),
|
||||
None => widgets::swatch_tile(ui, rect, &Paint::None, false, false),
|
||||
}
|
||||
if chip_resp.has_focus() {
|
||||
ui.painter().rect_stroke(rect, 0.0, ui.visuals().selection.stroke, StrokeKind::Inside);
|
||||
}
|
||||
let enabled = ui.is_enabled();
|
||||
let value = chip.map(|c| hex(bytes(cms::active().display_rgb(&c))));
|
||||
chip_resp.widget_info(|| egui::WidgetInfo {
|
||||
current_text_value: value.clone(),
|
||||
..egui::WidgetInfo::labeled(egui::Role::Image, enabled, tl!("Background"))
|
||||
});
|
||||
let Some(ratio) = answer.as_ref().and_then(|r| r["ratio"].as_f64()) else {
|
||||
ui.label("—");
|
||||
return;
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
use egui::{Event, Modifiers, PointerButton, Pos2, vec2};
|
||||
use egui_kittest::Harness;
|
||||
use egui_kittest::kittest::Queryable;
|
||||
use egui_kittest::kittest::{NodeT, Queryable};
|
||||
use serde_json::{Value, json};
|
||||
use vectorcraft_color::wcag;
|
||||
use vectorcraft_engine::Session;
|
||||
@@ -119,6 +119,10 @@ fn the_background_is_the_art_behind_the_selection() {
|
||||
let h = harness(app);
|
||||
let want = wcag::ratio_text(wcag::contrast_ratio([0.0; 3], [1.0, 1.0, 0.0]));
|
||||
assert!(shows(&h, &want), "black on the locked yellow: {want}");
|
||||
// Screen readers find the chip by its name, with the background's hex value as its value.
|
||||
let chip = h.get_by_label("Background");
|
||||
assert_eq!(chip.accesskit_node().role(), egui::accesskit::Role::Image);
|
||||
assert_eq!(chip.value().as_deref(), Some("FFFF00"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user