Skip to content

PhotoCraft: An open-source, photo editor written by scratch in pure Rust

Canvas: themes without a dot pattern draw no dots texture (#4542) (#5093)

Michael Higgins42c5cc64be03
diff --git a/crates/ui-egui/src/canvas.rs b/crates/ui-egui/src/canvas.rs
index 676d06807..11adb2c79 100644
--- a/crates/ui-egui/src/canvas.rs
+++ b/crates/ui-egui/src/canvas.rs
@@ -2575,9 +2575,10 @@ pub fn fmt_zoom(pct: f32) -> String {
if (pct - pct.round()).abs() < 0.05 { format!("{}", pct.round() as i64) } else { format!("{pct:.1}") }
}
-/// Repeating dot-grid texture for the canvas surround.
+/// Repeating dot-grid texture for the canvas surround. A theme whose dots are its canvas colour
+/// has no pattern to show, so it gets no texture at all rather than an invisible one (#4542).
fn dots(ctx: &egui::Context, t: &crate::theme::Tokens) -> Option<egui::TextureId> {
- if t.bevel {
+ if t.bevel || t.canvas_dot == t.canvas {
return None;
}
let key = egui::Id::new(("canvas-dots", format!("{:?}", t.kind)));
@@ -6003,6 +6004,32 @@ mod tests {
assert_ne!(ensure_texture(&mut app, &ctx, 1, Some(1)).unwrap().0, a, "reopening a preserved ID creates a fresh texture");
}
+ #[test]
+ fn only_themes_with_a_dot_pattern_tile_the_canvas_surround() {
+ // #4542: switching to Pro filled the empty workspace with red blocks on one GPU. Pro's
+ // dots are its canvas colour, so the tiled texture had nothing to show in the first place.
+ use crate::theme::ThemeKind;
+ let tiles = |ctx: &egui::Context, kind: ThemeKind| {
+ crate::theme::apply(ctx, kind);
+ let mut output = ctx.run_ui(Default::default(), |ui| paint_dots(ui, ui.max_rect(), true));
+ output.textures_delta.clear();
+ output.shapes.iter().any(|s| matches!(s.shape, egui::Shape::Mesh(_)))
+ };
+ let uploaded = |ctx: &egui::Context| ctx.tex_manager().read().allocated().filter(|(_, meta)| meta.name == "canvas-dots").count();
+ for kind in ThemeKind::ALL {
+ let ctx = egui::Context::default();
+ let dotted = matches!(kind, ThemeKind::Studio | ThemeKind::StudioLight | ThemeKind::SolarizedDark);
+ assert_eq!(tiles(&ctx, kind), dotted, "{kind:?}");
+ assert_eq!(uploaded(&ctx), usize::from(dotted), "{kind:?}");
+ }
+ // The reported switch: a dotted theme, then Pro.
+ let ctx = egui::Context::default();
+ assert!(tiles(&ctx, ThemeKind::Studio));
+ assert!(!tiles(&ctx, ThemeKind::Pro));
+ assert!(!tiles(&ctx, ThemeKind::ProMedium));
+ assert_eq!(uploaded(&ctx), 1, "only Studio's dots were uploaded");
+ }
+
#[test]
fn closed_documents_release_cpu_canvas_textures() {
let mut app = app_on_two_displays();