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;
|
2024-10-14 23:35:47 +00:00
|
|
|
var lineV: line.VerticalLine = undefined;
|
|
|
|
var lineH: line.HorizontalLine = undefined;
|
2024-10-14 23:05:56 +00:00
|
|
|
|
|
|
|
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 } };
|
|
|
|
|
2024-10-14 23:35:47 +00:00
|
|
|
const green = color.RGB(0, 255, 0);
|
|
|
|
const purple = color.RGB(125, 0, 125);
|
|
|
|
const orange = color.RGB(255, 125, 10);
|
|
|
|
|
|
|
|
_ = stack.Stack.create(&top, .{ .direction = .Horizontal, .style = .{ .border = borders.BoldBorder, .background = color.RGB(30, 30, 30), .foreground = green } }, &[_]stack.StackedPane{
|
2024-10-14 23:05:56 +00:00
|
|
|
.{
|
2024-10-14 23:35:47 +00:00
|
|
|
.pane = menu.Menu.create(&side_menu, .{ .title = "Menu", .style = .{ .background = color.RGB(80, 80, 80), .foreground = green }, .align_text = .Center, .expand_highlight = true, .on_select = on_side_select }, &items2),
|
2024-10-14 23:05:56 +00:00
|
|
|
.dimensions = .{ .width = .{ .type = .Fill, .value = 1 }, .height = .{ .type = .Fill, .value = 100 } },
|
2024-10-11 15:11:51 +00:00
|
|
|
},
|
2024-10-14 23:35:47 +00:00
|
|
|
.{ .pane = line.VerticalLine.create(&lineV, borders.BoldBorder), .dimensions = .{ .width = .{ .type = .Absolute, .value = 1 }, .height = .{ .type = .Fill, .value = 100 } } },
|
2024-10-14 23:05:56 +00:00
|
|
|
.{
|
2024-10-14 23:35:47 +00:00
|
|
|
.pane = stack.Stack.create(&child, .{ .direction = .Vertical, .style = .{ .border = borders.BoldBorder, .background = purple, .foreground = orange } }, &[_]stack.StackedPane{
|
2024-10-14 23:05:56 +00:00
|
|
|
.{
|
|
|
|
.pane = tabs.TabBar.create(&tabbar, .{ .highlight_color = color.RGB(0, 0, 255) }, &tabs_),
|
|
|
|
.dimensions = .{ .width = .{ .type = .Fill, .value = 100 }, .height = .{ .type = .Absolute, .value = 1 } },
|
|
|
|
},
|
|
|
|
.{
|
2024-10-14 23:35:47 +00:00
|
|
|
.pane = menu.Menu.create(&m, .{ .title = "Test", .style = .{ .background = purple, .foreground = orange }, .align_text = .Left, .expand_highlight = true, .on_select = on_select }, &items),
|
2024-10-14 23:05:56 +00:00
|
|
|
.dimensions = .{ .width = .{ .type = .Fill, .value = 100 }, .height = .{ .type = .Fill, .value = 1 } },
|
|
|
|
},
|
2024-10-14 23:35:47 +00:00
|
|
|
.{ .pane = line.HorizontalLine.create(&lineH, borders.BoldBorder), .dimensions = .{ .width = .{ .type = .Fill, .value = 100 }, .height = .{ .type = .Absolute, .value = 1 } } },
|
2024-10-14 23:05:56 +00:00
|
|
|
.{
|
2024-10-14 23:35:47 +00:00
|
|
|
.pane = btn.Button.create(&button, .{ .text = "<Button>", .style = .{ .background = purple, .foreground = orange }, .callback = on_click }),
|
2024-10-14 23:05:56 +00:00
|
|
|
.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
|
|
|
});
|
|
|
|
|
|
|
|
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
|
|
|
}
|