Skip to content

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

Theme: the viewport keeps the previous colours until the camera moves (#5802) (#5835)

Homero Thompson8d63a9f4cbd8
diff --git a/crates/gpu/src/view.rs b/crates/gpu/src/view.rs
index d08ca79aa1..5126930aa9 100644
--- a/crates/gpu/src/view.rs
+++ b/crates/gpu/src/view.rs
@@ -2125,8 +2125,9 @@ fn can_reuse(ss_ready: bool, cached: Option<u64>, key: u64) -> bool {
}
/// Everything the drawn picture depends on: the scene keys and camera, the viewport's size, the
-/// section, images, analysis, accessibility map and ambient occlusion. The same key draws the
-/// same picture (pipelines and shaders are fixed for the renderer).
+/// section, images, analysis, accessibility map, ambient occlusion and the theme's hover and
+/// selection tints. The same key draws the same picture (pipelines and shaders are fixed for the
+/// renderer).
fn frame_key(cb: &Frame) -> u64 {
use std::hash::Hash as _;
let mut h = std::collections::hash_map::DefaultHasher::new();
@@ -2144,6 +2145,10 @@ fn frame_key(cb: &Frame) -> u64 {
cb.cap.map(f32::to_bits).hash(&mut h);
cb.analysis.map(f32::to_bits).hash(&mut h);
cb.analysis_colors.map(f32::to_bits).hash(&mut h);
+ // The theme's hover and selection tints: a theme change draws the frame again, so the
+ // picture cached under the previous theme's colours is not shown (#5802).
+ cb.hover_tint.map(f32::to_bits).hash(&mut h);
+ cb.selection_tint.map(f32::to_bits).hash(&mut h);
cb.outline.hash(&mut h);
cb.ao_radius.to_bits().hash(&mut h);
cb.ssaa.to_bits().hash(&mut h);
@@ -2964,6 +2969,10 @@ mod tests {
("section cap", key(|f| f.cap[0] = 0.5)),
("analysis", key(|f| f.analysis[0] = 1.0)),
("analysis colours", key(|f| f.analysis_colors[0] = 1.0)),
+ // The theme's hover and selection tints: a theme change draws the frame again, so
+ // the picture cached under the previous theme's colours is not shown (#5802).
+ ("hover tint", key(|f| f.hover_tint = [0.1, 0.2, 0.3])),
+ ("selection tint", key(|f| f.selection_tint = [0.4, 0.5, 0.6])),
("outline", key(|f| f.outline = true)),
("ambient occlusion", key(|f| f.ao_radius = 1.0)),
("supersampling", key(|f| f.ssaa = 2.0)),
diff --git a/crates/ui-egui/src/theme.rs b/crates/ui-egui/src/theme.rs
index dd9989e7a1..aa111750b2 100644
--- a/crates/ui-egui/src/theme.rs
+++ b/crates/ui-egui/src/theme.rs
@@ -858,6 +858,9 @@ pub fn apply(ctx: &egui::Context) {
s.spacing.item_spacing = egui::vec2(t.space_6, t.space_4);
s.spacing.button_padding = egui::vec2(t.space_6, t.space_3);
});
+ // The new visuals are painted on the next pass: without a repaint request the widgets
+ // keep the previous theme's colours until some other event schedules a pass (#5802).
+ ctx.request_repaint();
}
#[cfg(test)]
@@ -895,6 +898,45 @@ mod tests {
assert_eq!(Tokens::outset_radius(6.0, 3.0), 9.0);
}
+ /// A theme change repaints: egui paints the new visuals on the next pass, so without a
+ /// repaint request the widgets keep the previous theme's colours until another event
+ /// schedules a pass (#5802).
+ #[test]
+ fn applying_a_theme_asks_for_a_repaint_with_the_new_visuals() {
+ use std::sync::atomic::{AtomicUsize, Ordering};
+ let ctx = egui::Context::default();
+ // The integration hook fires on every repaint request, whoever asked for it.
+ let requests = std::sync::Arc::new(AtomicUsize::new(0));
+ let counter = std::sync::Arc::clone(&requests);
+ ctx.set_request_repaint_callback(move |_| {
+ counter.fetch_add(1, Ordering::Relaxed);
+ });
+ // Let egui's own startup repaints settle: the context must be idle before the
+ // theme changes, so the only repaint left is the one the theme asks for.
+ let mut settled = false;
+ for _ in 0..8 {
+ ctx.run_ui(egui::RawInput::default(), |_| {}).textures_delta.clear();
+ if !ctx.has_requested_repaint() {
+ settled = true;
+ break;
+ }
+ }
+ assert!(settled, "the context must be idle before the theme changes");
+ let before = requests.load(Ordering::Relaxed);
+ let previous = super::is_dark();
+ super::set_dark(!previous);
+ let dark = super::is_dark();
+ let expected = super::visuals(dark);
+ // The theme is applied outside a pass: inside one egui schedules repaints of its
+ // own, and the request of the theme would hide among them.
+ super::apply(&ctx);
+ super::set_dark(previous);
+ assert!(requests.load(Ordering::Relaxed) > before, "a theme change must ask for a repaint");
+ assert!(ctx.has_requested_repaint(), "a theme change must leave a repaint pending");
+ let theme = if dark { egui::Theme::Dark } else { egui::Theme::Light };
+ assert_eq!(ctx.style_of(theme).visuals, expected, "the new theme's visuals must be in place");
+ }
+
#[test]
fn file_view_foreground_pairs_hold_small_text_contrast_without_changing_accent() {
for dark in [false, true] {