From 96cbae13fcb8ee313d62de13ee3f1b62e733af3a Mon Sep 17 00:00:00 2001 From: 00JCIV00 Date: Mon, 11 Mar 2024 16:52:14 -0400 Subject: [PATCH] Improved Integer bounds checking with Saturated Operators. --- src/widgets/border.zig | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/widgets/border.zig b/src/widgets/border.zig index f7e3de3..fe62aeb 100644 --- a/src/widgets/border.zig +++ b/src/widgets/border.zig @@ -15,20 +15,20 @@ pub fn all(win: Window, style: Style) Window { const h = win.height; const w = win.width; win.writeCell(0, 0, .{ .char = top_left, .style = style }); - win.writeCell(0, h - 1, .{ .char = bottom_left, .style = style }); - win.writeCell(w - 1, 0, .{ .char = top_right, .style = style }); - win.writeCell(w - 1, h - 1, .{ .char = bottom_right, .style = style }); + win.writeCell(0, h -| 1, .{ .char = bottom_left, .style = style }); + win.writeCell(w -| 1, 0, .{ .char = top_right, .style = style }); + win.writeCell(w -| 1, h -| 1, .{ .char = bottom_right, .style = style }); var i: usize = 1; - while (i < (h - 1)) : (i += 1) { + while (i < (h -| 1)) : (i += 1) { win.writeCell(0, i, .{ .char = vertical, .style = style }); - win.writeCell(w - 1, i, .{ .char = vertical, .style = style }); + win.writeCell(w -| 1, i, .{ .char = vertical, .style = style }); } i = 1; - while (i < w - 1) : (i += 1) { + while (i < w -| 1) : (i += 1) { win.writeCell(i, 0, .{ .char = horizontal, .style = style }); - win.writeCell(i, h - 1, .{ .char = horizontal, .style = style }); + win.writeCell(i, h -| 1, .{ .char = horizontal, .style = style }); } - return win.initChild(1, 1, .{ .limit = w - 2 }, .{ .limit = h - 2 }); + return win.initChild(1, 1, .{ .limit = w -| 2 }, .{ .limit = h -| 2 }); } pub fn right(win: Window, style: Style) Window { @@ -36,9 +36,9 @@ pub fn right(win: Window, style: Style) Window { const w = win.width; var i: usize = 0; while (i < h) : (i += 1) { - win.writeCell(w - 1, i, .{ .char = vertical, .style = style }); + win.writeCell(w -| 1, i, .{ .char = vertical, .style = style }); } - return win.initChild(0, 0, .{ .limit = w - 1 }, .expand); + return win.initChild(0, 0, .{ .limit = w -| 1 }, .expand); } pub fn bottom(win: Window, style: Style) Window { @@ -46,7 +46,7 @@ pub fn bottom(win: Window, style: Style) Window { const w = win.width; var i: usize = 0; while (i < w) : (i += 1) { - win.writeCell(i, h - 1, .{ .char = horizontal, .style = style }); + win.writeCell(i, h -| 1, .{ .char = horizontal, .style = style }); } - return win.initChild(0, 0, .expand, .{ .limit = h - 1 }); + return win.initChild(0, 0, .expand, .{ .limit = h -| 1 }); }