refactor: move from_client_box and to_client_box to Widget.Box

This commit is contained in:
CJ van den Berg 2025-11-30 22:49:05 +01:00
parent 9557703fc9
commit 393c18c54e
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9
4 changed files with 34 additions and 33 deletions

View file

@ -1,5 +1,6 @@
const Plane = @import("renderer").Plane;
const Layer = @import("renderer").Layer;
const WidgetStyle = @import("WidgetStyle.zig");
const Self = @This();
@ -36,6 +37,30 @@ pub fn from(n: Plane) Self {
};
}
pub fn from_client_box(self: Self, padding: WidgetStyle.Margin) Self {
const total_y_padding = padding.top + padding.bottom;
const total_x_padding = padding.left + padding.right;
const y = if (self.y < padding.top) padding.top else self.y;
const x = if (self.x < padding.left) padding.left else self.x;
var box = self;
box.y = y - padding.top;
box.h += total_y_padding;
box.x = x - padding.left;
box.w += total_x_padding;
return box;
}
pub fn to_client_box(self: Self, padding: WidgetStyle.Margin) Self {
const total_y_padding = padding.top + padding.bottom;
const total_x_padding = padding.left + padding.right;
var box = self;
box.y += padding.top;
box.h -= if (box.h > total_y_padding) total_y_padding else box.h;
box.x += padding.left;
box.w -= if (box.w > total_x_padding) total_x_padding else box.w;
return box;
}
pub fn to_layer(self: Self) Layer.Options {
return .{
.y = @intCast(self.y),