add(container/layout): sizing:fixed option
This commit is contained in:
@@ -30,6 +30,14 @@ pub const Border = struct {
|
||||
pub fn all() @This() {
|
||||
return .{ .top = true, .bottom = true, .left = true, .right = true };
|
||||
}
|
||||
|
||||
pub fn horizontal() @This() {
|
||||
return .{ .left = true, .right = true };
|
||||
}
|
||||
|
||||
pub fn vertical() @This() {
|
||||
return .{ .top = true, .bottom = true };
|
||||
}
|
||||
} = .{},
|
||||
/// Configure separator borders between child element to added to the layout
|
||||
separator: struct {
|
||||
@@ -280,7 +288,45 @@ pub fn Container(comptime Event: type) type {
|
||||
pub fn handle(this: *@This(), event: Event) !void {
|
||||
switch (event) {
|
||||
.init => log.debug(".init event", .{}),
|
||||
.resize => |size| resize: {
|
||||
.resize => |s| resize: {
|
||||
// sizing
|
||||
var size = s;
|
||||
const sizing = this.properties.layout.sizing;
|
||||
switch (sizing.width) {
|
||||
.fit => {
|
||||
// use as much space as necessary (but nothing more than necessary)
|
||||
},
|
||||
.grow => {
|
||||
// grow use as much space as available by the parent (i.e. the entire width)
|
||||
// NOTE: this is pretty much the current implementation
|
||||
},
|
||||
.fixed => |fix| {
|
||||
std.debug.assert(fix <= size.cols);
|
||||
size.cols = fix;
|
||||
},
|
||||
.percent => |percent| {
|
||||
// use a percentage unit calculated from the available space
|
||||
size.cols = @divTrunc(size.cols * percent, 100);
|
||||
},
|
||||
}
|
||||
switch (sizing.height) {
|
||||
.fit => {
|
||||
// use as much space as necessary (but nothing more than necessary)
|
||||
},
|
||||
.grow => {
|
||||
// grow use as much space as available by the parent (i.e. the entire width)
|
||||
// NOTE: this is pretty much the current implementation
|
||||
},
|
||||
.fixed => |fix| {
|
||||
std.debug.assert(fix <= size.rows);
|
||||
size.rows = fix;
|
||||
},
|
||||
.percent => |percent| {
|
||||
// use a percentage unit calculated from the available space
|
||||
size.rows = @divTrunc(size.rows * percent, 100);
|
||||
},
|
||||
}
|
||||
|
||||
log.debug("Event .resize: {{ .anchor = {{ .col = {d}, .row = {d} }}, .cols = {d}, .rows = {d} }}", .{
|
||||
size.anchor.col,
|
||||
size.anchor.row,
|
||||
|
||||
Reference in New Issue
Block a user