Первая версия тулбара
This commit is contained in:
@@ -3,6 +3,7 @@ const dvui = @import("dvui");
|
||||
const dvui_ext = @import("dvui_ext.zig");
|
||||
const Canvas = @import("../Canvas.zig");
|
||||
const Rect_i = @import("../models/basic_models.zig").Rect_i;
|
||||
const tool_interface = @import("../tool_interface.zig");
|
||||
|
||||
pub fn canvasView(canvas: *Canvas, content_rect_scale: dvui.RectScale) void {
|
||||
var textured = dvui_ext.texturedBox(content_rect_scale, dvui.Rect.all(20));
|
||||
@@ -25,6 +26,7 @@ pub fn canvasView(canvas: *Canvas, content_rect_scale: dvui.RectScale) void {
|
||||
}
|
||||
scroll.deinit();
|
||||
|
||||
drawToolbar(canvas);
|
||||
dvui.label(@src(), "Canvas", .{}, .{ .gravity_x = 0.5, .gravity_y = 0.0 });
|
||||
}
|
||||
overlay.deinit();
|
||||
@@ -159,10 +161,49 @@ fn handleCanvasMouse(canvas: *Canvas, scroll: anytype) void {
|
||||
};
|
||||
const doc_pt = canvas.contentPointToDocument(content_pt, natural_scale);
|
||||
canvas.cursor_document_point = if (canvas.isContentPointOnDocument(content_pt, natural_scale)) doc_pt else null;
|
||||
if (canvas.cursor_document_point) |point|
|
||||
std.debug.print("cursor_document_point: {}\n", .{point});
|
||||
if (canvas.cursor_document_point) |point| {
|
||||
if (canvas.toolbar.currentDescriptor()) |desc| {
|
||||
var ctx = tool_interface.ToolContext{
|
||||
.canvas = canvas,
|
||||
.document_point = point,
|
||||
};
|
||||
desc.implementation.onClick(&ctx);
|
||||
}
|
||||
}
|
||||
},
|
||||
else => {},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn drawToolbar(canvas: *Canvas) void {
|
||||
const tools_list = canvas.toolbar.tools;
|
||||
if (tools_list.len == 0) return;
|
||||
|
||||
var bar = dvui.box(
|
||||
@src(),
|
||||
.{ .dir = .vertical },
|
||||
.{
|
||||
.gravity_x = 0.0,
|
||||
.gravity_y = 0.0,
|
||||
.margin = dvui.Rect{ .x = 8, .y = 8 },
|
||||
.padding = dvui.Rect.all(6),
|
||||
.corner_radius = dvui.Rect.all(8),
|
||||
.background = true,
|
||||
.color_fill = dvui.Color.black.opacity(0.2),
|
||||
},
|
||||
);
|
||||
{
|
||||
for (tools_list, 0..) |*tool_desc, i| {
|
||||
const is_selected = (canvas.toolbar.selected_index == i);
|
||||
const opts: dvui.Options = .{
|
||||
.id_extra = i,
|
||||
.color_fill = if (is_selected) dvui.Color.transparent else undefined,
|
||||
};
|
||||
if (dvui.buttonIcon(@src(), tool_desc.name, tool_desc.icon_tvg, .{}, .{}, opts)) {
|
||||
canvas.toolbar.select(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
bar.deinit();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user