From 508c4bb2aaba8c3a7a5e7af481516fdbff69eeb8 Mon Sep 17 00:00:00 2001 From: Rebornim Date: Sat, 7 Nov 2026 02:49:47 +0000 Subject: [PATCH] Keep the click that dismisses the image drop menu from painting The views don't paint while a dropped image waits for its menu pick, so a click on the mesh outside the menu only closes it. Also document Texel::source and DecalDrop::menu_id. --- crates/compose/src/eval.rs | 1 + crates/ui-egui/src/decal_drop.rs | 6 ++++++ crates/ui-egui/src/viewport.rs | 7 +++++-- crates/ui-egui/tests/shelf_drop.rs | 13 +++++++++---- 4 files changed, 21 insertions(+), 6 deletions(-) diff --git a/crates/compose/src/eval.rs b/crates/compose/src/eval.rs index 308d11c2..9dba941a 100644 --- a/crates/compose/src/eval.rs +++ b/crates/compose/src/eval.rs @@ -1129,6 +1129,7 @@ impl<'a, 'b> Texel<'a, 'b> { w * image.map_or(1.0, |img| img.sample(c.uv.x, c.uv.y)[3].clamp(0.0, 1.0)) } + /// The value `source` gives this texel through `projection`, read as a channel of `kind` fn source(&mut self, source: &Source, projection: &Projection, kind: ChannelKind) -> [f32; 3] { match source { Source::Uniform(value) => *value, diff --git a/crates/ui-egui/src/decal_drop.rs b/crates/ui-egui/src/decal_drop.rs index 0bb95f65..1dfba5f2 100644 --- a/crates/ui-egui/src/decal_drop.rs +++ b/crates/ui-egui/src/decal_drop.rs @@ -25,6 +25,7 @@ pub struct DecalDrop { } impl DecalDrop { + /// Where the waiting drop and its menu's state are kept fn menu_id() -> Id { Id::unique("decal_drop_menu") } @@ -34,6 +35,11 @@ impl DecalDrop { ui.ctx().data_mut(|data| data.insert_temp(Self::menu_id(), self)); } + /// Whether a drop waits for its menu pick: the views don't paint meanwhile, so the click that dismisses the menu paints nothing + pub fn waiting(ctx: &egui::Context) -> bool { + ctx.data(|data| data.get_temp::(Self::menu_id()).is_some()) + } + /// Show the waiting drop's menu over the 3D view `response`; a pick places the decal, a click elsewhere drops nothing pub fn show_menu(app: &mut TextureCraftApp, ui: &Ui, response: &egui::Response) { let id = Self::menu_id(); diff --git a/crates/ui-egui/src/viewport.rs b/crates/ui-egui/src/viewport.rs index 1855438a..ec58ce89 100644 --- a/crates/ui-egui/src/viewport.rs +++ b/crates/ui-egui/src/viewport.rs @@ -13,6 +13,7 @@ use texturecraft_engine::{Tool, ViewMode}; use texturecraft_render::{Frame, SetHighlight, Shade, ViewKind}; use crate::TextureCraftApp; +use crate::decal_drop::DecalDrop; use crate::gpu::ViewCallback; use crate::i18n::{tr, trf}; use crate::state::ViewLayout; @@ -571,7 +572,8 @@ fn view_3d(app: &mut TextureCraftApp, ui: &mut Ui, rect: Rect, sync: &mut Pendin && !focus_pick && placing.is_none() && touch.is_none() - && !decal_drag; + && !decal_drag + && !DecalDrop::waiting(ui.ctx()); let path_tool = app.session.tool.tool == Tool::Path; let viewport = app.session.viewport; let show = |app: &TextureCraftApp, point: Vec3| project(app, rect, point); @@ -1236,7 +1238,8 @@ fn view_2d(app: &mut TextureCraftApp, ui: &mut Ui, rect: Rect, sync: &mut Pendin crate::properties_popup::open_on_right_click(app, ui, &response, rect, v_held); // Painting in UV space - let painting = app.ui.mode == crate::state::Mode::Painting && app.properties_popup.is_none() && !alt && !adjusting && !v_held; + let painting = + app.ui.mode == crate::state::Mode::Painting && app.properties_popup.is_none() && !alt && !adjusting && !v_held && !DecalDrop::waiting(ui.ctx()); if painting && path_tool { path_input(app, ui, &response, true, |_, pointer| Some(to_uv(pointer).extend(0.0)), show); } else if painting { diff --git a/crates/ui-egui/tests/shelf_drop.rs b/crates/ui-egui/tests/shelf_drop.rs index 7bb94a04..36a89de6 100644 --- a/crates/ui-egui/tests/shelf_drop.rs +++ b/crates/ui-egui/tests/shelf_drop.rs @@ -3,6 +3,7 @@ use egui::{Event, Modifiers, PointerButton, Pos2}; use egui_kittest::Harness; use egui_kittest::kittest::Queryable; +use texturecraft_engine::Tool; use texturecraft_engine::core::Channel; use texturecraft_engine::geom::glam::Vec2; use texturecraft_ui_egui::TextureCraftApp; @@ -125,10 +126,14 @@ fn an_image_drop_places_nothing_until_a_pick_and_nothing_on_the_background() { let (stacks, history) = (stack_sizes(&harness), harness.state().session.history_labels().len()); assert!(menu_open(&harness, position)); - // A click elsewhere closes the menu - let corner = harness.state().viewport_rect.min + egui::vec2(SEARCH_STEP, SEARCH_STEP); - harness.event(Event::PointerButton { pos: corner, button: PointerButton::Primary, pressed: true, modifiers: Modifiers::NONE }); - harness.event(Event::PointerButton { pos: corner, button: PointerButton::Primary, pressed: false, modifiers: Modifiers::NONE }); + // A click elsewhere on the mesh closes the menu and fills nothing there (a polygon fill click records a step in this harness) + harness.state_mut().session.tool.tool = Tool::PolygonFill; + let elsewhere = point_over(&harness, Some(0)); + harness.hover_at(elsewhere); + harness.run_steps(1); + harness.event(Event::PointerButton { pos: elsewhere, button: PointerButton::Primary, pressed: true, modifiers: Modifiers::NONE }); + harness.run_steps(1); + harness.event(Event::PointerButton { pos: elsewhere, button: PointerButton::Primary, pressed: false, modifiers: Modifiers::NONE }); harness.run_steps(2); assert!(!menu_open(&harness, position)); assert_eq!(stack_sizes(&harness), stacks);