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-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});
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-24 04:13:42 +00:00
|
|
|
pub fn main() !void {
|
2024-07-25 19:48:17 +00:00
|
|
|
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
|
|
|
|
const allocator = gpa.allocator();
|
|
|
|
defer {
|
|
|
|
if (gpa.deinit() == .leak) {
|
2024-10-11 15:11:51 +00:00
|
|
|
log.warn("Memory was leaked D:", .{});
|
2024-07-25 19:48:17 +00:00
|
|
|
std.debug.print("Memory was leaked D:\n", .{});
|
|
|
|
}
|
|
|
|
}
|
2024-07-24 04:13:42 +00:00
|
|
|
|
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-07-25 19:48:17 +00:00
|
|
|
var top = pane.Pane{
|
2024-10-11 15:11:51 +00:00
|
|
|
.dimensions = .{
|
|
|
|
.x = dim.Fill,
|
|
|
|
.y = dim.Fill,
|
|
|
|
},
|
2024-07-25 19:48:17 +00:00
|
|
|
.border = borders.BoldBorder,
|
|
|
|
.children = std.ArrayList(*pane.Pane).init(allocator),
|
|
|
|
.background = color.RGB(30, 30, 30),
|
|
|
|
.foreground = color.RGB(0, 255, 0),
|
|
|
|
};
|
|
|
|
|
2024-10-11 15:11:51 +00:00
|
|
|
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;
|
|
|
|
|
2024-07-25 19:48:17 +00:00
|
|
|
var child = pane.Pane{
|
|
|
|
.parent = &top,
|
2024-07-27 20:41:13 +00:00
|
|
|
.children = std.ArrayList(*pane.Pane).init(allocator),
|
2024-07-25 19:48:17 +00:00
|
|
|
.dimensions = .{
|
2024-10-11 15:11:51 +00:00
|
|
|
.anchor = .CenterRight,
|
|
|
|
.x = .{ .value = 80, .type = .Relative },
|
|
|
|
.y = .{ .value = 100, .type = .Relative },
|
2024-07-25 19:48:17 +00:00
|
|
|
},
|
|
|
|
.border = borders.BoldBorder,
|
|
|
|
.background = color.RGB(125, 0, 125),
|
|
|
|
.foreground = color.RGB(255, 125, 10),
|
|
|
|
};
|
|
|
|
|
2024-10-11 15:11:51 +00:00
|
|
|
var button = btn.Button.init(&child, .{ .anchor = .BottomLeft, .x = .{ .value = 8 }, .y = .{ .value = 1 } }, "<Button>", on_click);
|
|
|
|
button.pane.background = child.background;
|
|
|
|
button.pane.foreground = child.foreground;
|
|
|
|
|
|
|
|
var items = [_]menu.MenuItem{ .{ .name = "Item 1", .value = 1 }, .{ .name = "Item ab", .value = 2 } };
|
|
|
|
m = menu.Menu.init(&child, dim.Dimensions{ .anchor = .TopLeft, .x = .{ .value = 100, .type = .Relative }, .y = .{ .value = 50, .type = .Relative } }, .{ .title = "Test", .align_text = .Left, .expand_highlight = true }, &items, on_select);
|
|
|
|
m.pane.background = child.background;
|
|
|
|
m.pane.foreground = child.foreground;
|
|
|
|
|
|
|
|
var l = line.HorizontalLine.create(&child, .{ .anchor = .Center, .x = .{ .value = 100, .type = .Relative }, .y = .{ .value = 1 } }, borders.BasicBorder);
|
|
|
|
// var l = line.HorizontalLine.create(@ptrFromInt(0x7fffabc0), .{ .anchor = .Center, .x = .{ .value = 100, .type = .Relative }, .y = .{ .value = 1 } }, borders.BasicBorder);
|
2024-07-27 20:41:13 +00:00
|
|
|
|
2024-10-11 15:11:51 +00:00
|
|
|
try top.children.?.append(&side_menu.pane);
|
2024-07-25 19:48:17 +00:00
|
|
|
try top.children.?.append(&child);
|
2024-07-27 20:41:13 +00:00
|
|
|
try child.children.?.append(&m.pane);
|
2024-10-11 15:11:51 +00:00
|
|
|
try child.children.?.append(&l.pane);
|
|
|
|
try child.children.?.append(&button.pane);
|
2024-07-25 19:48:17 +00:00
|
|
|
|
2024-10-11 15:11:51 +00:00
|
|
|
defer top.children.?.deinit();
|
|
|
|
defer child.children.?.deinit();
|
2024-07-24 04:13:42 +00:00
|
|
|
|
2024-10-11 15:11:51 +00:00
|
|
|
try pane.init(&term_io, &top, &m.pane);
|
|
|
|
defer pane.cleanup(&term_io);
|
|
|
|
|
|
|
|
while (!pane.should_exit.load(.acquire)) {
|
|
|
|
try pane.tick(&term_io);
|
|
|
|
}
|
2024-07-24 04:13:42 +00:00
|
|
|
}
|