examples(view): update view example
This commit is contained in:
parent
a426b5c96e
commit
f3c81292b1
1 changed files with 21 additions and 22 deletions
|
@ -130,9 +130,6 @@ pub fn main() !void {
|
||||||
},
|
},
|
||||||
.winsize => |ws| try vx.resize(alloc, tty.anyWriter(), ws),
|
.winsize => |ws| try vx.resize(alloc, tty.anyWriter(), ws),
|
||||||
}
|
}
|
||||||
// Bounds Check
|
|
||||||
x = @min(x, map_width -| 1);
|
|
||||||
y = @min(y, map_height -| 1);
|
|
||||||
|
|
||||||
const win = vx.window();
|
const win = vx.window();
|
||||||
win.clear();
|
win.clear();
|
||||||
|
@ -154,27 +151,29 @@ pub fn main() !void {
|
||||||
);
|
);
|
||||||
|
|
||||||
// Views require a Window to render to.
|
// Views require a Window to render to.
|
||||||
const map_win = win.child(.{
|
const map_win = if (use_mini_view)
|
||||||
.y_off = controls_win.height,
|
win.child(.{
|
||||||
.border = .{ .where = .top },
|
.y_off = controls_win.height,
|
||||||
});
|
.border = .{ .where = .top },
|
||||||
// The `View.toWin()` method takes:
|
.width = .{ .limit = 45 },
|
||||||
// 1. A Window to render to.
|
.height = .{ .limit = 15 },
|
||||||
// 2. A RenderConfig consisting of:
|
})
|
||||||
// a. An x/y (col, row) position within the View as the start point of the render.
|
else
|
||||||
// b. A Width and Height extending Right and Down from the start point that will represent the square being rendered.
|
win.child(.{
|
||||||
// It also returns the calculated x/y position to help maintain scrolloing boundaries.
|
.y_off = controls_win.height,
|
||||||
x, y = try map_view.toWin(map_win, if (!use_mini_view) .{
|
.border = .{ .where = .top },
|
||||||
.x = x,
|
});
|
||||||
.y = y,
|
|
||||||
} else .{
|
// Clamp x and y
|
||||||
.x = x,
|
x = @min(x, map_width - map_win.width);
|
||||||
.y = y,
|
y = @min(y, map_height - map_win.height);
|
||||||
.width = .{ .max = 45 },
|
|
||||||
.height = .{ .max = 15 },
|
map_view.draw(map_win, .{
|
||||||
|
.x_off = x,
|
||||||
|
.y_off = y,
|
||||||
});
|
});
|
||||||
if (use_mini_view) {
|
if (use_mini_view) {
|
||||||
_ = try map_win.printSegment(
|
_ = try win.printSegment(
|
||||||
.{ .text = "This is a mini portion of the View." },
|
.{ .text = "This is a mini portion of the View." },
|
||||||
.{ .row_offset = 16, .col_offset = 5, .wrap = .word },
|
.{ .row_offset = 16, .col_offset = 5, .wrap = .word },
|
||||||
);
|
);
|
||||||
|
|
Loading…
Add table
Reference in a new issue