const std = @import("std"); const term = @import("term.zig"); const borders = @import("borders.zig"); const pane = @import("pane.zig"); const color = @import("colors.zig"); const dim = @import("dimensions.zig"); const menu = @import("menu.zig"); const btn = @import("button.zig"); const log = @import("log.zig"); const line = @import("line.zig"); const tabs = @import("tabs.zig"); const stack = @import("stack.zig"); var term_io: term.TermIO = undefined; var side_menu: menu.Menu = undefined; var m: menu.Menu = undefined; pub fn panic(msg: []const u8, error_return_trace: ?*std.builtin.StackTrace, ret_addr: ?usize) noreturn { pane.cleanup(&term_io); std.builtin.default_panic(msg, error_return_trace, ret_addr); } fn on_click() void { log.debug("Button was pressed", .{}); } fn on_side_select(item: usize) void { log.debug("Side menu: Item {d} was selected", .{item}); if (item == 1) { pane.focus(&m.pane, &term_io); } } fn on_select(item: usize) void { log.debug("Main menu: Item {d} was selected", .{item}); if (item == 1) { pane.focus(&side_menu.pane, &term_io); } } pub fn main() !void { var gpa = std.heap.GeneralPurposeAllocator(.{}){}; const allocator = gpa.allocator(); defer { if (gpa.deinit() == .leak) { log.warn("Memory was leaked D:", .{}); std.debug.print("Memory was leaked D:\n", .{}); } } try log.init("panes.log", .Debug); defer log.deinit(); const stdin = std.io.getStdIn().reader(); var stdout = std.io.bufferedWriter(std.io.getStdOut().writer().any()); term_io = try term.getTermIO(stdin.any(), stdout.writer()); var top = pane.Pane{ .dimensions = .{ .x = dim.Fill, .y = dim.Fill, }, .border = borders.BoldBorder, .children = std.ArrayList(*pane.Pane).init(allocator), .background = color.RGB(30, 30, 30), .foreground = color.RGB(0, 255, 0), }; var items2 = [_]menu.MenuItem{ .{ .name = "Item 1", .value = 1 }, .{ .name = "Item ab", .value = 2 } }; side_menu = menu.Menu.init(&top, dim.Dimensions{ .anchor = .TopLeft, .x = .{ .value = 20, .type = .Relative }, .y = .{ .value = 100, .type = .Relative } }, .{ .title = "Menu", .align_text = .Right, .expand_highlight = true }, &items2, on_side_select); side_menu.pane.background = color.RGB(80, 80, 80); side_menu.pane.foreground = top.foreground; var child = pane.Pane{ .parent = &top, .children = std.ArrayList(*pane.Pane).init(allocator), .dimensions = .{ .anchor = .CenterRight, .x = .{ .value = 80, .type = .Relative }, .y = .{ .value = 100, .type = .Relative }, }, .border = borders.BoldBorder, .background = color.RGB(125, 0, 125), .foreground = color.RGB(255, 125, 10), }; var button = btn.Button.init(&child, .{ .anchor = .BottomLeft, .x = .{ .value = 8 }, .y = .{ .value = 1 } }, "