Merge pull request #10992 from dotCooCoo/fix/issue-10271

Fix #10271: square swatches, palette-style floating groups and black and white drawing pointers
This commit is contained in:
.CooCoo authored and GitHub committed 2026-12-05 14:52:38 -08:00
commit d149d894b5
3 files changed
+87 -10

No files matched your search

+10 -2
View File
@@ -5,12 +5,13 @@ use craft::platform::clipboard::{Clipboard, ClipboardProbe, EventClipboard};
use craft::platform::clock::monotonic_ms;
use craft::theme::variant::Tone;
use craft::ui::buttons::{ActiveLook, PushButtonLook};
use craft::ui::choice::ChoiceLook;
use craft::ui::choice::{ChoiceLook, SwatchCorners};
use craft::ui::contract::{Bind, CaptionInk, GlyphColon, LinkLabelInk, LinkLabelUnderline, MoveBandCursor, QuietHeader, SectionRhythm};
use craft::ui::docking::IconGroupSeparator;
use craft::ui::docking::{FloatingGroupLook, IconGroupSeparator};
use craft::ui::list::{CommandHighlight, ThumbRows};
use craft::ui::menu::{MenuTitleLook, MenuTitlePad};
use craft::ui::patterns::form_dialogs::PresetCardLook;
use craft::ui::primitives::DrawingCursorLook;
use craft::ui::runtime::drag::{self, OsFiles};
use craft::ui::runtime::env::{AltCodeKeys, RootEnv, Scale, ScrubDrags, WindowKey, WordsOverride, with_env};
use craft::ui::runtime::frame::{FrameInput, FrameOutput};
@@ -941,6 +942,9 @@ pub(crate) fn root_env(prefs: &vectorcraft_engine::Prefs, native_ppp: f32, print
let mut root = RootEnv::new().theme(theme).mode(mode).accent(accent).scale(Scale::new(scaling)).tooltips(prefs.show_tool_tips);
// Painted tool cursors grow with UI Scaling only when Scale Cursor Proportional to UI is on.
root = root.cursor_follows_zoom(prefs.scale_cursor_with_ui);
// The Selection, Direct Selection and Hand pointers, the drawing crosshairs and the tool cursors draw in black and
// white over the artwork in either interface theme.
root.values.set(DrawingCursorLook::Monochrome);
root.sizes = theme::app_sizes();
root.values.set(view::zoom_scheme(print, native_ppp));
root.values.set(if prefs.scrub_numeric_fields { ScrubDrags::LabelOnly } else { ScrubDrags::Off });
@@ -969,6 +973,10 @@ pub(crate) fn root_env(prefs: &vectorcraft_engine::Prefs, native_ppp: f32, print
// Check boxes, radio buttons and switches that are on take the strong accent with a white mark, sliders fill their
// track to the value in the accent, and a dialog's Cancel is a filled button beside its accent answer.
root.values.set(ChoiceLook::Strong);
// Color swatches and the Fill and Stroke wells keep square corners, so a small sample shows its whole color.
root.values.set(SwatchCorners::Square);
// Floating panel groups and tool palettes are square palettes with a small shadow.
root.values.set(FloatingGroupLook::Palette);
root.values.set(TrackFill::Accent);
root.values.set(DialogButtonLook::Filled);
// Sections stand apart with production's room around their dividers.
+36
View File
@@ -78,3 +78,39 @@ fn the_close_caption_asks_about_unsaved_documents() {
assert_eq!(close_frame(&mut app, &ctx), Some(CloseDecision::Close));
assert!(!asks_about_unsaved(&app), "nothing unsaved, nothing asked");
}
/// A color swatch fills its well to the corners: every opaque rectangle the well paints has square corners, so a
/// small sample shows its whole color.
#[test]
fn a_color_swatch_paints_a_square_well() {
use craft::theme::Srgba;
use craft::ui::choice::Swatch;
use craft::ui::contract::Show as _;
let mut well = egui::Rect::NOTHING;
let mut out = crate::testing::ui_context().run_ui(Default::default(), |ui| {
well = Swatch::new("Color", Srgba::rgb(0.2, 0.6, 0.4)).show(ui).response.rect;
});
out.textures_delta.clear();
let fills: Vec<(egui::Rect, egui::CornerRadius)> = out
.shapes
.iter()
.filter_map(|clipped| match &clipped.shape {
egui::Shape::Rect(rect) if rect.fill.a() == 255 && well.expand(1.0).contains_rect(rect.rect) => Some((rect.rect, rect.corner_radius)),
_ => None,
})
.collect();
assert!(!fills.is_empty(), "the well paints its color in {well:?}");
let rounded: Vec<_> = fills.iter().filter(|(_, corners)| *corners != egui::CornerRadius::ZERO).collect();
assert!(rounded.is_empty(), "the well's corners are square: {rounded:?}");
}
/// Floating panel groups and tool palettes take the palette frame, square with a small shadow, not the rounded frame
/// of a floating window.
#[test]
fn floating_groups_take_the_palette_frame() {
use craft::ui::docking::FloatingGroupLook;
use craft::ui::runtime::env::Env;
let mut look = None;
crate::testing::ui_context().run_ui(Default::default(), |ui| look = Some(Env::of(ui).get::<FloatingGroupLook>())).textures_delta.clear();
assert_eq!(look, Some(FloatingGroupLook::Palette));
}
+41 -8
View File
@@ -6,15 +6,14 @@ use super::*;
fn every_tool_cursors_hotspot_is_on_its_glyph() {
use craft::ui::primitives::{painted_image, register_app_icons};
use craft::ui::runtime::env::Env;
use craft::ui::style::rgba_color;
crate::icons::register();
register_app_icons(&CURSOR_ICONS);
let mut missed = Vec::new();
crate::testing::ui_context()
.run_ui(Default::default(), |ui| {
let env = Env::of(ui);
let ink = rgba_color(env.tokens.tokens().color.overlay.cursor);
let near_ink = |px: &[u8]| px[3] == 255 && [ink.r(), ink.g(), ink.b()].iter().zip(px).all(|(want, got)| want.abs_diff(*got) <= 8);
// The tool marks are black; their white halo is not a part of the glyph a click lands on.
let near_ink = |px: &[u8]| px[3] == 255 && px[..3].iter().all(|value| *value <= 8);
for c in GLYPHS {
let cb::Cursor::Painted(painted @ PaintedCursor::Tool { .. }) = tool_cursor(c) else { continue };
let Some(image) = painted_image(&env, &painted, 2.0) else {
@@ -71,6 +70,42 @@ fn a_tools_move_resize_grab_and_not_allowed_cursors_are_drawn_like_its_own() {
assert!(matches!(tool_cursor(Cursor::Busy), cb::Cursor::System(_)), "the wait pointer stays the system's");
}
/// The Selection and Direct Selection arrows, the Hand, the drawing crosshair and a tool cursor draw in black and
/// white only, in the Modern and Classic color schemes and in light and dark interfaces: no pixel takes the accent or
/// another hue over the artwork.
#[test]
fn drawing_pointers_draw_in_black_and_white() {
use craft::ui::primitives::{painted_image, register_app_icons};
use craft::ui::runtime::env::Env;
use craft::ui::runtime::frame::{FrameInput, set_input};
crate::icons::register();
register_app_icons(&CURSOR_ICONS);
let pointers = [Cursor::Arrow, Cursor::ArrowHollow, Cursor::Hand, Cursor::Crosshair, Cursor::Pen];
use crate::theme::{Brightness, Scheme};
let looks = [(Scheme::Modern, Brightness::Dark), (Scheme::Classic, Brightness::MediumDark), (Scheme::Classic, Brightness::Light)];
for (scheme, brightness) in looks {
let ctx = crate::testing::ui_context();
let prefs = vectorcraft_engine::Prefs { ui_color_scheme: scheme.id().into(), ui_brightness: brightness.id().into(), ..Default::default() };
set_input(&ctx, FrameInput::new(crate::app::root_env(&prefs, 1.0, None)));
ctx.run_ui(Default::default(), |ui| {
let env = Env::of(ui);
for c in pointers {
let cb::Cursor::Painted(painted) = tool_cursor(c) else { panic!("{c:?} is painted") };
let image = painted_image(&env, &painted, 2.0).unwrap_or_else(|| panic!("{c:?} has no image"));
let tinted = image
.rgba
.as_chunks::<4>()
.0
.iter()
.find(|px| px[3] > 0 && px[..3].iter().max().zip(px[..3].iter().min()).is_some_and(|(hi, lo)| hi - lo > 8));
assert!(tinted.is_none(), "{scheme:?} {brightness:?} {c:?}: a pixel takes a hue: {tinted:?}");
}
})
.textures_delta
.clear();
}
}
/// A `cursor-` icon name a cursor uses must be in the set the host registers.
#[test]
fn every_cursor_icon_the_app_names_is_in_its_set() {
@@ -87,18 +122,16 @@ fn every_cursor_icon_the_app_names_is_in_its_set() {
fn the_painted_pen_nibs_keep_their_breather_holes() {
use craft::ui::primitives::{painted_image, register_app_icons};
use craft::ui::runtime::env::Env;
use craft::ui::style::rgba_color;
register_app_icons(&crate::icons::APP_ICONS);
register_app_icons(&CURSOR_ICONS);
crate::testing::ui_context()
.run_ui(Default::default(), |ui| {
let env = Env::of(ui);
let tokens = env.tokens.tokens();
let ink = rgba_color(tokens.color.overlay.cursor);
let is_ink = |px: &[u8]| px[3] >= 240 && [ink.r(), ink.g(), ink.b()].iter().zip(px).all(|(want, got)| want.abs_diff(*got) <= 8);
// The tool marks are black, drawn on the icon's 24-unit box at one point per unit.
let is_ink = |px: &[u8]| px[3] >= 240 && px[..3].iter().all(|value| *value <= 8);
let scale = 4.0;
let from_art_units = tokens.size.icon.md * scale / 24.0;
let from_art_units = scale;
for c in [Cursor::Pen, Cursor::PenConvert, Cursor::PenJoin, Cursor::Curvature] {
let cb::Cursor::Painted(painted @ PaintedCursor::Tool { hotspot, .. }) = tool_cursor(c) else {
panic!("{c:?} must have painted tool art");