fix(element/scrollable): reduce the number of minSize calls and correctly resize scrollable Container
Some checks failed
Zig Project Action / Lint, Spell-check and test zig project (push) Failing after 1m26s
Some checks failed
Zig Project Action / Lint, Spell-check and test zig project (push) Failing after 1m26s
This commit is contained in:
@@ -891,7 +891,7 @@ pub fn Container(Model: type, Event: type) type {
|
|||||||
const fit_size = this.fit_resize();
|
const fit_size = this.fit_resize();
|
||||||
// if (fit_size.y > size.y or fit_size.x > size.x) @panic("error: cannot render in available space");
|
// if (fit_size.y > size.y or fit_size.x > size.x) @panic("error: cannot render in available space");
|
||||||
switch (this.properties.size.grow) {
|
switch (this.properties.size.grow) {
|
||||||
.both => this.size = Point.max(size, fit_size),
|
.both => this.size = .max(size, fit_size),
|
||||||
.fixed => {},
|
.fixed => {},
|
||||||
.horizontal => this.size = .{
|
.horizontal => this.size = .{
|
||||||
.x = @max(size.x, fit_size.x),
|
.x = @max(size.x, fit_size.x),
|
||||||
|
|||||||
@@ -275,26 +275,26 @@ pub fn Scrollable(Model: type, Event: type) type {
|
|||||||
const last_max_anchor_x = this.container_size.x -| this.size.x;
|
const last_max_anchor_x = this.container_size.x -| this.size.x;
|
||||||
const last_max_anchor_y = this.container_size.y -| this.size.y;
|
const last_max_anchor_y = this.container_size.y -| this.size.y;
|
||||||
|
|
||||||
this.size = size;
|
// NOTE `container_size` denotes the `size` required for the container contents
|
||||||
|
var container_size = this.container.element.minSize(size);
|
||||||
if (this.configuration.scrollbar) {
|
if (this.configuration.scrollbar) {
|
||||||
this.configuration.y_axis = this.container.properties.size.dim.x > this.size.x or this.container.size.x > this.size.x;
|
this.configuration.y_axis = this.container.properties.size.dim.x > size.x or container_size.x > size.x;
|
||||||
this.configuration.x_axis = this.container.properties.size.dim.y > this.size.y or this.container.size.y > this.size.y;
|
this.configuration.x_axis = this.container.properties.size.dim.y > size.y or container_size.y > size.y;
|
||||||
|
// correct size dimensions due to space needed for the axis (if any)
|
||||||
|
container_size.x -= if (this.configuration.x_axis) 1 else 0;
|
||||||
|
container_size.y -= if (this.configuration.y_axis) 1 else 0;
|
||||||
|
}
|
||||||
|
|
||||||
const min_size = this.container.element.minSize(size);
|
const new_max_anchor_x = container_size.x -| size.x;
|
||||||
this.container.resize(.{
|
const new_max_anchor_y = container_size.y -| size.y;
|
||||||
.x = min_size.x - if (this.configuration.x_axis) @as(u16, 1) else @as(u16, 0),
|
|
||||||
.y = min_size.y - if (this.configuration.y_axis) @as(u16, 1) else @as(u16, 0),
|
|
||||||
});
|
|
||||||
} else this.container.resize(this.container.element.minSize(size)); // notify the container about the minimal size it should have (can be larger)
|
|
||||||
|
|
||||||
const new_max_anchor_x = this.container.size.x -| size.x;
|
|
||||||
const new_max_anchor_y = this.container.size.y -| size.y;
|
|
||||||
|
|
||||||
// correct anchor if necessary
|
// correct anchor if necessary
|
||||||
if (new_max_anchor_x < last_max_anchor_x and this.anchor.x > new_max_anchor_x) this.anchor.x = new_max_anchor_x;
|
if (new_max_anchor_x < last_max_anchor_x and this.anchor.x > new_max_anchor_x) this.anchor.x = new_max_anchor_x;
|
||||||
if (new_max_anchor_y < last_max_anchor_y and this.anchor.y > new_max_anchor_y) this.anchor.y = new_max_anchor_y;
|
if (new_max_anchor_y < last_max_anchor_y and this.anchor.y > new_max_anchor_y) this.anchor.y = new_max_anchor_y;
|
||||||
|
|
||||||
this.container_size = this.container.size;
|
this.size = size;
|
||||||
|
this.container.resize(container_size); // notify the container about the minimal size it should have
|
||||||
|
this.container_size = container_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn reposition(ctx: *anyopaque, _: Point) void {
|
fn reposition(ctx: *anyopaque, _: Point) void {
|
||||||
@@ -305,7 +305,6 @@ pub fn Scrollable(Model: type, Event: type) type {
|
|||||||
fn handle(ctx: *anyopaque, model: *Model, event: Event) !void {
|
fn handle(ctx: *anyopaque, model: *Model, event: Event) !void {
|
||||||
const this: *@This() = @ptrCast(@alignCast(ctx));
|
const this: *@This() = @ptrCast(@alignCast(ctx));
|
||||||
switch (event) {
|
switch (event) {
|
||||||
.init => this.container.resize(this.container.element.minSize(this.size)),
|
|
||||||
// TODO what about multiple scrollable `Element` usages? mouse
|
// TODO what about multiple scrollable `Element` usages? mouse
|
||||||
// can differ between them (due to the event being only send to
|
// can differ between them (due to the event being only send to
|
||||||
// the `Container` / `Element` one under the cursor!)
|
// the `Container` / `Element` one under the cursor!)
|
||||||
|
|||||||
Reference in New Issue
Block a user