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.
This commit is contained in:
Rebornim committed 2026-11-08 00:11:02 +00:00
1 parent c827d1b910
commit 508c4bb2aa
4 files changed
+21 -6

No files matched your search

+1
View File
@@ -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,
+6
View File
@@ -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::<DecalDrop>(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();
+5 -2
View File
@@ -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 {
+9 -4
View File
@@ -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);