diff --git a/src/container.zig b/src/container.zig index 4bb91c0..a024096 100644 --- a/src/container.zig +++ b/src/container.zig @@ -6,6 +6,7 @@ const Cell = @import("cell.zig"); const Color = @import("color.zig").Color; const Size = @import("size.zig").Size; const Style = @import("style.zig"); +const Error = @import("error.zig").Error; const log = std.log.scoped(.container); @@ -144,7 +145,7 @@ pub const Rectangle = packed struct { /// children accordingly without removing the coloring of the `Rectangle` fill: Color = .default, - // NOTE: caller owns `cells` slice and ensures that `cells.len == size.cols * size.rows` + // NOTE: caller owns `Cells` slice and ensures that `cells.len == size.cols * size.rows` pub fn contents(this: @This(), cells: []Cell, size: Size) void { std.debug.assert(cells.len == @as(usize, size.cols) * @as(usize, size.rows)); @@ -600,8 +601,8 @@ pub fn Container(comptime Event: type) type { size.rows, }); this.size = size; - if (this.properties.fixed_size.cols > 0 and size.cols < this.properties.fixed_size.cols) return error.TooSmall; - if (this.properties.fixed_size.rows > 0 and size.rows < this.properties.fixed_size.rows) return error.TooSmall; + if (this.properties.fixed_size.cols > 0 and size.cols < this.properties.fixed_size.cols) return Error.TooSmall; + if (this.properties.fixed_size.rows > 0 and size.rows < this.properties.fixed_size.rows) return Error.TooSmall; try this.element.handle(event); @@ -623,8 +624,8 @@ pub fn Container(comptime Event: type) type { } // check if the available screen is large enough switch (layout.direction) { - .horizontal => if (fixed_size.cols > size.cols) return error.TooSmall, - .vertical => if (fixed_size.rows > size.rows) return error.TooSmall, + .horizontal => if (fixed_size.cols > size.cols) return Error.TooSmall, + .vertical => if (fixed_size.rows > size.rows) return Error.TooSmall, } const sides = this.properties.border.sides; const padding = layout.padding; diff --git a/src/error.zig b/src/error.zig new file mode 100644 index 0000000..1cae8ac --- /dev/null +++ b/src/error.zig @@ -0,0 +1,4 @@ +pub const Error = error{ + /// Thrown when a `Container` is too small to be rendered in the current screen part. + TooSmall, +}; diff --git a/src/zterm.zig b/src/zterm.zig index b32042f..163b940 100644 --- a/src/zterm.zig +++ b/src/zterm.zig @@ -8,6 +8,7 @@ pub const input = @import("input.zig"); pub const testing = @import("testing.zig"); pub const App = @import("app.zig").App; +pub const Error = @import("error.zig").Error; // App also exports further types once initialized with the user events at compile time: // `App.Container` // `App.Element` @@ -31,6 +32,7 @@ test { _ = @import("terminal.zig"); _ = @import("container.zig"); _ = @import("queue.zig"); + _ = @import("error.zig"); _ = color; _ = size;