From 108cc34fb67d3b5a57fe0bff9b916f3eda67857a Mon Sep 17 00:00:00 2001 From: Cameron Reed Date: Wed, 16 Oct 2024 11:06:31 -0600 Subject: [PATCH] Make tabs work; Does break the focus hack :/ --- src/main.zig | 48 +++++++++++++++++++++++++++++++++++++----------- src/pane.zig | 8 ++++++-- src/tabs.zig | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 91 insertions(+), 13 deletions(-) diff --git a/src/main.zig b/src/main.zig index fbbd7f3..62b3493 100644 --- a/src/main.zig +++ b/src/main.zig @@ -39,7 +39,9 @@ fn on_select(item: usize) void { } pub fn main() !void { - try log.init("panes.log", .Debug); + if (@import("builtin").mode == .Debug) { + try log.init("panes.log", .Debug); + } defer log.deinit(); const stdin = std.io.getStdIn().reader(); @@ -53,9 +55,16 @@ pub fn main() !void { var lineV: line.VerticalLine = undefined; var lineH: line.HorizontalLine = undefined; + var target: tabs.TabbedTarget = undefined; + var child1: stack.Stack = undefined; + var child2: btn.Button = undefined; + var child3: btn.Button = undefined; + var child4: btn.Button = undefined; + var child5: btn.Button = 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 } }; + var tabs_ = [_]tabs.Tab{ .{ .name = "Tab 1", .pane = &child1.pane }, .{ .name = "Tab 2", .pane = &child2.pane }, .{ .name = "Tab 3", .pane = &child3.pane }, .{ .name = "Tab 4", .pane = &child4.pane }, .{ .name = "Tab 5", .pane = &child5.pane } }; const gray = color.RGB(80, 80, 80); const green = color.RGB(0, 255, 0); @@ -67,28 +76,45 @@ pub fn main() !void { .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 = 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 = s }, &[_]stack.StackedPane{ .{ - .pane = tabs.TabBar.create(&tabbar, .{ .style = s, .highlight_color = green }, &tabs_), + .pane = tabs.TabBar.create(&tabbar, .{ .target = &target, .style = s, .highlight_color = green }, &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), + .pane = tabs.TabbedTarget.create(&target, s), .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 = "