mod: remove min_size argument from App.start
This commit is contained in:
@@ -52,32 +52,36 @@ pub const Border = struct {
|
||||
// render top and bottom border
|
||||
for (0..size.cols) |col| {
|
||||
const last_row = (size.rows - 1) * size.cols;
|
||||
if (col == 0) {
|
||||
if (this.sides.left and col == 0) {
|
||||
// top left corner
|
||||
cells[col].cp = frame[0];
|
||||
if (this.sides.top) cells[col].cp = frame[0];
|
||||
// bottom left corner
|
||||
cells[last_row + col].cp = frame[4];
|
||||
} else if (col == size.cols - 1) {
|
||||
if (this.sides.bottom) cells[last_row + col].cp = frame[4];
|
||||
} else if (this.sides.right and col == size.cols - 1) {
|
||||
// top right corner
|
||||
cells[col].cp = frame[2];
|
||||
if (this.sides.top) cells[col].cp = frame[2];
|
||||
// bottom left corner
|
||||
cells[last_row + col].cp = frame[5];
|
||||
if (this.sides.bottom) cells[last_row + col].cp = frame[5];
|
||||
} else {
|
||||
// top side
|
||||
cells[col].cp = frame[1];
|
||||
if (this.sides.top) cells[col].cp = frame[1];
|
||||
// bottom side
|
||||
cells[last_row + col].cp = frame[1];
|
||||
if (this.sides.bottom) cells[last_row + col].cp = frame[1];
|
||||
}
|
||||
cells[col].style.fg = this.color;
|
||||
cells[last_row + col].style.fg = this.color;
|
||||
if (this.sides.top) cells[col].style.fg = this.color;
|
||||
if (this.sides.bottom) cells[last_row + col].style.fg = this.color;
|
||||
}
|
||||
// render left and right border
|
||||
for (1..size.rows - 1) |row| {
|
||||
const idx = (row * size.cols);
|
||||
cells[idx].cp = frame[3]; // left
|
||||
cells[idx].style.fg = this.color;
|
||||
cells[idx + size.cols - 1].cp = frame[3]; // right
|
||||
cells[idx + size.cols - 1].style.fg = this.color;
|
||||
if (this.sides.left) {
|
||||
cells[idx].cp = frame[3]; // left
|
||||
cells[idx].style.fg = this.color;
|
||||
}
|
||||
if (this.sides.right) {
|
||||
cells[idx + size.cols - 1].cp = frame[3]; // right
|
||||
cells[idx + size.cols - 1].style.fg = this.color;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: the separator should be rendered regardless of the gap
|
||||
@@ -258,7 +262,7 @@ pub fn Container(comptime Event: type) type {
|
||||
try this.elements.append(element);
|
||||
}
|
||||
|
||||
pub fn handle(this: *@This(), event: Event) ?Event {
|
||||
pub fn handle(this: *@This(), event: Event) !void {
|
||||
switch (event) {
|
||||
.init => log.debug(".init event", .{}),
|
||||
.resize => |size| resize: {
|
||||
@@ -359,29 +363,15 @@ pub fn Container(comptime Event: type) type {
|
||||
element_size.anchor.col += 1;
|
||||
}
|
||||
|
||||
// TODO: adjust size according to the layout of the `Container`
|
||||
if (element.handle(.{ .resize = element_size })) |e| {
|
||||
_ = e;
|
||||
}
|
||||
try element.handle(.{ .resize = element_size });
|
||||
}
|
||||
return null;
|
||||
},
|
||||
else => {},
|
||||
else => for (this.elements.items) |*element| try element.handle(event),
|
||||
}
|
||||
for (this.elements.items) |*element| {
|
||||
if (element.handle(event)) |e| {
|
||||
// TODO: if only the top level container returns a single
|
||||
// event (i.e. as a reaction to a certain other event) what
|
||||
// should happen to potential other events?
|
||||
_ = e;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
pub fn contents(this: *const @This()) []const Cell {
|
||||
// TODO: use the size and the corresponding contents to determine what should be show in form of a `Cell` array
|
||||
const cells = this.allocator.alloc(Cell, this.size.cols * this.size.rows) catch @panic("Container::contents: Out of memory.");
|
||||
pub fn contents(this: *const @This()) ![]const Cell {
|
||||
const cells = try this.allocator.alloc(Cell, this.size.cols * this.size.rows);
|
||||
@memset(cells, .{}); // reset all cells
|
||||
this.properties.border.contents(cells, this.size, this.properties.layout, @truncate(this.elements.items.len));
|
||||
return cells;
|
||||
|
||||
Reference in New Issue
Block a user