Skip to content

SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.

Show scroll arrows on the theme row when more themes are hidden (#5846)

Nathan Dane7cea14643828
diff --git a/assets/locales/en.json b/assets/locales/en.json
index aec612a4bf..68d74879db 100644
--- a/assets/locales/en.json
+++ b/assets/locales/en.json
@@ -318,7 +318,6 @@
"Mitre": "Mitre",
"Model Parameters": "Model Parameters",
"Modeled": "Modeled",
- "More themes": "More themes",
"More toolbar panels": "More toolbar panels",
"Motion": "Motion",
"Mouse gestures": "Mouse gestures",
@@ -395,7 +394,6 @@
"Preview": "Preview",
"Preview Row": "Preview Row",
"Preview leaves the current design unchanged.": "Preview leaves the current design unchanged.",
- "Previous themes": "Previous themes",
"Profile / Edges": "Profile / Edges",
"Profiles or curves": "Profiles or curves",
"Profiles/Curves": "Profiles/Curves",
diff --git a/assets/locales/ja.json b/assets/locales/ja.json
index e779379c24..6834c895b6 100644
--- a/assets/locales/ja.json
+++ b/assets/locales/ja.json
@@ -318,7 +318,6 @@
"Mitre": "留め継ぎ",
"Model Parameters": "モデルパラメータ",
"Modeled": "モデル化済み",
- "More themes": "その他のテーマ",
"More toolbar panels": "その他のツールバーパネル",
"Motion": "モーション",
"Mouse gestures": "マウス ジェスチャ",
@@ -395,7 +394,6 @@
"Preview": "プレビュー",
"Preview Row": "行をプレビュー",
"Preview leaves the current design unchanged.": "プレビューは現在のデザインを変更しません。",
- "Previous themes": "前のテーマ",
"Profile / Edges": "プロファイル / エッジ",
"Profiles or curves": "プロファイルまたは曲線",
"Profiles/Curves": "プロファイル/曲線",
diff --git a/assets/locales/zh.json b/assets/locales/zh.json
index e916025852..2349d2b0aa 100644
--- a/assets/locales/zh.json
+++ b/assets/locales/zh.json
@@ -318,7 +318,6 @@
"Mitre": "斜接",
"Model Parameters": "模型参数",
"Modeled": "已建模",
- "More themes": "更多主题",
"More toolbar panels": "更多工具栏面板",
"Motion": "运动",
"Mouse gestures": "鼠标手势",
@@ -395,7 +394,6 @@
"Preview": "预览",
"Preview Row": "预览行",
"Preview leaves the current design unchanged.": "预览不会更改当前设计。",
- "Previous themes": "上一组主题",
"Profile / Edges": "轮廓 / 边",
"Profiles or curves": "轮廓或曲线",
"Profiles/Curves": "轮廓/曲线",
diff --git a/crates/ui-egui/src/prefs.rs b/crates/ui-egui/src/prefs.rs
index a36f29f343..ce039eb483 100644
--- a/crates/ui-egui/src/prefs.rs
+++ b/crates/ui-egui/src/prefs.rs
@@ -3343,24 +3343,6 @@ mod tests {
/// next frame draws with their colours (dark following the base), an export gives the theme
/// back complete, imported themes are saved with the preferences, Remove falls back to the
/// base and Cancel takes an import back.
- /// #6161: the theme strip shows a chevron at each end with more themes past it; a click
- /// scrolls that way.
- #[test]
- fn the_theme_strip_shows_where_more_themes_are() {
- use serde_json::json;
- let mut h = crate::scenario::Harness::new();
- h.call("ui.prefs", json!({"open": "Interface"}));
- h.frames(4);
- let shown = |name: &str| crate::scenario::handle_at(name).is_some();
- assert!(shown("theme_rail:next"), "more themes than fit: a chevron on the right");
- assert!(!shown("theme_rail:previous"), "nothing before the first");
- let first = crate::scenario::handle_at("prefs:theme:light").unwrap();
- h.step(&json!({"click": {"handle": "theme_rail:next"}})).unwrap();
- h.frames(4);
- assert!(shown("theme_rail:previous"), "scrolled: a chevron on the left too");
- assert!(crate::scenario::handle_at("prefs:theme:light").is_none_or(|p| p.x < first.x), "the strip moved");
- }
-
#[test]
fn system_theme_tile_export_uses_os_brightness_without_selecting_it() {
let mut app = SolveApp::new(solidcraft_engine::Session::default(), Default::default());
diff --git a/crates/ui-egui/src/ui_kit/layout_tests.rs b/crates/ui-egui/src/ui_kit/layout_tests.rs
index b6fb0e4882..8c7af64807 100644
--- a/crates/ui-egui/src/ui_kit/layout_tests.rs
+++ b/crates/ui-egui/src/ui_kit/layout_tests.rs
@@ -4,6 +4,89 @@ use crate::ui_kit::*;
use crate::{scenario, theme::Tokens};
use egui::Ui;
+#[test]
+fn theme_rail_cues_follow_hidden_content() {
+ use crate::ui_kit::preferences::theme_rail_cues;
+ assert_eq!(theme_rail_cues(0.0, 0.0), (false, false));
+ assert_eq!(theme_rail_cues(0.0, 300.0), (false, true));
+ assert_eq!(theme_rail_cues(150.0, 300.0), (true, true));
+ assert_eq!(theme_rail_cues(300.0, 300.0), (true, false));
+ assert_eq!(theme_rail_cues(0.25, 0.5), (false, false));
+}
+
+#[test]
+fn theme_rail_arrows_scroll_one_card_and_hide_at_ends() {
+ let ctx = crate::fonts::test_context();
+ let t = Tokens::get();
+ let width = t.form_label_width + t.space_24 + t.space_6;
+ let draw = |ui: &mut Ui| {
+ theme_rail(
+ ui,
+ |ui| {
+ for i in 0..3 {
+ let (rect, _) = ui.allocate_exact_size(egui::vec2(width, 80.0), egui::Sense::click());
+ scenario::publish_target(&format!("test:theme:{i}"), rect);
+ }
+ },
+ |_| {},
+ );
+ };
+ for _ in 0..3 {
+ frame(&ctx, vec![], draw);
+ }
+ assert!(scenario::rect_of("prefs:theme_rail:Scroll left").is_none());
+ let start = scenario::rect_of("test:theme:0").unwrap().left();
+ let right = scenario::handle_at("prefs:theme_rail:Scroll right").unwrap();
+ assert!((right.y - scenario::rect_of("test:theme:0").unwrap().center().y).abs() < 1.0);
+ frame(&ctx, pointer(right, true), draw);
+ frame(&ctx, pointer(right, false), draw);
+ frame(&ctx, vec![], draw);
+ let after = scenario::rect_of("test:theme:0").unwrap().left();
+ assert!((start - after - width - t.space_8).abs() < 1.0);
+ assert!(scenario::rect_of("prefs:theme_rail:Scroll left").is_some());
+ for _ in 0..4 {
+ if let Some(pos) = scenario::handle_at("prefs:theme_rail:Scroll right") {
+ frame(&ctx, pointer(pos, true), draw);
+ frame(&ctx, pointer(pos, false), draw);
+ frame(&ctx, vec![], draw);
+ }
+ }
+ assert!(scenario::rect_of("prefs:theme_rail:Scroll right").is_none());
+ for _ in 0..4 {
+ if let Some(pos) = scenario::handle_at("prefs:theme_rail:Scroll left") {
+ frame(&ctx, pointer(pos, true), draw);
+ frame(&ctx, pointer(pos, false), draw);
+ frame(&ctx, vec![], draw);
+ }
+ }
+ assert!(scenario::rect_of("prefs:theme_rail:Scroll left").is_none());
+}
+
+#[test]
+fn theme_rail_chevrons_have_no_idle_box_and_show_hover_and_focus() {
+ let ctx = crate::fonts::test_context();
+ let t = Tokens::get();
+ let rect = egui::Rect::from_min_size(egui::pos2(20.0, 20.0), egui::vec2(t.control_height, t.control_height));
+ let draw = |events| {
+ crate::test_support::frame(&ctx, egui::RawInput { events, focused: true, ..Default::default() }, |ui| {
+ crate::ui_kit::preferences::theme_rail_arrow(ui, rect, 1.0, "Scroll right");
+ })
+ };
+ let idle = draw(vec![]);
+ assert!(!idle.shapes.iter().any(|s| matches!(s.shape, egui::Shape::Rect(_))));
+ assert!(!idle.shapes.iter().any(|s| matches!(s.shape, egui::Shape::Circle(_))), "no backing until hovered");
+ let hover = draw(vec![egui::Event::PointerMoved(rect.center())]);
+ assert_eq!(hover.platform_output.cursor_icon, egui::CursorIcon::PointingHand);
+ assert!(hover.shapes.iter().any(|s| matches!(&s.shape, egui::Shape::Circle(c) if c.fill == t.hover && c.radius == rect.width() / 2.0)));
+ draw(pointer(rect.center(), true));
+ draw(pointer(rect.center(), false));
+ let focus = draw(vec![egui::Event::PointerMoved(egui::pos2(200.0, 200.0))]);
+ assert!(
+ !focus.shapes.iter().any(|s| matches!(&s.shape, egui::Shape::Rect(r) if r.stroke.color == t.form_primary)),
+ "a mouse click leaves no outline"
+ );
+}
+
#[test]
fn row_height_and_label_column_are_fixed_for_long_labels_and_expressions() {
let ctx = crate::fonts::test_context();
diff --git a/crates/ui-egui/src/ui_kit/preferences.rs b/crates/ui-egui/src/ui_kit/preferences.rs
index e8952b60d6..3608231479 100644
--- a/crates/ui-egui/src/ui_kit/preferences.rs
+++ b/crates/ui-egui/src/ui_kit/preferences.rs
@@ -100,7 +100,6 @@ pub(crate) fn settings_pair<R>(ui: &mut Ui, controls: impl FnOnce(&mut Ui) -> R,
/// A horizontally scrollable, draggable tile rail with its import action pinned outside it.
/// The hidden scrollbar never reserves vertical space; a vertical wheel also moves the rail.
-/// An end with more tiles past it shows a chevron that scrolls a page that way (#6161).
pub(crate) fn theme_rail(ui: &mut Ui, tiles: impl FnOnce(&mut Ui), import: impl FnOnce(&mut Ui)) {
let t = Tokens::get();
let action_width = t.form_label_width + t.space_24 + t.space_6;
@@ -109,7 +108,9 @@ pub(crate) fn theme_rail(ui: &mut Ui, tiles: impl FnOnce(&mut Ui), import: impl
ui.spacing_mut().item_spacing.x = t.space_8;
ui.allocate_ui_with_layout(vec2(rail_width, 0.0), egui::Layout::top_down(egui::Align::Min), |ui| {
ui.style_mut().always_scroll_the_only_direction = true;
- let out = egui::ScrollArea::horizontal()
+ // This rail paints its own fully opaque, page-coloured edge cues.
+ ui.spacing_mut().scroll.fade.strength = 0.0;
+ let mut rail = egui::ScrollArea::horizontal()
.id_salt("settings_theme_rail")
.max_width(rail_width)
.auto_shrink([false, true])
@@ -121,43 +122,74 @@ pub(crate) fn theme_rail(ui: &mut Ui, tiles: impl FnOnce(&mut Ui), import: impl
tiles(ui);
});
});
- rail_arrows(ui, out.id, out.state, out.inner_rect, out.content_size);
+ let max_offset = (rail.content_size.x - rail.inner_rect.width()).max(0.0);
+ let (left, right) = theme_rail_cues(rail.state.offset.x, max_offset);
+ let arrow_size = t.control_height.min(rail.inner_rect.width() / 2.0);
+ for (visible, direction, label) in [(left, -1.0, "Scroll left"), (right, 1.0, "Scroll right")] {
+ if !visible || arrow_size <= 0.0 {
+ continue;
+ }
+ // The horizontal host starts with zero requested height; use the measured
+ // cards' height rather than the scroll area's initial viewport height.
+ let rail_rect = Rect::from_min_size(rail.inner_rect.min, vec2(rail.inner_rect.width(), rail.content_size.y));
+ theme_rail_fade(ui, rail_rect, direction);
+ let center = pos2(
+ if direction < 0.0 { rail.inner_rect.left() + arrow_size / 2.0 } else { rail.inner_rect.right() - arrow_size / 2.0 },
+ rail.inner_rect.top() + rail.content_size.y / 2.0,
+ );
+ let rect = Rect::from_center_size(center, vec2(arrow_size, t.control_height));
+ if theme_rail_arrow(ui, rect, direction, label).clicked() {
+ rail.state.offset.x = (rail.state.offset.x + direction * (action_width + t.space_8)).clamp(0.0, max_offset);
+ rail.state.store(ui.ctx(), rail.id);
+ ui.ctx().request_repaint();
+ }
+ }
});
ui.allocate_ui_with_layout(vec2(action_width, 0.0), egui::Layout::top_down(egui::Align::Min), import);
});
}
-/// The theme rail's chevrons: one at each end with tiles past it, over the tiles there.
-fn rail_arrows(ui: &mut Ui, id: egui::Id, mut state: egui::scroll_area::State, view: Rect, content: egui::Vec2) {
+/// Ignore subpixel rounding at either end so cues do not flicker on a fully visible rail.
+pub(super) fn theme_rail_cues(offset: f32, max_offset: f32) -> (bool, bool) {
+ (offset > 0.5, max_offset - offset > 0.5)
+}
+
+/// Preferences pages inherit the Window card's opaque dialog_body surface.
+/// Paint after the cards and before the arrows so the outer edge fully conceals content.
+fn theme_rail_fade(ui: &Ui, rail: Rect, direction: f32) {
let t = Tokens::get();
- let room = (content.x - view.width()).max(0.0);
- // Halfway down the tiles (the area itself may report less height than they take).
- let middle = view.top() + content.y.max(view.height()) / 2.0;
- let size = t.control_height;
- for (more, next) in [(state.offset.x > 0.5, false), (state.offset.x < room - 0.5, true)] {
- if !more {
- continue;
- }
- let x = if next { view.right() - size / 2.0 } else { view.left() + size / 2.0 };
- let r = Rect::from_center_size(pos2(x, middle), vec2(size, size));
- let label = crate::i18n::tr_label(if next { "More themes" } else { "Previous themes" });
- let response = ui.interact(r, id.with(("rail_arrow", next)), Sense::click());
- ui.painter().rect_filled(r, t.control_radius, if response.hovered() { t.hover } else { t.control_fill });
- ui.painter().rect_stroke(r, t.control_radius, Stroke::new(1.0, t.control_border), egui::StrokeKind::Inside);
- let icon = r.shrink(t.form_icon_inset);
- if next {
- crate::icons::paint_ink(ui.painter(), icon, "chevron_right", t.form_ink);
- } else {
- crate::icons::paint_ink_mirrored(ui.painter(), icon, "chevron_right", t.form_ink);
- }
- response.widget_info(|| egui::WidgetInfo::labeled(egui::WidgetType::Button, ui.is_enabled(), label));
- scenario::publish_target(if next { "theme_rail:next" } else { "theme_rail:previous" }, r);
- if response.on_hover_cursor(egui::CursorIcon::PointingHand).on_hover_text(label).clicked() {
- let page = (view.width() * 0.8).max(size);
- state.offset.x = (state.offset.x + if next { page } else { -page }).clamp(0.0, room);
- state.store(ui.ctx(), id);
- }
+ let width = (t.space_24 * 2.0 + t.space_8).min(rail.width() / 2.0);
+ let outer = if direction < 0.0 { rail.left() } else { rail.right() };
+ let inner = outer - direction * width;
+ let mut mesh = egui::Mesh::default();
+ for (x, color) in [(outer, t.dialog_body), (inner, Color32::TRANSPARENT)] {
+ mesh.colored_vertex(pos2(x, rail.top()), color);
+ mesh.colored_vertex(pos2(x, rail.bottom()), color);
+ }
+ mesh.add_triangle(0, 1, 2);
+ mesh.add_triangle(2, 1, 3);
+ ui.painter().with_clip_rect(ui.clip_rect().intersect(rail)).add(mesh);
+}
+
+pub(super) fn theme_rail_arrow(ui: &mut Ui, rect: Rect, direction: f32, label: &str) -> Response {
+ let t = Tokens::get();
+ let response = ui.interact(rect, ui.make_persistent_id(("theme_rail_arrow", label)), Sense::click());
+ if response.hovered() {
+ ui.painter().circle_filled(rect.center(), rect.width().min(rect.height()) / 2.0, t.hover);
+ }
+ let ink = if response.hovered() { t.form_ink } else { t.form_ink.gamma_multiply(0.65) };
+ let icon = Rect::from_center_size(rect.center(), vec2(t.space_16, t.space_16));
+ if direction < 0.0 {
+ crate::icons::paint_ink_mirrored(ui.painter(), icon, "chevron_right", ink);
+ } else {
+ crate::icons::paint_ink(ui.painter(), icon, "chevron_right", ink);
+ }
+ if response.has_focus() {
+ ui.painter().rect_stroke(rect, t.control_radius, Stroke::new(t.space_2, t.form_primary), egui::StrokeKind::Inside);
}
+ response.widget_info(|| egui::WidgetInfo::labeled(egui::WidgetType::Button, ui.is_enabled(), crate::i18n::tr_label(label)));
+ scenario::publish_target(&format!("prefs:theme_rail:{label}"), rect);
+ response.on_hover_cursor(egui::CursorIcon::PointingHand).on_hover_text(crate::i18n::tr_label(label))
}
/// Dashed import tile matches the swatch tiles, while remaining permanently visible.