Вывод текстуры
This commit is contained in:
62
src/main.zig
62
src/main.zig
@@ -2,6 +2,8 @@ const std = @import("std");
|
||||
const builtin = @import("builtin");
|
||||
const dvui = @import("dvui");
|
||||
const SDLBackend = @import("sdl-backend");
|
||||
const Document = @import("Document.zig");
|
||||
const WindowContext = @import("WindowContext.zig");
|
||||
const sdl_c = SDLBackend.c;
|
||||
const Allocator = std.mem.Allocator;
|
||||
const Color = dvui.Color;
|
||||
@@ -24,9 +26,11 @@ pub fn main() !void {
|
||||
.dark => dvui.Theme.builtin.adwaita_dark,
|
||||
},
|
||||
});
|
||||
|
||||
defer win.deinit();
|
||||
|
||||
var ctx = WindowContext.init(allocator);
|
||||
defer ctx.deinit();
|
||||
|
||||
var interrupted = false;
|
||||
|
||||
main_loop: while (true) {
|
||||
@@ -44,7 +48,7 @@ pub fn main() !void {
|
||||
_ = SDLBackend.c.SDL_SetRenderDrawColor(backend.renderer, 0, 0, 0, 255);
|
||||
_ = SDLBackend.c.SDL_RenderClear(backend.renderer);
|
||||
|
||||
const keep_running = gui_frame();
|
||||
const keep_running = gui_frame(&ctx);
|
||||
if (!keep_running) break :main_loop;
|
||||
|
||||
// marks end of dvui frame, don't call dvui functions after this
|
||||
@@ -64,7 +68,7 @@ pub fn main() !void {
|
||||
}
|
||||
}
|
||||
|
||||
fn gui_frame() bool {
|
||||
fn gui_frame(ctx: *WindowContext) bool {
|
||||
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;
|
||||
@@ -83,7 +87,11 @@ fn gui_frame() bool {
|
||||
defer left_panel.deinit();
|
||||
|
||||
dvui.label(@src(), "Tools", .{}, .{});
|
||||
_ = dvui.button(@src(), "Button", .{}, .{});
|
||||
if (dvui.button(@src(), "Fill Random Color", .{}, .{})) {
|
||||
ctx.fillRandomColor() catch |err| {
|
||||
std.debug.print("Error filling canvas: {}\n", .{err});
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// Правая панель - занимает оставшееся пространство
|
||||
@@ -95,20 +103,40 @@ fn gui_frame() bool {
|
||||
);
|
||||
defer back.deinit();
|
||||
|
||||
const fill_color = Color.white.opacity(0.5);
|
||||
var right_panel = dvui.box(
|
||||
@src(),
|
||||
.{ .dir = .vertical },
|
||||
.{
|
||||
.expand = .both,
|
||||
.background = true,
|
||||
.corner_radius = dvui.Rect.all(10),
|
||||
.color_fill = fill_color,
|
||||
},
|
||||
);
|
||||
defer right_panel.deinit();
|
||||
{
|
||||
const fill_color = Color.white.opacity(0.5);
|
||||
var right_panel = dvui.box(
|
||||
@src(),
|
||||
.{ .dir = .vertical },
|
||||
.{
|
||||
.expand = .both,
|
||||
.background = true,
|
||||
.corner_radius = dvui.Rect.all(10),
|
||||
.color_fill = fill_color,
|
||||
},
|
||||
);
|
||||
defer right_panel.deinit();
|
||||
|
||||
dvui.label(@src(), "Canvas", .{}, .{ .gravity_x = 0.5 });
|
||||
const overlay = dvui.overlay(@src(), .{
|
||||
.expand = .both,
|
||||
});
|
||||
defer overlay.deinit();
|
||||
|
||||
// Отобразить canvas внутри контейнера
|
||||
if (ctx.canvas_texture) |texture| {
|
||||
_ = dvui.image(@src(), .{
|
||||
.source = .{ .texture = texture },
|
||||
}, .{
|
||||
.expand = .both,
|
||||
.min_size_content = .{
|
||||
.w = @floatFromInt(ctx.canvas_width),
|
||||
.h = @floatFromInt(ctx.canvas_height),
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
dvui.label(@src(), "Canvas", .{}, .{ .gravity_x = 0.5, .gravity_y = 0.0 });
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user