Теперь сквозь тулбар не кликается на холст

This commit is contained in:
2026-02-25 23:59:46 +03:00
parent 790200be2a
commit b6e14cd74d
2 changed files with 33 additions and 4 deletions

View File

@@ -30,6 +30,8 @@ _redraw_pending: bool = false,
_last_redraw_time_ms: i64 = 0, _last_redraw_time_ms: i64 = 0,
cursor_document_point: ?Point2_f = null, cursor_document_point: ?Point2_f = null,
draw_document: bool = true, draw_document: bool = true,
/// Rect тулбара (из предыдущего кадра) для исключения кликов по нему из handleCanvasMouse.
toolbar_rect_scale: ?dvui.RectScale = null,
pub fn init(allocator: std.mem.Allocator, document: *Document, engine: RenderEngine) Canvas { pub fn init(allocator: std.mem.Allocator, document: *Document, engine: RenderEngine) Canvas {
return .{ return .{

View File

@@ -26,7 +26,25 @@ pub fn canvasView(canvas: *Canvas, content_rect_scale: dvui.RectScale) void {
} }
scroll.deinit(); scroll.deinit();
// Тулбар поверх scroll
var toolbar_box = dvui.box(
@src(),
.{ .dir = .horizontal },
.{
.expand = .none,
.background = false,
.gravity_x = 0.0,
.gravity_y = 0.0,
.margin = dvui.Rect{ .x = 8, .y = 8 },
},
);
{
drawToolbar(canvas); drawToolbar(canvas);
}
// Сохраняем rect тулбара для следующего кадра — в handleCanvasMouse исключаем из него клики
canvas.toolbar_rect_scale = toolbar_box.data().contentRectScale();
toolbar_box.deinit();
dvui.label(@src(), "Canvas", .{}, .{ .gravity_x = 0.5, .gravity_y = 0.0 }); dvui.label(@src(), "Canvas", .{}, .{ .gravity_x = 0.5, .gravity_y = 0.0 });
} }
overlay.deinit(); overlay.deinit();
@@ -145,16 +163,25 @@ fn handleCanvasZoom(canvas: *Canvas, scroll: anytype) void {
} }
} }
fn handleCanvasMouse(canvas: *Canvas, scroll: anytype) void { fn handleCanvasMouse(canvas: *Canvas, scroll: *dvui.ScrollAreaWidget) void {
const natural_scale = if (canvas.native_scaling) 1 else dvui.windowNaturalScale(); const natural_scale = if (canvas.native_scaling) 1 else dvui.windowNaturalScale();
const scroll_data = scroll.data();
for (dvui.events()) |*e| { for (dvui.events()) |*e| {
switch (e.evt) { switch (e.evt) {
.mouse => |*mouse| { .mouse => |*mouse| {
if (mouse.action != .press or mouse.button != .left) continue; if (mouse.action != .press or mouse.button != .left) continue;
if (!dvui.eventMatchSimple(e, scroll.data())) continue; if (e.handled) continue;
if (!dvui.eventMatchSimple(e, scroll_data)) continue;
const viewport_pt = scroll.data().contentRectScale().pointFromPhysical(mouse.p); // Не обрабатывать клик, если он попал в область тулбара (rect с предыдущего кадра).
if (canvas.toolbar_rect_scale) |trs| {
const pt = trs.pointFromPhysical(mouse.p);
const r = trs.r;
if (pt.x >= 0 and pt.x * trs.s < r.w and pt.y >= 0 and pt.y * trs.s < r.h) continue;
}
const viewport_pt = scroll_data.contentRectScale().pointFromPhysical(mouse.p);
const content_pt = dvui.Point{ const content_pt = dvui.Point{
.x = viewport_pt.x + canvas.scroll.viewport.x, .x = viewport_pt.x + canvas.scroll.viewport.x,
.y = viewport_pt.y + canvas.scroll.viewport.y, .y = viewport_pt.y + canvas.scroll.viewport.y,