Panes/src/main.zig

107 lines
4.1 KiB
Zig
Raw Normal View History

2024-07-24 04:13:42 +00:00
const std = @import("std");
2024-07-25 19:48:17 +00:00
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");
2024-07-27 20:41:13 +00:00
const menu = @import("menu.zig");
2024-10-11 15:11:51 +00:00
const btn = @import("button.zig");
const log = @import("log.zig");
const line = @import("line.zig");
2024-10-13 22:28:15 +00:00
const tabs = @import("tabs.zig");
const stack = @import("stack.zig");
2024-07-25 19:48:17 +00:00
var term_io: term.TermIO = undefined;
2024-10-11 15:11:51 +00:00
var side_menu: menu.Menu = undefined;
var m: menu.Menu = undefined;
2024-07-25 19:48:17 +00:00
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);
}
2024-07-24 04:13:42 +00:00
2024-10-11 15:11:51 +00:00
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});
2024-10-14 23:05:56 +00:00
if (item == 0) {
2024-10-11 15:11:51 +00:00
pane.focus(&m.pane, &term_io);
}
}
fn on_select(item: usize) void {
log.debug("Main menu: Item {d} was selected", .{item});
2024-10-14 23:05:56 +00:00
if (item == 0) {
2024-10-11 15:11:51 +00:00
pane.focus(&side_menu.pane, &term_io);
}
}
2024-07-24 04:13:42 +00:00
pub fn main() !void {
2024-10-11 15:11:51 +00:00
try log.init("panes.log", .Debug);
defer log.deinit();
2024-07-24 04:13:42 +00:00
2024-10-11 15:11:51 +00:00
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());
2024-07-24 04:13:42 +00:00
2024-10-14 23:05:56 +00:00
var top: stack.Stack = undefined;
var child: stack.Stack = undefined;
var button: btn.Button = undefined;
var tabbar: tabs.TabBar = 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 } };
_ = stack.Stack.create(&top, .Horizontal, &[_]stack.StackedPane{
.{
.pane = menu.Menu.create(&side_menu, .{ .title = "Menu", .align_text = .Center, .expand_highlight = true, .on_select = on_side_select }, &items2),
.dimensions = .{ .width = .{ .type = .Fill, .value = 1 }, .height = .{ .type = .Fill, .value = 100 } },
2024-10-11 15:11:51 +00:00
},
2024-10-14 23:05:56 +00:00
.{
.pane = stack.Stack.create(&child, .Vertical, &[_]stack.StackedPane{
.{
.pane = tabs.TabBar.create(&tabbar, .{ .highlight_color = color.RGB(0, 0, 255) }, &tabs_),
.dimensions = .{ .width = .{ .type = .Fill, .value = 100 }, .height = .{ .type = .Absolute, .value = 1 } },
},
.{
.pane = menu.Menu.create(&m, .{ .title = "Test", .align_text = .Left, .expand_highlight = true, .on_select = on_select }, &items),
.dimensions = .{ .width = .{ .type = .Fill, .value = 100 }, .height = .{ .type = .Fill, .value = 1 } },
},
.{
.pane = btn.Button.create(&button, .{ .text = "<Button>", .callback = on_click }),
.dimensions = .{ .width = .{ .type = .Absolute, .value = 8 }, .height = .{ .type = .Absolute, .value = 1 } },
},
}),
.dimensions = .{ .width = .{ .type = .Fill, .value = 9 }, .height = .{ .type = .Fill, .value = 100 } },
2024-07-25 19:48:17 +00:00
},
2024-10-14 23:05:56 +00:00
});
top.pane.border = borders.BoldBorder;
top.pane.background = color.RGB(30, 30, 30);
top.pane.foreground = color.RGB(0, 255, 0);
side_menu.pane.background = color.RGB(80, 80, 80);
side_menu.pane.foreground = top.pane.foreground;
child.pane.border = borders.BoldBorder;
child.pane.background = color.RGB(125, 0, 125);
child.pane.foreground = color.RGB(255, 125, 10);
button.pane.background = child.pane.background;
button.pane.foreground = child.pane.foreground;
m.pane.background = child.pane.background;
m.pane.foreground = child.pane.foreground;
pane.set_layout(&top.pane, &m.pane);
try pane.init(&term_io);
2024-10-11 15:11:51 +00:00
defer pane.cleanup(&term_io);
while (!pane.should_exit.load(.acquire)) {
try pane.tick(&term_io);
}
2024-07-24 04:13:42 +00:00
}