feat(Padding): user configuration for custom padding
This commit is contained in:
@@ -24,13 +24,22 @@ pub fn Layout(comptime Event: type, comptime Renderer: type) type {
|
||||
size: terminal.Size = undefined,
|
||||
element: Element = undefined,
|
||||
events: Events = undefined,
|
||||
padding: u16 = undefined,
|
||||
config: Config = undefined,
|
||||
|
||||
pub fn init(allocator: std.mem.Allocator, padding: u16, element: Element) @This() {
|
||||
// TODO: padding (for all 4 directions?)
|
||||
const Config = struct {
|
||||
padding: ?u16 = undefined,
|
||||
left: u16 = 0,
|
||||
right: u16 = 0,
|
||||
top: u16 = 0,
|
||||
bottom: u16 = 0,
|
||||
};
|
||||
|
||||
pub fn init(allocator: std.mem.Allocator, config: Config, element: Element) @This() {
|
||||
return .{
|
||||
.config = config,
|
||||
.element = element,
|
||||
.events = Events.init(allocator),
|
||||
.padding = padding,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -58,16 +67,32 @@ pub fn Layout(comptime Event: type, comptime Renderer: type) type {
|
||||
size.cols,
|
||||
size.rows,
|
||||
});
|
||||
const sub_event: Event = .{
|
||||
.resize = .{
|
||||
.anchor = .{
|
||||
.col = size.anchor.col + this.padding,
|
||||
.row = size.anchor.row + this.padding,
|
||||
var sub_event: Event = undefined;
|
||||
if (this.config.padding) |padding| {
|
||||
// used overall padding
|
||||
sub_event = .{
|
||||
.resize = .{
|
||||
.anchor = .{
|
||||
.col = size.anchor.col + padding,
|
||||
.row = size.anchor.row + padding,
|
||||
},
|
||||
.cols = size.cols -| (padding * 2),
|
||||
.rows = size.rows -| (padding * 2),
|
||||
},
|
||||
.cols = size.cols -| this.padding -| this.padding,
|
||||
.rows = size.rows -| this.padding -| this.padding,
|
||||
},
|
||||
};
|
||||
};
|
||||
} else {
|
||||
// use all for directions individually
|
||||
sub_event = .{
|
||||
.resize = .{
|
||||
.anchor = .{
|
||||
.col = size.anchor.col + this.config.left,
|
||||
.row = size.anchor.row + this.config.top,
|
||||
},
|
||||
.cols = size.cols -| this.config.left -| this.config.right,
|
||||
.rows = size.rows -| this.config.top -| this.config.bottom,
|
||||
},
|
||||
};
|
||||
}
|
||||
// adjust size according to the containing elements
|
||||
switch ((&this.element).*) {
|
||||
.layout => |*layout| {
|
||||
|
||||
Reference in New Issue
Block a user