Теперь сквозь тулбар не кликается на холст
This commit is contained in:
@@ -30,6 +30,8 @@ _redraw_pending: bool = false,
|
||||
_last_redraw_time_ms: i64 = 0,
|
||||
cursor_document_point: ?Point2_f = null,
|
||||
draw_document: bool = true,
|
||||
/// Rect тулбара (из предыдущего кадра) для исключения кликов по нему из handleCanvasMouse.
|
||||
toolbar_rect_scale: ?dvui.RectScale = null,
|
||||
|
||||
pub fn init(allocator: std.mem.Allocator, document: *Document, engine: RenderEngine) Canvas {
|
||||
return .{
|
||||
|
||||
@@ -26,7 +26,25 @@ pub fn canvasView(canvas: *Canvas, content_rect_scale: dvui.RectScale) void {
|
||||
}
|
||||
scroll.deinit();
|
||||
|
||||
drawToolbar(canvas);
|
||||
// Тулбар поверх 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);
|
||||
}
|
||||
// Сохраняем 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 });
|
||||
}
|
||||
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 scroll_data = scroll.data();
|
||||
|
||||
for (dvui.events()) |*e| {
|
||||
switch (e.evt) {
|
||||
.mouse => |*mouse| {
|
||||
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{
|
||||
.x = viewport_pt.x + canvas.scroll.viewport.x,
|
||||
.y = viewport_pt.y + canvas.scroll.viewport.y,
|
||||
|
||||
Reference in New Issue
Block a user