From a82b9312fd8ee4cd7f2feb03fb18815a3a21b974 Mon Sep 17 00:00:00 2001 From: Rebornim <250083243+Rebornim@users.noreply.github.com> Date: Fri, 27 Nov 2026 01:17:59 +0000 Subject: [PATCH] Keep the right-click popup's brush pictures apart from the docked panel's The popup and the docked panel draw the brush preview, stamp dial and jitter strip at their own widths through one cache entry per picture, so each frame one replaced the other's texture: the popup's pictures came out blank and both were rendered again every frame. The cache now keeps one entry per drawing layer. --- crates/ui-egui/src/brush_stroke_preview.rs | 3 ++- crates/ui-egui/tests/it/properties_popup.rs | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/crates/ui-egui/src/brush_stroke_preview.rs b/crates/ui-egui/src/brush_stroke_preview.rs index 245065bb..52b8b9b3 100644 --- a/crates/ui-egui/src/brush_stroke_preview.rs +++ b/crates/ui-egui/src/brush_stroke_preview.rs @@ -53,7 +53,8 @@ impl BrushStrokePreview { let pixels_per_point = ctx.pixels_per_point(); let size = [(rect.width() * pixels_per_point).round().max(1.0) as usize, (rect.height() * pixels_per_point).round().max(1.0) as usize]; let tints: Vec<[u8; 3]> = (0..size[0]).map(|x| tint((x as f32 + 0.5) / size[0] as f32)).collect(); - let id = Id::unique(key); + // The docked panel and the right-click popup draw the same picture at their own widths: one cache each + let id = Id::unique(key).with(painter.layer_id()); let cached = ctx.data(|data| data.get_temp::(id)).filter(|preview| { preview.brush == *brush && preview.size == size && preview.tints == tints && preview.image.as_ref().map(Arc::as_ptr) == image.map(Arc::as_ptr) }); diff --git a/crates/ui-egui/tests/it/properties_popup.rs b/crates/ui-egui/tests/it/properties_popup.rs index cb96b1e3..80403926 100644 --- a/crates/ui-egui/tests/it/properties_popup.rs +++ b/crates/ui-egui/tests/it/properties_popup.rs @@ -201,6 +201,27 @@ fn it_shows_what_the_properties_panel_shows() { assert!(!in_popup("Minimum Size (%)"), "not the brush's"); } +#[test] +fn its_brush_pictures_and_the_docked_panels_keep_their_own_textures() { + let mut harness = harness(); + let center = view_center(&harness); + click(&mut harness, PointerButton::Secondary, center); + + assert!(is_open(&harness)); + + let previews = |harness: &Harness<'_, TextureCraftApp>| { + let mut ids: Vec<_> = + harness.ctx.tex_manager().read().allocated().filter(|(_, texture)| texture.name == "brush_stroke_preview").map(|(id, _)| *id).collect(); + ids.sort_unstable_by_key(|id| format!("{id:?}")); + ids + }; + let before = previews(&harness); + harness.run_steps(SETTLE_FRAMES); + + assert_eq!(before.len(), 2, "one stroke preview for the docked panel and one for the popup"); + assert_eq!(previews(&harness), before, "neither is drawn again while the brush stays the same"); +} + /// Whether the jump tab `name` inside `area` is the lit one fn tab_lit(harness: &Harness<'_, TextureCraftApp>, area: egui::Rect, name: &str) -> bool { let tab = harness.get_all_by_role_and_label(Role::Tab, name).find(|tab| area.contains_rect(tab.rect()));