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 == 0) { pane.focus(&m.pane, &term_io); } } fn on_select(item: usize) void { log.debug("Main menu: Item {d} was selected", .{item}); if (item == 0) { pane.focus(&side_menu.pane, &term_io); } } pub fn main() !void { 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: stack.Stack = undefined; var child: stack.Stack = undefined; var button: btn.Button = undefined; var tabbar: tabs.TabBar = undefined; var lineV: line.VerticalLine = undefined; var lineH: line.HorizontalLine = undefined; var items = [_]menu.MenuItem{ .{ .name = "Item 1" }, .{ .name = "Item ab" } }; var items2 = [_]menu.MenuItem{ .{ .name = "Item 1" }, .{ .name = "Item ab" } }; var tabs_ = [_]tabs.Tab{ .{ .name = "Tab 1", .pane = &side_menu.pane }, .{ .name = "Tab 2", .pane = &child.pane }, .{ .name = "Tab 3", .pane = &child.pane }, .{ .name = "Tab 4", .pane = &child.pane }, .{ .name = "Tab 5", .pane = &child.pane } }; const gray = color.RGB(80, 80, 80); const green = color.RGB(0, 255, 0); const s = pane.Style{ .background = gray, .foreground = green }; const sb = pane.Style{ .border = borders.BoldBorder, .background = gray, .foreground = green }; _ = stack.Stack.create(&top, .{ .direction = .Horizontal, .style = sb }, &[_]stack.StackedPane{ .{ .pane = menu.Menu.create(&side_menu, .{ .title = "Menu", .style = s, .align_text = .Center, .expand_highlight = true, .on_select = on_side_select }, &items2), .dimensions = .{ .width = .{ .type = .Fill, .value = 1 }, .height = .{ .type = .Fill, .value = 100 } }, }, .{ .pane = line.VerticalLine.create(&lineV, .{ .border = borders.BoldBorder, .style = s }), .dimensions = .{ .width = .{ .type = .Absolute, .value = 1 }, .height = .{ .type = .Fill, .value = 100 } } }, .{ .pane = stack.Stack.create(&child, .{ .direction = .Vertical, .style = sb }, &[_]stack.StackedPane{ .{ .pane = tabs.TabBar.create(&tabbar, .{ .highlight_color = color.RGB(0, 125, 0), .style = .{ .background = gray } }, &tabs_), .dimensions = .{ .width = .{ .type = .Fill, .value = 100 }, .height = .{ .type = .Absolute, .value = 1 } }, }, .{ .pane = menu.Menu.create(&m, .{ .title = "Test", .style = s, .align_text = .Left, .expand_highlight = true, .on_select = on_select }, &items), .dimensions = .{ .width = .{ .type = .Fill, .value = 100 }, .height = .{ .type = .Fill, .value = 1 } }, }, .{ .pane = line.HorizontalLine.create(&lineH, .{ .border = borders.BoldBorder, .style = s }), .dimensions = .{ .width = .{ .type = .Fill, .value = 100 }, .height = .{ .type = .Absolute, .value = 1 } } }, .{ .pane = btn.Button.create(&button, .{ .text = "