Compare commits

..

No commits in common. "bb807a86f3f5162b36bf4f421a3bed6da45c2c88" and "c1eea0352e79f7a052cf45f815f7e4bafc5a75f4" have entirely different histories.

3 changed files with 16 additions and 35 deletions

View File

@ -4,22 +4,15 @@ const term = @import("term.zig");
const borders = @import("borders.zig");
const Pane = pane.Pane;
const Style = pane.Style;
const TermIO = term.TermIO;
pub const HorizontalLine = struct {
pane: Pane,
border: borders.Border,
const Config = struct {
border: borders.Border,
style: Style,
};
pub fn create(mem: *HorizontalLine, config: Config) *Pane {
mem.border = config.border;
pub fn create(mem: *HorizontalLine, border: borders.Border) *Pane {
mem.border = border;
mem.pane = Pane{
.style = config.style,
.vtable = .{
.draw = draw,
},
@ -43,15 +36,9 @@ pub const VerticalLine = struct {
pane: Pane,
border: borders.Border,
const Config = struct {
border: borders.Border,
style: Style,
};
pub fn create(mem: *VerticalLine, config: Config) *Pane {
mem.border = config.border;
pub fn create(mem: *VerticalLine, border: borders.Border) *Pane {
mem.border = border;
mem.pane = Pane{
.style = config.style,
.vtable = .{
.draw = draw,
},

View File

@ -57,30 +57,29 @@ pub fn main() !void {
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 };
const purple = color.RGB(125, 0, 125);
const orange = color.RGB(255, 125, 10);
_ = stack.Stack.create(&top, .{ .direction = .Horizontal, .style = sb }, &[_]stack.StackedPane{
_ = stack.Stack.create(&top, .{ .direction = .Horizontal, .style = .{ .border = borders.BoldBorder, .background = color.RGB(30, 30, 30), .foreground = green } }, &[_]stack.StackedPane{
.{
.pane = menu.Menu.create(&side_menu, .{ .title = "Menu", .style = s, .align_text = .Center, .expand_highlight = true, .on_select = on_side_select }, &items2),
.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),
.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, borders.BoldBorder), .dimensions = .{ .width = .{ .type = .Absolute, .value = 1 }, .height = .{ .type = .Fill, .value = 100 } } },
.{
.pane = stack.Stack.create(&child, .{ .direction = .Vertical, .style = sb }, &[_]stack.StackedPane{
.pane = stack.Stack.create(&child, .{ .direction = .Vertical, .style = .{ .border = borders.BoldBorder, .background = purple, .foreground = orange } }, &[_]stack.StackedPane{
.{
.pane = tabs.TabBar.create(&tabbar, .{ .highlight_color = color.RGB(0, 125, 0), .style = .{ .background = gray } }, &tabs_),
.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", .style = s, .align_text = .Left, .expand_highlight = true, .on_select = on_select }, &items),
.pane = menu.Menu.create(&m, .{ .title = "Test", .style = .{ .background = purple, .foreground = orange }, .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 = line.HorizontalLine.create(&lineH, borders.BoldBorder), .dimensions = .{ .width = .{ .type = .Fill, .value = 100 }, .height = .{ .type = .Absolute, .value = 1 } } },
.{
.pane = btn.Button.create(&button, .{ .text = "<Button>", .style = s, .callback = on_click }),
.pane = btn.Button.create(&button, .{ .text = "<Button>", .style = .{ .background = purple, .foreground = orange }, .callback = on_click }),
.dimensions = .{ .width = .{ .type = .Absolute, .value = 8 }, .height = .{ .type = .Absolute, .value = 1 } },
},
}),

View File

@ -1,7 +1,6 @@
const dim = @import("dimensions.zig");
const term = @import("term.zig");
const pane = @import("pane.zig");
const log = @import("log.zig");
const std = @import("std");
const Pane = pane.Pane;
@ -127,7 +126,6 @@ pub const Stack = struct {
var used: usize = 0;
var available = height - total_absolute;
const ratio = available / total_fill;
var extra = available - (total_fill * ratio);
for (self.children) |child| {
child.pane.dimensions.pos = .{
@ -142,8 +140,7 @@ pub const Stack = struct {
switch (child.dimensions.height.type) {
.Fill => {
child.pane.dimensions.size.height = (child.dimensions.height.value * ratio) + @min(child.dimensions.height.value, extra);
extra -= @min(child.dimensions.width.value, extra);
child.pane.dimensions.size.height = child.dimensions.height.value * ratio;
available -= child.pane.dimensions.size.height;
},
.Absolute => child.pane.dimensions.size.height = child.dimensions.height.value,
@ -209,7 +206,6 @@ pub const Stack = struct {
var used: usize = 0;
var available = width - total_absolute;
const ratio = available / total_fill;
var extra = available - (total_fill * ratio);
for (self.children) |child| {
child.pane.dimensions.pos = .{
@ -224,8 +220,7 @@ pub const Stack = struct {
switch (child.dimensions.width.type) {
.Fill => {
child.pane.dimensions.size.width = (child.dimensions.width.value * ratio) + @min(child.dimensions.width.value, extra);
extra -= @min(child.dimensions.width.value, extra);
child.pane.dimensions.size.width = child.dimensions.width.value * ratio;
available -= child.pane.dimensions.size.width;
},
.Absolute => child.pane.dimensions.size.width = child.dimensions.width.value,