Icons keep their multi-tone artwork: tone accents for confirm, menu and radial glyphs

This commit is contained in:
Nathan Dane
2026-10-20 17:09:24 +02:00
parent d45fcce72c
commit 41f5957d60
8 changed files with 424 additions and 24 deletions
+72 -4
View File
@@ -470,6 +470,33 @@ impl Look {
}
}
/// Explicit whole-glyph tinting maps shaded passive faces to the selected active ramp.
/// Keep ink, guides, literal mask colours and knockouts in their original roles.
#[derive(Clone, Copy)]
struct PaintLook {
look: Look,
tint_passive: bool,
}
impl PaintLook {
fn resolve(self, paint: Paint) -> Option<[u8; 3]> {
if self.tint_passive
&& let Paint::Role(role) = paint
{
let active = match ROLE_NAMES.get(role).copied() {
Some("passive-1") => Some("active-1"),
Some("passive-2") => Some("active-2"),
Some("passive-3") => Some("active-3"),
_ => None,
};
if let Some(role) = active.and_then(|name| ROLE_NAMES.iter().position(|role| *role == name)) {
return Some(self.look.rgb(role));
}
}
self.look.resolve(paint)
}
}
fn paint_of(c: [u8; 3], alpha: f32) -> sk::Paint<'static> {
let mut p = sk::Paint::default();
p.set_color_rgba8(c[0], c[1], c[2], (alpha.clamp(0.0, 1.0) * 255.0).round() as u8);
@@ -477,7 +504,7 @@ fn paint_of(c: [u8; 3], alpha: f32) -> sk::Paint<'static> {
p
}
fn shape_paint(paint: Paint, look: Look, alpha: f32) -> Option<sk::Paint<'static>> {
fn shape_paint(paint: Paint, look: PaintLook, alpha: f32) -> Option<sk::Paint<'static>> {
if paint == Paint::Knockout {
let mut paint = paint_of([0, 0, 0], alpha);
paint.blend_mode = sk::BlendMode::DestinationOut;
@@ -487,7 +514,7 @@ fn shape_paint(paint: Paint, look: Look, alpha: f32) -> Option<sk::Paint<'static
}
}
fn draw_node(pm: &mut sk::Pixmap, n: &Node, look: Look, tf: sk::Transform, doc: &Doc, clip: Option<&sk::Mask>, opacity: f32) {
fn draw_node(pm: &mut sk::Pixmap, n: &Node, look: PaintLook, tf: sk::Transform, doc: &Doc, clip: Option<&sk::Mask>, opacity: f32) {
let own;
let mask = if let Some(m) = n.mask {
own = doc.masks.get(m).and_then(|nodes| {
@@ -523,7 +550,7 @@ fn draw_node(pm: &mut sk::Pixmap, n: &Node, look: Look, tf: sk::Transform, doc:
}
}
fn draw_items(pm: &mut sk::Pixmap, items: &[Item], look: Look, tf: sk::Transform, doc: &Doc, clip: Option<&sk::Mask>, opacity: f32) {
fn draw_items(pm: &mut sk::Pixmap, items: &[Item], look: PaintLook, tf: sk::Transform, doc: &Doc, clip: Option<&sk::Mask>, opacity: f32) {
for item in items {
match item {
Item::Node(n) => draw_node(pm, n, look, tf, doc, clip, opacity),
@@ -543,6 +570,15 @@ fn draw_items(pm: &mut sk::Pixmap, items: &[Item], look: Look, tf: sk::Transform
/// Rasterise `doc` into a square `px` × `px` premultiplied RGBA image.
pub fn render(doc: &Doc, look: Look, px: u32) -> Option<sk::Pixmap> {
render_with_look(doc, PaintLook { look, tint_passive: false }, px)
}
/// Tint passive faces through the active ramp while retaining shading and all geometry.
pub(crate) fn render_tinted(doc: &Doc, look: Look, px: u32) -> Option<sk::Pixmap> {
render_with_look(doc, PaintLook { look, tint_passive: true }, px)
}
fn render_with_look(doc: &Doc, look: PaintLook, px: u32) -> Option<sk::Pixmap> {
let mut pm = sk::Pixmap::new(px, px)?;
let s = px as f32 / 64.0;
draw_items(&mut pm, &doc.items, look, sk::Transform::from_scale(s, s), doc, None, 1.0);
@@ -582,7 +618,7 @@ pub struct Resolved {
pub placeholder: bool,
}
fn accent_index(name: &str) -> Option<usize> {
pub(crate) fn accent_index(name: &str) -> Option<usize> {
if name.is_empty() { None } else { ACCENT_NAMES.iter().position(|a| *a == name) }
}
@@ -946,4 +982,36 @@ mod tests {
assert_eq!(PALETTE.len(), 2);
assert!(PALETTE.iter().all(|p| p.len() == ROLE_NAMES.len()));
}
#[test]
fn danger_tint_preserves_faces_outlines_and_transparent_details() {
for dark in [false, true] {
for vision in crate::theme::ColorVision::ALL {
let look = Look { dark, accent: accent_index("constraint"), vision };
for id in ["delete", "new", "extrude"] {
for px in [16, 20, 64] {
let doc = doc_for(id, px).unwrap();
let normal = render(doc, look, px).unwrap();
let tinted = render_tinted(doc, look, px).unwrap();
assert!(
normal.pixels().iter().zip(tinted.pixels()).all(|(a, b)| a.alpha() == b.alpha()),
"{id}/{px}: preserve contours, handle, slat cutouts and masks"
);
if id == "delete" && px == 64 {
let image = egui::ColorImage::from_rgba_premultiplied([64, 64], tinted.data());
for role in ["ink", "active-2", "active-3"] {
assert!(
image.pixels.contains(&role_colour(role, look)),
"{role}, dark={dark}/{vision:?}: retain separate face and outline colours"
);
}
for role in ["passive-2", "passive-3"] {
assert!(!image.pixels.contains(&role_colour(role, look)), "{role}: bin faces must take the red ramp");
}
}
}
}
}
}
}
}
+164 -7
View File
@@ -20,9 +20,16 @@ pub(crate) mod navigation;
#[path = "../../../assets/icons/ui/source/pointer.rs"]
pub(crate) mod pointer;
/// Textures already rasterised: one per (master, look, pixel size).
#[derive(Clone, Copy, PartialEq, Eq, Hash)]
enum Finish {
Artwork,
Ink(Color32),
Danger,
}
/// Textures already rasterised: one per (master, look, pixel size, finish).
#[derive(Clone, Default)]
struct Cache(Arc<Mutex<HashMap<(&'static str, Look, u32, Option<Color32>), TextureHandle>>>);
struct Cache(Arc<Mutex<HashMap<(&'static str, Look, u32, Finish), TextureHandle>>>);
/// Draw the icon `name` in `r`. The ink, fill and accent colours the callers pass are no longer
/// used: the palette decides. Only the ink's opacity is kept, so a dimmed (disabled) button dims
@@ -58,20 +65,48 @@ pub(crate) fn paint_ink_flipped(p: &Painter, r: Rect, name: &str, ink: Color32)
}
fn paint_with_ink(p: &Painter, r: Rect, name: &str, dark: Option<bool>, opacity: f32, ink: Option<Color32>, flip_y: bool) {
let ctx = p.ctx();
let resolved = icon_svg::resolve(name);
let look = Look { dark: dark.unwrap_or_else(|| ctx.global_style().visuals.dark_mode), accent: resolved.accent, vision: crate::theme::vision() };
paint_resolved(p, r, resolved, look, opacity, ink.map_or(Finish::Artwork, Finish::Ink), flip_y);
}
/// Draw with a named palette ramp, preserving outlines, passive faces and transparency.
/// `None` explicitly selects base blue; an unknown name retains the icon's own accent.
/// Existing painters continue to select the icon's semantic accent.
pub fn paint_accented(p: &Painter, r: Rect, name: &str, accent: Option<&str>, opacity: f32) {
let resolved = icon_svg::resolve(name);
let accent = match accent {
Some(name) => icon_svg::accent_index(name).or(resolved.accent),
None => None,
};
let look = Look { dark: p.ctx().global_style().visuals.dark_mode, accent, vision: crate::theme::vision() };
paint_resolved(p, r, resolved, look, opacity, Finish::Artwork, false);
}
/// Shared destructive-action artwork: red shaded faces, normal outlines and cutouts.
/// Unlike a single-colour mask, this also tints a master's passive faces through
/// the constraint ramp without flattening the lid, handle or other details.
pub(crate) fn paint_danger(p: &Painter, r: Rect, name: &str, opacity: f32) {
let resolved = icon_svg::resolve(name);
let look = Look { dark: p.ctx().global_style().visuals.dark_mode, accent: icon_svg::accent_index("constraint"), vision: crate::theme::vision() };
paint_resolved(p, r, resolved, look, opacity, Finish::Danger, false);
}
fn paint_resolved(p: &Painter, r: Rect, resolved: icon_svg::Resolved, look: Look, opacity: f32, finish: Finish, flip_y: bool) {
let ctx = p.ctx();
let ppp = ctx.pixels_per_point().max(0.5);
let side = r.width().min(r.height());
let px = (side * ppp).round().clamp(8.0, 512.0) as u32;
let resolved = icon_svg::resolve(name);
let look = Look { dark: dark.unwrap_or_else(|| ctx.global_style().visuals.dark_mode), accent: resolved.accent, vision: crate::theme::vision() };
let cache = ctx.data_mut(|d| d.get_temp_mut_or_insert_with(egui::Id::new("sc_icon_cache"), Cache::default).clone());
let Ok(mut map) = cache.0.lock() else { return };
let key = (resolved.master, look, px, ink);
let key = (resolved.master, look, px, finish);
if let std::collections::hash_map::Entry::Vacant(slot) = map.entry(key) {
let Some(doc) = icon_svg::doc_for(resolved.master, px) else { return };
let Some(pm) = icon_svg::render(doc, look, px) else { return };
let pm = if finish == Finish::Danger { icon_svg::render_tinted(doc, look, px) } else { icon_svg::render(doc, look, px) };
let Some(pm) = pm else { return };
let mut image = egui::ColorImage::from_rgba_premultiplied([px as usize, px as usize], pm.data());
if let Some(ink) = ink {
if let Finish::Ink(ink) = finish {
for pixel in &mut image.pixels {
*pixel = ink.gamma_multiply(f32::from(pixel.a()) / 255.0);
}
@@ -154,4 +189,126 @@ mod tests {
}
theme::set_vision(previous);
}
#[test]
fn per_call_accents_preserve_roles_and_share_the_existing_cache() {
let previous = theme::vision();
for dark in [false, true] {
for vision in ColorVision::ALL {
theme::set_vision(vision);
let ctx = crate::fonts::test_context();
ctx.set_visuals(if dark { egui::Visuals::dark() } else { egui::Visuals::light() });
let mut textures = HashMap::new();
let mut ids = HashMap::new();
let mut silhouette = None;
for accent in [
Some("construction"),
Some("constraint"),
None,
Some("sketch"),
Some("surface"),
Some("form"),
Some("mesh"),
Some("unknown"),
Some(""),
None,
] {
let expected_accent = match accent {
Some("unknown" | "") => icon_svg::resolve("surface_extrude").accent,
Some(name) => icon_svg::accent_index(name),
None => None,
};
let mut output = ctx.run_ui(egui::RawInput::default(), |ui| {
paint_accented(ui.painter(), Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(64.0, 64.0)), "surface_extrude", accent, 0.42);
});
let texture = output
.shapes
.iter()
.find_map(|shape| match &shape.shape {
egui::Shape::Mesh(mesh) => {
assert!(mesh.vertices.iter().all(|vertex| vertex.color == Color32::from_white_alpha(107)));
Some(mesh.texture_id)
}
_ => None,
})
.unwrap();
for (id, deltas) in &output.textures_delta.set {
for delta in deltas {
let egui::ImageData::Color(image) = &delta.image;
if delta.pos.is_none() {
textures.insert(*id, image.clone());
}
}
}
if let Some(previous_id) = ids.insert(expected_accent, texture) {
assert_eq!(texture, previous_id, "repeat and unknown-name fallback reuse the same accent texture");
assert!(!output.textures_delta.set.contains_key(&texture));
}
let image = textures.get(&texture).unwrap();
let look = Look { dark, accent: expected_accent, vision };
for role in ["ink", "passive-2", "passive-3", "active-1", "active-2", "active-3"] {
assert!(image.pixels.contains(&icon_svg::role_colour(role, look)), "{accent:?}/{role}, {dark}/{vision:?}");
}
let alpha: Vec<_> = image.pixels.iter().map(|pixel| pixel.a()).collect();
if let Some(previous) = &silhouette {
assert_eq!(&alpha, previous, "a ramp override must preserve all geometry and knockouts");
} else {
silhouette = Some(alpha);
}
output.textures_delta.clear();
}
let mut output = ctx.run_ui(egui::RawInput::default(), |ui| {
paint_icon(ui.painter(), Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(64.0, 64.0)), "surface_extrude", 1.0);
});
let texture = output
.shapes
.iter()
.find_map(|shape| match &shape.shape {
egui::Shape::Mesh(mesh) => Some(mesh.texture_id),
_ => None,
})
.unwrap();
assert_eq!(
ids.get(&icon_svg::resolve("surface_extrude").accent),
Some(&texture),
"the old painter retains semantic selection and shares the cache"
);
output.textures_delta.clear();
}
}
theme::set_vision(previous);
}
#[test]
fn danger_and_accent_only_textures_do_not_share_a_cache_entry() {
for dark in [false, true] {
let ctx = crate::fonts::test_context();
ctx.set_visuals(if dark { egui::Visuals::dark() } else { egui::Visuals::light() });
let mut textures = HashMap::new();
for danger in [false, true, false, true] {
let mut output = ctx.run_ui(egui::RawInput::default(), |ui| {
let rect = Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(20.0, 20.0));
if danger {
paint_danger(ui.painter(), rect, "delete", 1.0);
} else {
paint_accented(ui.painter(), rect, "delete", Some("constraint"), 1.0);
}
});
let id = output
.shapes
.iter()
.find_map(|shape| match &shape.shape {
egui::Shape::Mesh(mesh) => Some(mesh.texture_id),
_ => None,
})
.unwrap();
if let Some(previous) = textures.insert(danger, id) {
assert_eq!(id, previous, "repeated danger painting reuses its texture");
assert!(!output.textures_delta.set.contains_key(&id));
}
output.textures_delta.clear();
}
assert_ne!(textures[&false], textures[&true], "matching Look values must not mix ordinary gray bins with shaded red bins");
}
}
}
+19
View File
@@ -49,6 +49,17 @@ pub(crate) struct TabAccent {
pub soft: Color32,
}
/// Palette ramp for icons on a surface explicitly accented by its active tab.
pub(crate) fn icon_accent_for_tab(tab: &str) -> Option<&'static str> {
match tab {
"SKETCH" => Some("sketch"),
"SURFACE" => Some("surface"),
"MESH" => Some("mesh"),
"FORM" => Some("form"),
_ => None,
}
}
/// WCAG contrast of two opaque sRGB colours.
pub(crate) fn contrast_ratio(a: Color32, b: Color32) -> f64 {
let luminance = |c: Color32| {
@@ -86,10 +97,15 @@ impl TabAccent {
ctx.data(|d| d.get_temp::<Self>(egui::Id::new("sc_tab_accent"))).unwrap_or_else(|| Self::for_tab(&Tokens::get(), "MODEL"))
}
pub fn current_icon_accent(ctx: &egui::Context) -> Option<&'static str> {
ctx.data(|d| d.get_temp::<Option<&'static str>>(egui::Id::new("sc_tab_icon_accent"))).flatten()
}
pub fn publish(app: &crate::SolveApp, ctx: &egui::Context) {
let accent = Self::for_tab(&Tokens::get(), &app.ui.tab);
ctx.data_mut(|d| {
d.insert_temp(egui::Id::new("sc_tab_accent"), accent);
d.insert_temp(egui::Id::new("sc_tab_icon_accent"), icon_accent_for_tab(&app.ui.tab));
d.insert_temp(egui::Id::new("sc_sketch_open"), app.session.active_sketch.is_some());
d.insert_temp(egui::Id::new("sc_tool_accent"), app.tool.is_some() || app.dialog.is_some());
});
@@ -694,10 +710,13 @@ mod tests {
super::TabAccent::publish(app, &first);
assert_eq!(super::TabAccent::current(&first).color, super::Tokens::get().surface_fill);
assert_eq!(super::TabAccent::current(&second).color, super::Tokens::get().accent);
assert_eq!(super::TabAccent::current_icon_accent(&first), Some("surface"));
assert_eq!(super::TabAccent::current_icon_accent(&second), None);
assert_eq!(first.style_of(egui::Theme::Dark).visuals, before, "dialog OK, checkboxes and status styles must not inherit the tab");
app.ui.tab = "MODEL".into();
super::TabAccent::publish(app, &first);
assert_eq!(super::TabAccent::current(&first).soft, super::Tokens::get().accent_soft);
assert_eq!(super::TabAccent::current_icon_accent(&first), None);
}
#[test]
+9 -5
View File
@@ -85,13 +85,17 @@ impl<'a> Confirm<'a> {
ui.horizontal_top(|ui| {
let diameter = t.control_height + t.space_8;
let (disc, _) = ui.allocate_exact_size(vec2(diameter, diameter), egui::Sense::hover());
let (fill, ink) = match self.tone {
Tone::Warning => (t.warning.gamma_multiply(0.15), t.warning),
Tone::Danger => (t.form_error_fill, t.form_error),
Tone::Info => (t.accent_soft, t.form_primary),
let (fill, accent) = match self.tone {
Tone::Warning => (t.warning.gamma_multiply(0.15), Some("construction")),
Tone::Danger => (t.form_error_fill, Some("constraint")),
Tone::Info => (t.accent_soft, None),
};
ui.painter().circle_filled(disc.center(), diameter / 2.0, fill);
crate::icons::paint_ink(ui.painter(), disc.shrink(t.space_8), self.icon, ink);
if matches!(self.tone, Tone::Danger) {
crate::icons::paint_danger(ui.painter(), disc.shrink(t.space_8), self.icon, 1.0);
} else {
crate::icons::paint_accented(ui.painter(), disc.shrink(t.space_8), self.icon, accent, 1.0);
}
scenario::publish_rect("confirm:disc", disc);
ui.vertical(|ui| {
ui.set_width(ui.available_width().max(0.0));
+131 -1
View File
@@ -95,7 +95,9 @@ const ELEMENTS: &[Element] = &[
}),
element!("radial_menu", |ui, _| {
let (r, _) = ui.allocate_exact_size(vec2(360.0, 360.0), egui::Sense::hover());
let app = crate::test_support::sample_app();
let mut app = crate::test_support::sample_app();
app.ui.tab = "SURFACE".into();
crate::theme::TabAccent::publish(&app, ui.ctx());
radial_menu(ui, r.center(), &crate::context_menu::radial_items(&app), Some(3));
}),
element!("workspace_menu", |ui, _| {
@@ -1162,3 +1164,131 @@ fn command_search_board_in_both_themes() {
}
crate::theme::set_dark(previous);
}
/// Exercise the actual surface painters, including deliberately shared artwork whose
/// own accent differs from its tone or tab.
#[test]
fn confirm_radial_and_menu_danger_keep_multitone_artwork() {
let previous = crate::theme::is_dark();
for dark in [false, true] {
crate::theme::set_dark(dark);
let mut cases = vec![
("warning", "extrude", "MODEL", Some("construction"), 20),
("danger", "extrude", "MODEL", Some("constraint"), 20),
("info", "extrude", "MODEL", None, 20),
("warning", "status_warning", "MODEL", Some("construction"), 20),
("danger", "delete", "MODEL", Some("constraint"), 20),
("danger_menu", "delete", "MODEL", Some("constraint"), 16),
("info", "surface_extrude", "MODEL", None, 20),
];
for (tab, ramp) in [
("SKETCH", Some("sketch")),
("SURFACE", Some("surface")),
("MESH", Some("mesh")),
("FORM", Some("form")),
("MODEL", None),
("SHEET METAL", None),
("RENDER", None),
("unknown", None),
] {
for surface in ["radial", "radial_hover"] {
cases.push((surface, "extrude", tab, ramp, 24));
}
}
let mut dominant_accents: std::collections::HashMap<&str, std::collections::HashSet<egui::Color32>> = std::collections::HashMap::new();
for (surface, icon, tab, ramp, side) in cases {
let ctx = crate::fonts::test_context();
ctx.set_visuals(if dark { egui::Visuals::dark() } else { egui::Visuals::light() });
let mut app = crate::SolveApp::new(Default::default(), Default::default());
app.ui.tab = tab.into();
crate::theme::TabAccent::publish(&app, &ctx);
let bounds = egui::Rect::from_min_size(egui::Pos2::ZERO, vec2(600.0, 360.0));
let mut output = ctx.run_ui(egui::RawInput { screen_rect: Some(bounds), ..Default::default() }, |ui| {
ui.painter().rect_filled(bounds, 0.0, Tokens::get().panel);
match surface {
"radial" | "radial_hover" => {
radial_menu(
ui,
egui::pos2(180.0, 180.0),
&[crate::context_menu::Item::action("solid.extrude", "Extrude", icon)],
(surface == "radial_hover").then_some(0),
);
}
"danger_menu" => {
let mut item = MenuItem::new("gallery:danger", "Delete", icon);
item.danger = true;
item.show(ui);
}
_ => {
let tone = match surface {
"warning" => Tone::Warning,
"danger" => Tone::Danger,
_ => Tone::Info,
};
Confirm::new(ui.id().with("confirm"), icon, "Confirm").tone(tone).content(ui, true, |_| {});
}
}
});
let image = output
.textures_delta
.set
.values()
.flatten()
.find_map(|delta| match &delta.image {
egui::ImageData::Color(image) if image.size == [side, side] => Some(image),
_ => None,
})
.expect("the surface must upload its icon texture");
let colours: std::collections::HashSet<_> = image.pixels.iter().filter(|pixel| pixel.a() == 255).copied().collect();
assert!(colours.len() >= 2, "{surface}/{icon}/{tab}, dark={dark}: opaque artwork is a silhouette");
let resolved = crate::icon_svg::resolve(icon);
assert!(!resolved.placeholder, "{icon} needs a master");
let look = crate::icon_svg::Look { dark, accent: ramp.and_then(crate::icon_svg::accent_index), vision: crate::theme::vision() };
let doc = crate::icon_svg::doc_for(resolved.master, side as u32).unwrap();
let expected = if matches!(surface, "danger" | "danger_menu") {
crate::icon_svg::render_tinted(doc, look, side as u32)
} else {
crate::icon_svg::render(doc, look, side as u32)
}
.unwrap();
if icon == "delete" {
assert!(colours.len() >= 3, "{surface}, dark={dark}: preserve the lid, faces and outline colours");
let dominant = colours.iter().max_by_key(|colour| image.pixels.iter().filter(|pixel| *pixel == *colour).count()).unwrap();
assert!(
dominant.r() > dominant.g() && dominant.r() > dominant.b(),
"{surface}, dark={dark}: dominant bin colour must be red, got {dominant:?}"
);
}
assert_eq!(
image.as_ref(),
&egui::ColorImage::from_rgba_premultiplied([side, side], expected.data()),
"{surface}/{tab}: preserve roles with {ramp:?}"
);
if icon == "extrude" {
let dominant = ["active-1", "active-2", "active-3"]
.map(|role| {
let colour = crate::icon_svg::role_colour(role, look);
(image.pixels.iter().filter(|pixel| **pixel == colour).count(), colour)
})
.into_iter()
.max_by_key(|(count, _)| *count)
.unwrap();
assert!(dominant.0 > 0, "{surface}/{tab}: missing accent pixels");
let group = if matches!(surface, "warning" | "danger" | "info") { "confirm" } else { surface };
dominant_accents.entry(group).or_default().insert(dominant.1);
}
if let Ok(dir) = std::env::var("SOLIDCRAFT_ICON_SURFACE_EVIDENCE") {
let mut textures = std::collections::HashMap::new();
super::checks::tests::textures_update(&mut textures, &output.textures_delta);
let capture = super::checks::tests::raster(&ctx, output.shapes.clone(), output.pixels_per_point, bounds, &textures);
std::fs::create_dir_all(&dir).unwrap();
capture.save(std::path::Path::new(&dir).join(format!("{surface}-{icon}-{tab}-{}.png", if dark { "dark" } else { "light" }))).unwrap();
}
output.textures_delta.clear();
}
for (group, count) in [("confirm", 3), ("radial", 5), ("radial_hover", 5)] {
assert_eq!(dominant_accents[group].len(), count, "{group}, dark={dark}: dominant accent pixels must differ across mappings");
}
}
crate::theme::set_dark(previous);
}
+3 -1
View File
@@ -199,7 +199,9 @@ impl<'a> MenuItem<'a> {
} else if let Some(color) = self.swatch {
painter.rect(icon, t.radius_sm, color, Stroke::new(1.0, t.control_border), egui::StrokeKind::Inside);
} else if !self.icon.is_empty() {
if self.danger || hot {
if self.danger {
icons::paint_danger(&painter, icon, self.icon, 1.0);
} else if hot {
icons::paint_ink(&painter, icon, self.icon, dim);
} else {
icons::paint_icon(&painter, icon, self.icon, 1.0);
+11 -4
View File
@@ -88,6 +88,7 @@ fn paint_sector(p: &egui::Painter, center: Pos2, k: usize, fill: Color32, stroke
pub(crate) fn radial_menu(ui: &mut Ui, center: Pos2, items: &[Item], hot: Option<usize>) -> Option<Item> {
let t = Tokens::get();
let accent = crate::theme::TabAccent::current(ui.ctx());
let mut picked = None;
for (k, item) in items.iter().take(8).enumerate() {
let enabled = item.enabled && ui.is_enabled();
@@ -100,16 +101,22 @@ pub(crate) fn radial_menu(ui: &mut Ui, center: Pos2, items: &[Item], hot: Option
&painter,
center,
k,
if lit { t.accent_soft } else { t.dialog_body },
Stroke::new(if lit { 1.6 } else { 1.0 }, if lit { t.form_primary } else { t.dialog_border }),
if lit { accent.soft } else { t.dialog_body },
Stroke::new(if lit { 1.6 } else { 1.0 }, if lit { accent.color } else { t.dialog_border }),
);
let a = -FRAC_PI_2 + k as f32 * FRAC_PI_4;
let at = center + unit(a) * 104.0;
let target = Rect::from_center_size(at, vec2(t.space_24 * 2.0 + t.space_12, t.space_24 + t.space_16 + t.space_2));
let response = ui.interact(target, ui.id().with(("radial", k)), Sense::hover());
crate::scenario::publish_target(&format!("radial:{}", item.id), target);
let ink = if lit { t.form_primary } else { t.form_ink };
crate::icons::paint_ink(&painter, Rect::from_center_size(at - vec2(0.0, t.space_6), vec2(t.space_24, t.space_24)), &item.icon, ink);
let ink = if lit { accent.ink } else { t.form_ink };
crate::icons::paint_accented(
&painter,
Rect::from_center_size(at - vec2(0.0, t.space_6), vec2(t.space_24, t.space_24)),
&item.icon,
crate::theme::TabAccent::current_icon_accent(ui.ctx()),
1.0,
);
let label = crate::i18n::tr_label(&item.label);
let mut job = egui::text::LayoutJob::simple_singleline(label.to_string(), FontId::proportional(t.font_small), ink);
job.wrap.max_width = 74.0;
+15 -2
View File
@@ -31,7 +31,9 @@ preferences, manager cards, prompts, context menus and the sketch palette. Impor
existing window behavior. Empty action labels omit the footer.
- `Confirm` is an input-blocking modal using the same card frame and footer controls.
It shows a 36 pt icon disc in warning, danger or info tone, a title, caller-supplied
message and optional monospace `detail`, above a 52 pt footer. `actions(primary, cancel, left_ghost)`
message and optional monospace `detail`, above a 52 pt footer. Glyphs use the construction
ramp for warning, the shared shaded danger treatment for danger, and base blue for info;
the disc keeps its tint. `actions(primary, cancel, left_ghost)`
places the optional third action at the left. Danger uses `form_error` with a
contrast-selected on-colour; other primaries use blue. Enter invokes the selected
answer (primary by default) when valid; Esc cancels. It retains close, answer and
@@ -57,7 +59,7 @@ table. Panel/Window/Confirm compositions also have dedicated geometry and intera
| --- | --- | --- |
| search: `CommandSearch`, `MenuItem::search_row` | Ribbon search composition: 40 pt bounded field, magnifier and S/Esc keycap, 38 pt two-line menu row with 26 pt icon tile, accent bold substring, path, shortcut/kind keycap, counts, JSON detail box and footer. The ordinary 30 pt menu row cannot fit a second line; this variant keeps its enabled/selected states and scenario IDs. Ranking and dispatch stay with the caller. | `form_card_width × 2 − space_8` (520 pt), `control_height`, `space_2/3/4/6/8/10/12/16/24`, `radius_xl/control_radius`, `control_fill`, `dialog_body/footer/rule/border`, `form_ink/dim/primary/error/error_fill/success/success_fill`, `selected_ink`, `accent_soft`, typography |
| menu: `Menu`, `MenuItem` | Shared popup, 30 pt rows, 28 pt icon column, clipped labels, right-aligned mono shortcuts, submenu chevrons, checked/unchecked and document swatches, inert 40% disabled rows and danger ink; headings and separators; ribbon drag/pin targets retained | `dialog_body/border/rule`, `radius_xl`, `control_height/radius`, `form_ink/dim/primary/error`, `accent_soft`, typography and spacing |
| radial: `radial_menu` | Eight rounded annular sectors, parallel 4 pt gaps, 9 pt circular corner joins, accent hover, centre label/key; existing hold/flick/release dispatch | `dialog_body/border`, `form_ink/dim/primary`, `accent_soft`, font/spacing tokens |
| radial: `radial_menu` | Eight rounded annular sectors, parallel 4 pt gaps, 9 pt circular corner joins, tab-accent artwork and hover, centre label/key; existing hold/flick/release dispatch | `dialog_body/border`, `form_ink/dim`, `TabAccent`, icon palette, font/spacing tokens |
| panel: `Window`, `WindowPage` | Shared card frame, header, optional page list, bounded content and footer with a left action | `form_header/footer_height`, `form_card_width`, `form_label_width`, `control_height`, `dialog_footer/rule`, `selected_bg/ink`, spacing |
| confirm: `Confirm`, `Tone` | Modal warning/danger/info, title/message, mono detail and ghost/cancel/primary actions | `warning`, `form_error/fill`, `accent_soft`, `form_primary`, `on_accent`, `tab_on_fill_dark`, `font_subtitle`, spacing |
| metrics: `row_height`, `table_row_height`, `header_height` | Shared control/header heights | `control_height`, `space_8`, `form_header_height` |
@@ -131,6 +133,17 @@ footer(ui, "OK", "Cancel", valid, Footer { apply: Some("Apply"), ..Default::defa
text(ui, report, Text::Report("validation", invalid));
```
Icon surfaces that explicitly choose a palette ramp use `icons::paint_accented`.
`None` selects base blue, while unknown names retain the icon's semantic accent.
Only active roles change: ink/line outlines, passive faces, guides and knockouts keep
normal artwork colours. Existing icon painters retain their semantic-accent behaviour.
Danger menu items and danger confirmation glyphs both use `icons::paint_danger`.
It additionally maps passive-1/2/3 faces to constraint active-1/2/3, retaining the
shading steps, ink outlines, handle and transparent slat details. The cache distinguishes
this whole-glyph treatment from ordinary accent selection and monochrome ink masks.
Radial icons follow the active tab (Sketch, Surface, Mesh, Form; other tabs use base blue)
in both normal and hovered sectors; the hovered background retains its tab tint.
## Extending and checking the kit
Add one implementation, document its tokens/options here, re-export it through