a modern tui library written in zig

examples(view): update view example

Changed files
+21 -22
examples
+21 -22
examples/view.zig
··· 130 130 }, 131 131 .winsize => |ws| try vx.resize(alloc, tty.anyWriter(), ws), 132 132 } 133 - // Bounds Check 134 - x = @min(x, map_width -| 1); 135 - y = @min(y, map_height -| 1); 136 133 137 134 const win = vx.window(); 138 135 win.clear(); ··· 154 151 ); 155 152 156 153 // Views require a Window to render to. 157 - const map_win = win.child(.{ 158 - .y_off = controls_win.height, 159 - .border = .{ .where = .top }, 160 - }); 161 - // The `View.toWin()` method takes: 162 - // 1. A Window to render to. 163 - // 2. A RenderConfig consisting of: 164 - // a. An x/y (col, row) position within the View as the start point of the render. 165 - // b. A Width and Height extending Right and Down from the start point that will represent the square being rendered. 166 - // It also returns the calculated x/y position to help maintain scrolloing boundaries. 167 - x, y = try map_view.toWin(map_win, if (!use_mini_view) .{ 168 - .x = x, 169 - .y = y, 170 - } else .{ 171 - .x = x, 172 - .y = y, 173 - .width = .{ .max = 45 }, 174 - .height = .{ .max = 15 }, 154 + const map_win = if (use_mini_view) 155 + win.child(.{ 156 + .y_off = controls_win.height, 157 + .border = .{ .where = .top }, 158 + .width = .{ .limit = 45 }, 159 + .height = .{ .limit = 15 }, 160 + }) 161 + else 162 + win.child(.{ 163 + .y_off = controls_win.height, 164 + .border = .{ .where = .top }, 165 + }); 166 + 167 + // Clamp x and y 168 + x = @min(x, map_width - map_win.width); 169 + y = @min(y, map_height - map_win.height); 170 + 171 + map_view.draw(map_win, .{ 172 + .x_off = x, 173 + .y_off = y, 175 174 }); 176 175 if (use_mini_view) { 177 - _ = try map_win.printSegment( 176 + _ = try win.printSegment( 178 177 .{ .text = "This is a mini portion of the View." }, 179 178 .{ .row_offset = 16, .col_offset = 5, .wrap = .word }, 180 179 );