feat: introduce growth options .horizontal_only and .vertical_only
All checks were successful
Zig Project Action / Lint, Spell-check and test zig project (push) Successful in 1m5s
All checks were successful
Zig Project Action / Lint, Spell-check and test zig project (push) Successful in 1m5s
Growing containers only in one specific direction while fixing the other dimension (which is then required to be provided - just like before).
This commit is contained in:
@@ -599,9 +599,11 @@ pub const Layout = packed struct {
|
||||
/// Sizing options which should be used by the `Container`
|
||||
pub const Size = packed struct {
|
||||
dim: Point = .{},
|
||||
grow: enum(u2) {
|
||||
grow: enum(u3) {
|
||||
both,
|
||||
fixed,
|
||||
vertical_only,
|
||||
horizontal_only,
|
||||
vertical,
|
||||
horizontal,
|
||||
} = .both,
|
||||
@@ -732,11 +734,11 @@ pub fn Container(Model: type, Event: type) type {
|
||||
assert(this.properties.size.dim.y > 0 or size.y > 0);
|
||||
break :blk .max(size, this.properties.size.dim);
|
||||
},
|
||||
.horizontal => blk: {
|
||||
.horizontal, .horizontal_only => blk: {
|
||||
assert(this.properties.size.dim.y > 0 or size.y > 0);
|
||||
break :blk .max(size, this.properties.size.dim);
|
||||
},
|
||||
.vertical => blk: {
|
||||
.vertical, .vertical_only => blk: {
|
||||
assert(this.properties.size.dim.x > 0 or size.x > 0);
|
||||
break :blk .max(size, this.properties.size.dim);
|
||||
},
|
||||
@@ -799,21 +801,21 @@ pub fn Container(Model: type, Event: type) type {
|
||||
if (growable_children == 0) first_growable_child = child;
|
||||
growable_children += 1;
|
||||
},
|
||||
.horizontal => if (layout.direction == .horizontal) {
|
||||
.horizontal, .horizontal_only => if (layout.direction == .horizontal) {
|
||||
if (growable_children == 0) first_growable_child = child;
|
||||
growable_children += 1;
|
||||
},
|
||||
.vertical => if (layout.direction == .vertical) {
|
||||
.vertical, .vertical_only => if (layout.direction == .vertical) {
|
||||
if (growable_children == 0) first_growable_child = child;
|
||||
growable_children += 1;
|
||||
},
|
||||
}
|
||||
// non layout direction side growth
|
||||
switch (layout.direction) {
|
||||
.horizontal => if (child.properties.size.grow == .vertical or child.properties.size.grow == .both) {
|
||||
.horizontal => if (child.properties.size.grow == .vertical or child.properties.size.grow == .vertical_only or child.properties.size.grow == .both) {
|
||||
child.size.y = available;
|
||||
},
|
||||
.vertical => if (child.properties.size.grow == .horizontal or child.properties.size.grow == .both) {
|
||||
.vertical => if (child.properties.size.grow == .horizontal or child.properties.size.grow == .vertical_only or child.properties.size.grow == .both) {
|
||||
child.size.x = available;
|
||||
},
|
||||
}
|
||||
@@ -831,8 +833,8 @@ pub fn Container(Model: type, Event: type) type {
|
||||
if (child.properties.size.grow == .fixed) continue;
|
||||
|
||||
switch (layout.direction) {
|
||||
.horizontal => if (child.properties.size.grow == .vertical) continue,
|
||||
.vertical => if (child.properties.size.grow == .horizontal) continue,
|
||||
.horizontal => if (child.properties.size.grow == .vertical or child.properties.size.grow == .vertical_only) continue,
|
||||
.vertical => if (child.properties.size.grow == .horizontal or child.properties.size.grow == .horizontal_only) continue,
|
||||
}
|
||||
|
||||
const size = switch (layout.direction) {
|
||||
@@ -898,6 +900,14 @@ pub fn Container(Model: type, Event: type) type {
|
||||
this.size = switch (this.properties.size.grow) {
|
||||
.both => .max(size, fit_size),
|
||||
.fixed => fit_size,
|
||||
.horizontal_only => .{
|
||||
.x = size.x,
|
||||
.y = fit_size.y,
|
||||
},
|
||||
.vertical_only => .{
|
||||
.x = fit_size.x,
|
||||
.y = size.y,
|
||||
},
|
||||
.horizontal => .{
|
||||
.x = @max(size.x, fit_size.x),
|
||||
.y = size.y,
|
||||
|
||||
@@ -219,8 +219,8 @@ pub fn Alignment(Model: type, Event: type) type {
|
||||
outer: for (0..csize.y) |row| {
|
||||
inner: for (0..csize.x) |col| {
|
||||
// do not read/write out of bounce
|
||||
if (this.size.x < row) break :outer;
|
||||
if (this.size.y < col) break :inner;
|
||||
if (this.size.y < row) break :outer;
|
||||
if (this.size.x < col) break :inner;
|
||||
|
||||
cells[((row + origin.y) * size.x) + col + origin.x] = container_cells[(row * csize.x) + col];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user