refactor: zigify imports and correct minor mistakes
This commit is contained in:
@@ -1,22 +1,5 @@
|
||||
const std = @import("std");
|
||||
const input = @import("input.zig");
|
||||
|
||||
const isTaggedUnion = @import("event.zig").isTaggedUnion;
|
||||
|
||||
const Cell = @import("cell.zig");
|
||||
const Color = @import("color.zig").Color;
|
||||
const Point = @import("point.zig").Point;
|
||||
const Style = @import("style.zig");
|
||||
const Error = @import("error.zig").Error;
|
||||
|
||||
const log = std.log.scoped(.container);
|
||||
|
||||
/// Border configuration struct
|
||||
pub const Border = packed struct {
|
||||
// corners:
|
||||
const rounded_border: [6]u21 = .{ '╭', '─', '╮', '│', '╰', '╯' };
|
||||
const squared_border: [6]u21 = .{ '┌', '─', '┐', '│', '└', '┘' };
|
||||
|
||||
/// Color to use for the border
|
||||
color: Color = .default,
|
||||
/// Configure the corner type to be used for the border
|
||||
@@ -40,13 +23,12 @@ pub const Border = packed struct {
|
||||
} = .{},
|
||||
|
||||
pub fn content(this: @This(), cells: []Cell, size: Point) void {
|
||||
std.debug.assert(cells.len == @as(usize, size.x) * @as(usize, size.y));
|
||||
assert(cells.len == @as(usize, size.x) * @as(usize, size.y));
|
||||
|
||||
const frame = switch (this.corners) {
|
||||
.rounded => Border.rounded_border,
|
||||
.squared => Border.squared_border,
|
||||
const frame: [6]u21 = switch (this.corners) {
|
||||
.rounded => .{ '╭', '─', '╮', '│', '╰', '╯' },
|
||||
.squared => .{ '┌', '─', '┐', '│', '└', '┘' },
|
||||
};
|
||||
std.debug.assert(frame.len == 6);
|
||||
|
||||
// render top and bottom border
|
||||
if (this.sides.top or this.sides.bottom) {
|
||||
@@ -156,7 +138,7 @@ pub const Rectangle = packed struct {
|
||||
|
||||
// NOTE caller owns `Cells` slice and ensures that `cells.len == size.x * size.y`
|
||||
pub fn content(this: @This(), cells: []Cell, size: Point) void {
|
||||
std.debug.assert(cells.len == @as(usize, size.x) * @as(usize, size.y));
|
||||
assert(cells.len == @as(usize, size.x) * @as(usize, size.y));
|
||||
|
||||
for (0..size.y) |row| {
|
||||
for (0..size.x) |col| {
|
||||
@@ -300,11 +282,6 @@ pub const Rectangle = packed struct {
|
||||
|
||||
/// Layout configuration struct
|
||||
pub const Layout = packed struct {
|
||||
// separator.line:
|
||||
const line: [2]u21 = .{ '│', '─' };
|
||||
const dotted: [2]u21 = .{ '┆', '┄' };
|
||||
const double: [2]u21 = .{ '║', '═' };
|
||||
|
||||
/// control the direction in which child elements are laid out
|
||||
direction: enum(u1) { horizontal, vertical } = .horizontal,
|
||||
/// Padding outside of the child elements
|
||||
@@ -343,13 +320,13 @@ pub const Layout = packed struct {
|
||||
} = .{},
|
||||
|
||||
pub fn content(this: @This(), comptime C: type, cells: []Cell, origin: Point, size: Point, children: []const C) void {
|
||||
std.debug.assert(cells.len == @as(usize, size.x) * @as(usize, size.y));
|
||||
assert(cells.len == @as(usize, size.x) * @as(usize, size.y));
|
||||
|
||||
if (this.separator.enabled and children.len > 1) {
|
||||
const line_cps: [2]u21 = switch (this.separator.line) {
|
||||
.line => line,
|
||||
.dotted => dotted,
|
||||
.double => double,
|
||||
.line => .{ '│', '─' },
|
||||
.dotted => .{ '┆', '┄' },
|
||||
.double => .{ '║', '═' },
|
||||
};
|
||||
const gap: u16 = (this.gap + 1) / 2;
|
||||
|
||||
@@ -574,7 +551,7 @@ pub fn Container(comptime Event: type) type {
|
||||
|
||||
const Element = @import("element.zig").Element(Event);
|
||||
return struct {
|
||||
allocator: std.mem.Allocator,
|
||||
allocator: Allocator,
|
||||
origin: Point,
|
||||
size: Point,
|
||||
properties: Properties,
|
||||
@@ -592,7 +569,7 @@ pub fn Container(comptime Event: type) type {
|
||||
};
|
||||
|
||||
pub fn init(
|
||||
allocator: std.mem.Allocator,
|
||||
allocator: Allocator,
|
||||
properties: Properties,
|
||||
element: Element,
|
||||
) !@This() {
|
||||
@@ -872,7 +849,7 @@ pub fn Container(comptime Event: type) type {
|
||||
switch (event) {
|
||||
.mouse => |mouse| if (mouse.in(this.origin, this.size)) {
|
||||
// the element receives the mouse event with relative position
|
||||
std.debug.assert(mouse.x >= this.origin.x and mouse.y >= this.origin.y);
|
||||
assert(mouse.x >= this.origin.x and mouse.y >= this.origin.y);
|
||||
var relative_mouse: input.Mouse = mouse;
|
||||
relative_mouse.x -= this.origin.x;
|
||||
relative_mouse.y -= this.origin.y;
|
||||
@@ -907,10 +884,21 @@ pub fn Container(comptime Event: type) type {
|
||||
};
|
||||
}
|
||||
|
||||
const log = std.log.scoped(.container);
|
||||
|
||||
const std = @import("std");
|
||||
const assert = std.debug.assert;
|
||||
const Allocator = std.mem.Allocator;
|
||||
const input = @import("input.zig");
|
||||
const isTaggedUnion = @import("event.zig").isTaggedUnion;
|
||||
const Cell = @import("cell.zig");
|
||||
const Color = @import("color.zig").Color;
|
||||
const Point = @import("point.zig").Point;
|
||||
const Style = @import("style.zig");
|
||||
const Error = @import("error.zig").Error;
|
||||
|
||||
test {
|
||||
_ = Border;
|
||||
_ = Layout;
|
||||
_ = Rectangle;
|
||||
@import("std").testing.refAllDeclsRecursive(@This());
|
||||
}
|
||||
|
||||
test "Container Fixed and Grow Size Vertical" {
|
||||
|
||||
Reference in New Issue
Block a user