feat(container): introduce fixed_size property for fixed sizing of Containers
Some checks failed
Zig Project Action / Lint, Spell-check and test zig project (push) Failing after 42s
Some checks failed
Zig Project Action / Lint, Spell-check and test zig project (push) Failing after 42s
Moved min_size property from `Container` to the `Scrollable` element, where it is only used anyway.
This commit is contained in:
@@ -58,12 +58,16 @@ pub fn Scrollable(Event: type) type {
|
||||
/// `Size` of the actual contents where the anchor and the size is
|
||||
/// representing the size and location on screen.
|
||||
size: Size = .{},
|
||||
/// Minimal `Size` of the scrollable `Container` to be used. If the
|
||||
/// actual scrollable container's size is larger it will be used instead
|
||||
/// (no scrolling will be necessary for that screen size).
|
||||
min_size: Size = .{},
|
||||
/// `Size` of the `Container` content that is scrollable and mapped to
|
||||
/// the *size* of the `Scrollable` `Element`.
|
||||
container_size: Size = .{},
|
||||
/// Anchor of the viewport of the scrollable `Container`.
|
||||
anchor: Position = .{},
|
||||
/// The actual container, that is scrollable.
|
||||
/// The actual `Container`, that is scrollable.
|
||||
container: Container(Event),
|
||||
|
||||
pub fn element(this: *@This()) Element(Event) {
|
||||
@@ -76,8 +80,11 @@ pub fn Scrollable(Event: type) type {
|
||||
};
|
||||
}
|
||||
|
||||
pub fn init(container: Container(Event)) @This() {
|
||||
return .{ .container = container };
|
||||
pub fn init(container: Container(Event), min_size: Size) @This() {
|
||||
return .{
|
||||
.container = container,
|
||||
.min_size = min_size,
|
||||
};
|
||||
}
|
||||
|
||||
fn handle(ctx: *anyopaque, event: Event) !void {
|
||||
@@ -86,7 +93,7 @@ pub fn Scrollable(Event: type) type {
|
||||
.resize => |size| {
|
||||
this.size = size;
|
||||
// TODO: scrollbar space - depending on configuration and only if necessary?
|
||||
this.container_size = size.max(this.container.minSize());
|
||||
this.container_size = size.max(this.min_size);
|
||||
this.container_size.anchor = size.anchor;
|
||||
try this.container.handle(.{ .resize = this.container_size });
|
||||
},
|
||||
@@ -190,7 +197,6 @@ test "scrollable vertical" {
|
||||
.direction = .vertical,
|
||||
.padding = .all(1),
|
||||
},
|
||||
.min_size = .{ .rows = size.rows + 15 },
|
||||
}, .{});
|
||||
try box.append(try .init(std.testing.allocator, .{
|
||||
.rectangle = .{ .fill = .grey },
|
||||
@@ -200,7 +206,7 @@ test "scrollable vertical" {
|
||||
}, .{}));
|
||||
defer box.deinit();
|
||||
|
||||
var scrollable: Scrollable(event.SystemEvent) = .init(box);
|
||||
var scrollable: Scrollable(event.SystemEvent) = .init(box, .{ .rows = size.rows + 15 });
|
||||
|
||||
var container: Container(event.SystemEvent) = try .init(std.testing.allocator, .{
|
||||
.border = .{
|
||||
@@ -265,7 +271,6 @@ test "scrollable horizontal" {
|
||||
.direction = .horizontal,
|
||||
.padding = .all(1),
|
||||
},
|
||||
.min_size = .{ .cols = size.cols + 15 },
|
||||
}, .{});
|
||||
try box.append(try .init(std.testing.allocator, .{
|
||||
.rectangle = .{ .fill = .grey },
|
||||
@@ -275,7 +280,7 @@ test "scrollable horizontal" {
|
||||
}, .{}));
|
||||
defer box.deinit();
|
||||
|
||||
var scrollable: Scrollable(event.SystemEvent) = .init(box);
|
||||
var scrollable: Scrollable(event.SystemEvent) = .init(box, .{ .cols = size.cols + 15 });
|
||||
|
||||
var container: Container(event.SystemEvent) = try .init(std.testing.allocator, .{
|
||||
.border = .{
|
||||
|
||||
Reference in New Issue
Block a user