intermediate #1
@@ -63,11 +63,16 @@ pub fn main() !void {
|
|||||||
const element = element_wrapper.element();
|
const element = element_wrapper.element();
|
||||||
|
|
||||||
var container = try App.Container.init(allocator, .{
|
var container = try App.Container.init(allocator, .{
|
||||||
.border = .{ .separator = .{ .enabled = true } },
|
.border = .{
|
||||||
|
.separator = .{
|
||||||
|
.enabled = true,
|
||||||
|
.line = .double,
|
||||||
|
},
|
||||||
|
},
|
||||||
.layout = .{
|
.layout = .{
|
||||||
.gap = 2,
|
.gap = 2,
|
||||||
.padding = .all(5),
|
.padding = .all(5),
|
||||||
.direction = .horizontal,
|
.direction = .vertical,
|
||||||
},
|
},
|
||||||
}, element);
|
}, element);
|
||||||
var box = try App.Container.init(allocator, .{
|
var box = try App.Container.init(allocator, .{
|
||||||
|
|||||||
@@ -13,6 +13,9 @@ const log = std.log.scoped(.container);
|
|||||||
pub const Border = packed struct {
|
pub const Border = packed struct {
|
||||||
pub const rounded_border: [6]u21 = .{ '╭', '─', '╮', '│', '╰', '╯' };
|
pub const rounded_border: [6]u21 = .{ '╭', '─', '╮', '│', '╰', '╯' };
|
||||||
pub const squared_border: [6]u21 = .{ '┌', '─', '┐', '│', '└', '┘' };
|
pub const squared_border: [6]u21 = .{ '┌', '─', '┐', '│', '└', '┘' };
|
||||||
|
pub const line: [2]u21 = .{ '│', '─' };
|
||||||
|
pub const dotted: [2]u21 = .{ '┆', '┄' };
|
||||||
|
pub const double: [2]u21 = .{ '║', '═' };
|
||||||
/// Color to use for the border
|
/// Color to use for the border
|
||||||
color: Color = .default,
|
color: Color = .default,
|
||||||
/// Configure the corner type to be used for the border
|
/// Configure the corner type to be used for the border
|
||||||
@@ -38,10 +41,10 @@ pub const Border = packed struct {
|
|||||||
separator: packed struct {
|
separator: packed struct {
|
||||||
enabled: bool = false,
|
enabled: bool = false,
|
||||||
color: Color = .white,
|
color: Color = .white,
|
||||||
line: enum(u1) {
|
line: enum(u2) {
|
||||||
line,
|
line,
|
||||||
dotted,
|
dotted,
|
||||||
// TODO: add more variations which could be used for the separator
|
double,
|
||||||
} = .line,
|
} = .line,
|
||||||
} = .{},
|
} = .{},
|
||||||
|
|
||||||
@@ -126,6 +129,11 @@ pub const Border = packed struct {
|
|||||||
break :blk rows - element_rows * len;
|
break :blk rows - element_rows * len;
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
const line_cps: [2]u21 = switch (this.separator.line) {
|
||||||
|
.line => line,
|
||||||
|
.dotted => dotted,
|
||||||
|
.double => double,
|
||||||
|
};
|
||||||
switch (layout.direction) {
|
switch (layout.direction) {
|
||||||
.horizontal => {
|
.horizontal => {
|
||||||
offset += layout.gap / 2;
|
offset += layout.gap / 2;
|
||||||
@@ -137,8 +145,7 @@ pub const Border = packed struct {
|
|||||||
}
|
}
|
||||||
offset += cols;
|
offset += cols;
|
||||||
for (1..size.rows -| 1) |row| {
|
for (1..size.rows -| 1) |row| {
|
||||||
// TODO: support the line options
|
cells[row * size.cols + offset].cp = line_cps[0];
|
||||||
cells[row * size.cols + offset].cp = frame[3];
|
|
||||||
cells[row * size.cols + offset].style.fg = this.separator.color;
|
cells[row * size.cols + offset].style.fg = this.separator.color;
|
||||||
}
|
}
|
||||||
offset += layout.gap;
|
offset += layout.gap;
|
||||||
@@ -154,8 +161,7 @@ pub const Border = packed struct {
|
|||||||
}
|
}
|
||||||
offset += rows;
|
offset += rows;
|
||||||
for (1..size.cols -| 1) |col| {
|
for (1..size.cols -| 1) |col| {
|
||||||
// TODO: support the line options
|
cells[offset * size.cols + col].cp = line_cps[1];
|
||||||
cells[offset * size.cols + col].cp = frame[1];
|
|
||||||
cells[offset * size.cols + col].style.fg = this.separator.color;
|
cells[offset * size.cols + col].style.fg = this.separator.color;
|
||||||
}
|
}
|
||||||
offset += layout.gap;
|
offset += layout.gap;
|
||||||
|
|||||||
Reference in New Issue
Block a user