stuff
This commit is contained in:
parent
695cbb1444
commit
80f1d8f8a0
1 changed files with 39 additions and 30 deletions
69
src/main.zig
69
src/main.zig
|
@ -16,21 +16,24 @@ pub fn main() !void {
|
|||
defer term.deinit();
|
||||
try term.clearScreen();
|
||||
|
||||
// var box1 = Terminal.Box.init(allocator);
|
||||
// defer box1.deinit();
|
||||
// box1.content = "hi";
|
||||
// box1.top = 0;
|
||||
// box1.bottom = 0;
|
||||
// box1.left = 0;
|
||||
// box1.right = 0;
|
||||
var box1 = Terminal.Box.init(allocator);
|
||||
defer box1.deinit();
|
||||
box1.content = "hi";
|
||||
box1.top = 0;
|
||||
box1.bottom = 0;
|
||||
box1.left = 0;
|
||||
box1.right = 0;
|
||||
|
||||
// var box2 = Terminal.Box.init(allocator);
|
||||
// defer box2.deinit();
|
||||
// box2.content = "hi";
|
||||
// box2.left = 80;
|
||||
var box2 = Terminal.Box.init(allocator);
|
||||
defer box2.deinit();
|
||||
box2.content = "hi";
|
||||
box2.top = 0;
|
||||
box2.bottom = 0;
|
||||
box2.left = 0;
|
||||
box2.right = 0;
|
||||
|
||||
// try term.box.addChild(&box1);
|
||||
// try term.box.addChild(&box2);
|
||||
try term.box.addChild(&box1);
|
||||
try box1.addChild(&box2);
|
||||
|
||||
while (true) {
|
||||
const events = try term.getEvents();
|
||||
|
@ -325,7 +328,7 @@ pub const Terminal = struct {
|
|||
.x = self.position.?.x + child.left,
|
||||
.y = self.position.?.y + child.top,
|
||||
.width = self.position.?.width - child.right - child.left,
|
||||
.height = self.position.?.height - 2,
|
||||
.height = self.position.?.height,
|
||||
} else .{
|
||||
.x = self.position.?.x + child.left,
|
||||
.y = self.position.?.y + child.top,
|
||||
|
@ -363,23 +366,23 @@ pub const Terminal = struct {
|
|||
const rect = self.getRect();
|
||||
switch (self.border_type) {
|
||||
.line => {
|
||||
var x = rect.x;
|
||||
var y = rect.y;
|
||||
try term.cursorSet(x, y);
|
||||
var x: u32 = 0;
|
||||
var y: u32 = 0;
|
||||
try term.cursorSet(rect.x, rect.y);
|
||||
try term.print("┌", .{});
|
||||
while (x < rect.x + rect.w - 2) : (x += 1) try term.print("─", .{});
|
||||
while (x < rect.w - 2) : (x += 1) try term.print("─", .{});
|
||||
try term.print("┐", .{});
|
||||
y += 1;
|
||||
while (y < rect.h - 1) : (y += 1) {
|
||||
try term.cursorSet(rect.x, rect.y + y);
|
||||
try term.print("│", .{});
|
||||
try term.cursorSet(rect.x + rect.w + 1, rect.y + y);
|
||||
try term.cursorSet(rect.w, rect.y + y);
|
||||
try term.print("│", .{});
|
||||
}
|
||||
x = rect.x;
|
||||
x = 0;
|
||||
try term.cursorSet(rect.x, rect.h);
|
||||
try term.print("└", .{});
|
||||
while (x < rect.x + rect.w - 2) : (x += 1) try term.print("─", .{});
|
||||
while (x < rect.w - 2) : (x += 1) try term.print("─", .{});
|
||||
try term.print("┘", .{});
|
||||
},
|
||||
.bg => {},
|
||||
|
@ -390,20 +393,26 @@ pub const Terminal = struct {
|
|||
}
|
||||
|
||||
fn getRect(self: *Box) Rect {
|
||||
if (self.parent) |parent| {
|
||||
if (parent.border_type == .line) return .{
|
||||
.x = self.position.?.x + 1,
|
||||
.y = self.position.?.y + 1,
|
||||
.w = self.position.?.width - 2,
|
||||
.h = self.position.?.height - 2,
|
||||
};
|
||||
}
|
||||
return .{
|
||||
var rect = Rect{
|
||||
.x = self.position.?.x,
|
||||
.y = self.position.?.y,
|
||||
.w = self.position.?.width,
|
||||
.h = self.position.?.height,
|
||||
};
|
||||
// if (self.border_type == .line) {
|
||||
// rect.x += 1;
|
||||
// rect.y += 1;
|
||||
// rect.w -= 2;
|
||||
// rect.h -= 2;
|
||||
// }
|
||||
if (self.parent) |parent| {
|
||||
const parent_rect = parent.getRect();
|
||||
rect.x += parent_rect.x + self.left;
|
||||
rect.y += parent_rect.y + self.top;
|
||||
rect.w += parent_rect.x + self.right;
|
||||
rect.h -= parent_rect.y + self.bottom;
|
||||
}
|
||||
return rect;
|
||||
}
|
||||
const Rect = struct { x: u32, y: u32, w: u32, h: u32 };
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue