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

* claim: #5802

* fix: repaint on a theme change and key the frame cache on the theme tints (#5802)

theme::apply asks for a repaint, so the new visuals are painted on the next pass instead of waiting for another event to schedule one. The gpu frame cache key now includes the theme's hover and selection tints, so a picture cached under the previous theme's colours is not reused.

* test(ui): settle egui's startup repaints before asserting the theme's repaint (#5802)

* test(ui): name the call site that asks for the theme's repaint (#5802)

* test(ui): apply the theme outside a pass so its repaint request stands alone (#5802)
This commit is contained in:
Homero Thompson authored and GitHub committed 2026-10-25 02:46:41 +00:00
1 parent a150822d9b
commit 8d63a9f4cb
2 files changed
+53 -2

No files matched your search

+11 -2
View File
@@ -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)),
+42
View File
@@ -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] {