Рабочий зум
This commit is contained in:
44
src/main.zig
44
src/main.zig
@@ -70,6 +70,9 @@ pub fn main() !void {
|
||||
}
|
||||
|
||||
fn gui_frame(ctx: *WindowContext) bool {
|
||||
const canvas = &ctx.canvas;
|
||||
const ctrl: bool = dvui.currentWindow().modifiers.control();
|
||||
|
||||
for (dvui.events()) |*e| {
|
||||
if (e.evt == .window and e.evt.window.action == .close) return false;
|
||||
if (e.evt == .app and e.evt.app.action == .quit) return false;
|
||||
@@ -87,10 +90,10 @@ fn gui_frame(ctx: *WindowContext) bool {
|
||||
{
|
||||
dvui.label(@src(), "Tools", .{}, .{});
|
||||
if (dvui.button(@src(), "Fill Random Color", .{}, .{})) {
|
||||
ctx.fillRandomColor() catch |err| {
|
||||
canvas.fillRandomGradient() catch |err| {
|
||||
std.debug.print("Error filling canvas: {}\n", .{err});
|
||||
};
|
||||
ctx.canvas.pos = .{ .x = 400, .y = 400 };
|
||||
canvas.pos = .{ .x = 400, .y = 400 };
|
||||
}
|
||||
}
|
||||
left_panel.deinit();
|
||||
@@ -128,27 +131,52 @@ fn gui_frame(ctx: *WindowContext) bool {
|
||||
var scroll = dvui.scrollArea(
|
||||
@src(),
|
||||
.{
|
||||
.scroll_info = &ctx.canvas.scroll,
|
||||
.scroll_info = &canvas.scroll,
|
||||
.vertical_bar = .auto,
|
||||
.horizontal_bar = .auto,
|
||||
},
|
||||
.{ .expand = .both, .background = false },
|
||||
.{
|
||||
.expand = .both,
|
||||
.background = false,
|
||||
},
|
||||
);
|
||||
{
|
||||
// Отобразить canvas внутри scroll area.
|
||||
// ScrollArea сам двигает дочерние виджеты, поэтому margin не нужен.
|
||||
if (ctx.canvas.texture) |texture| {
|
||||
if (canvas.texture) |texture| {
|
||||
_ = dvui.image(@src(), .{
|
||||
.source = .{ .texture = texture },
|
||||
}, .{
|
||||
.margin = .{ .x = ctx.canvas.pos.x, .y = ctx.canvas.pos.y },
|
||||
.margin = .{ .x = canvas.pos.x, .y = canvas.pos.y },
|
||||
.min_size_content = .{
|
||||
.w = @floatFromInt(ctx.canvas.width),
|
||||
.h = @floatFromInt(ctx.canvas.height),
|
||||
.w = @floatFromInt(texture.width),
|
||||
.h = @floatFromInt(texture.height),
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (ctrl) {
|
||||
for (dvui.events()) |*e| {
|
||||
switch (e.evt) {
|
||||
.mouse => |mouse| {
|
||||
const action = mouse.action;
|
||||
if (dvui.eventMatchSimple(e, scroll.data()) and (action == .wheel_x or action == .wheel_y)) {
|
||||
switch (action) {
|
||||
.wheel_y => |y| {
|
||||
canvas.addZoom(y / 1000);
|
||||
canvas.redrawGradient() catch {};
|
||||
},
|
||||
else => {},
|
||||
}
|
||||
e.handled = true;
|
||||
}
|
||||
},
|
||||
else => {},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
scroll.deinit();
|
||||
}
|
||||
canvas_box.deinit();
|
||||
|
||||
Reference in New Issue
Block a user