don't require the color and the width in mez.view.set_border

This commit is contained in:
Squibid 2026-03-01 22:38:25 -05:00
parent 6be66b6a71
commit 87259f96cb
Signed by: squibid
GPG key ID: BECE5684D3C4005D

View file

@ -328,11 +328,14 @@ pub fn get_resizing(L: *zlua.Lua) i32 {
pub fn set_border(L: *zlua.Lua) i32 {
const view_id = LuaUtils.coerceInteger(u64, L.checkInteger(1)) catch view_id_err(L);
var border_color: ?[4]f32 = null;
var width: ?u32 = null;
_ = L.pushString("color");
_ = L.getTable(2);
if (L.getTable(2) != .nil) {
if (!L.isString(-1)) L.raiseErrorStr("The color must be a string", .{});
const color = L.checkString(-1);
const border_color: [4]f32 = color: {
border_color = color: {
errdefer L.raiseErrorStr("The color must be a valid hex string", .{});
var start_color_idx: u8 = 0;
@ -352,18 +355,20 @@ pub fn set_border(L: *zlua.Lua) i32 {
break :color .{ r, g, b, a };
};
}
_ = L.pushString("width");
_ = L.getTable(2);
const width = LuaUtils.coerceInteger(u32, L.checkInteger(-1)) catch {
if (L.getTable(2) != .nil) {
width = LuaUtils.coerceInteger(u32, L.checkInteger(-1)) catch {
L.raiseErrorStr("The border width must be >= 0 and < inf", .{});
};
}
if (LuaUtils.viewById(view_id)) |v| {
v.setBorderColor(&border_color);
if (border_color != null) v.setBorderColor(&border_color.?);
if (width != v.border_width) {
v.border_width = @intCast(width);
if (width != null and width.? != v.border_width) {
v.border_width = @intCast(width.?);
// the size has changed which means we need to update the borders
v.resizeBorders();
}