add: Direct Renderer implementation rendering the fixed size of the root Container
A corresponding example has been added, which is very minimalistic as of now, but will add further functionality to test the corresponding workflow that is usual in `zterm` such that it in the best case only a swap in the renderer to switch from alternate mode drawing to direct drawing.
This commit is contained in:
46
examples/direct.zig
Normal file
46
examples/direct.zig
Normal file
@@ -0,0 +1,46 @@
|
||||
pub fn main() !void {
|
||||
errdefer |err| log.err("Application Error: {any}", .{err});
|
||||
|
||||
var allocator: std.heap.DebugAllocator(.{}) = .init;
|
||||
defer if (allocator.deinit() == .leak) log.err("memory leak", .{});
|
||||
|
||||
const gpa = allocator.allocator();
|
||||
|
||||
var app: App = .init(.{}, .{});
|
||||
var renderer = zterm.Renderer.Direct.init(gpa);
|
||||
defer renderer.deinit();
|
||||
|
||||
var container: App.Container = try .init(gpa, .{
|
||||
.layout = .{
|
||||
.direction = .horizontal,
|
||||
.separator = .{ .enabled = true },
|
||||
},
|
||||
.size = .{
|
||||
.dim = .{ .y = 30 },
|
||||
.grow = .horizontal_only,
|
||||
},
|
||||
}, .{});
|
||||
defer container.deinit();
|
||||
|
||||
try container.append(try .init(gpa, .{
|
||||
.rectangle = .{ .fill = .blue },
|
||||
}, .{}));
|
||||
|
||||
try container.append(try .init(gpa, .{
|
||||
.rectangle = .{ .fill = .green },
|
||||
}, .{}));
|
||||
|
||||
container.resize(&app.model, try renderer.resize());
|
||||
container.reposition(&app.model, .{});
|
||||
try renderer.render(@TypeOf(container), &container, App.Model, &app.model);
|
||||
try renderer.flush();
|
||||
}
|
||||
|
||||
pub const panic = App.panic_handler;
|
||||
const log = std.log.scoped(.default);
|
||||
|
||||
const std = @import("std");
|
||||
const assert = std.debug.assert;
|
||||
const zterm = @import("zterm");
|
||||
const input = zterm.input;
|
||||
const App = zterm.App(struct {}, union(enum) {});
|
||||
Reference in New Issue
Block a user