Документ в канвасе

This commit is contained in:
2026-02-22 22:09:40 +03:00
parent bee9513ba0
commit 85a3bac095
3 changed files with 9 additions and 15 deletions

View File

@@ -4,28 +4,27 @@ const dvui = @import("dvui");
const Document = @import("models/Document.zig");
const RenderEngine = @import("render/RenderEngine.zig").RenderEngine;
const ImageRect = @import("models/basic_models.zig").ImageRect;
const Size = dvui.Size;
const Color = dvui.Color;
const Canvas = @This();
allocator: std.mem.Allocator,
document: *Document,
render_engine: RenderEngine,
texture: ?dvui.Texture = null,
size: Size = .{ .w = 800, .h = 600 },
pos: dvui.Point = dvui.Point{ .x = 0, .y = 0 },
pos: dvui.Point = dvui.Point{ .x = 400, .y = 400 },
scroll: dvui.ScrollInfo = .{
.vertical = .auto,
.horizontal = .auto,
},
native_scaling: bool = true,
document: ?*Document = null,
render_engine: RenderEngine,
_visible_rect: ?ImageRect = null,
_zoom: f32 = 1,
pub fn init(allocator: std.mem.Allocator, engine: RenderEngine) Canvas {
pub fn init(allocator: std.mem.Allocator, document: *Document, engine: RenderEngine) Canvas {
return .{
.allocator = allocator,
.document = document,
.render_engine = engine,
};
}
@@ -79,11 +78,12 @@ pub fn addZoom(self: *Canvas, value: f32) void {
}
pub fn getScaledImageSize(self: Canvas) ImageRect {
const doc = self.document;
return .{
.x = @intFromFloat(self.pos.x),
.y = @intFromFloat(self.pos.y),
.w = @intFromFloat(self.size.w * self._zoom),
.h = @intFromFloat(self.size.h * self._zoom),
.w = @intFromFloat(doc.size.width * self._zoom),
.h = @intFromFloat(doc.size.height * self._zoom),
};
}