this repo has no description
13
fork

Configure Feed

Select the types of activity you want to include in your feed.

window!: use nullable width and height

Use a nullable width and height when creating a child window

Fixes: #84

+53 -67
+2 -2
README.md
··· 187 187 const child = win.child(.{ 188 188 .x_off = win.width / 2 - 20, 189 189 .y_off = win.height / 2 - 3, 190 - .width = .{ .limit = 40 }, 191 - .height = .{ .limit = 3 }, 190 + .width = 40 , 191 + .height = 3 , 192 192 .border = .{ 193 193 .where = .all, 194 194 .style = style,
+8 -8
examples/table.zig
··· 219 219 const see_win = win.child(.{ 220 220 .x_off = 0, 221 221 .y_off = 1, 222 - .width = .{ .limit = win.width }, 223 - .height = .{ .limit = 4 }, 222 + .width = win.width, 223 + .height = 4, 224 224 }); 225 225 see_win.fill(.{ .style = .{ .bg = ctx.bg } }); 226 226 const content_logo = ··· 256 256 const top_bar = win.child(.{ 257 257 .x_off = 0, 258 258 .y_off = 0, 259 - .width = .{ .limit = win.width }, 260 - .height = .{ .limit = win.height / top_div }, 259 + .width = win.width, 260 + .height = win.height / top_div, 261 261 }); 262 262 for (title_segs[0..]) |*title_seg| 263 263 title_seg.style.bg = if (active == .top) selected_bg else other_bg; ··· 275 275 const middle_bar = win.child(.{ 276 276 .x_off = 0, 277 277 .y_off = win.height / top_div, 278 - .width = .{ .limit = win.width }, 279 - .height = .{ .limit = win.height - (top_bar.height + 1) }, 278 + .width = win.width, 279 + .height = win.height - (top_bar.height + 1), 280 280 }); 281 281 if (user_list.items.len > 0) { 282 282 demo_tbl.active = active == .mid; ··· 294 294 const bottom_bar = win.child(.{ 295 295 .x_off = 0, 296 296 .y_off = win.height - 1, 297 - .width = .{ .limit = win.width }, 298 - .height = .{ .limit = 1 }, 297 + .width = win.width, 298 + .height = 1, 299 299 }); 300 300 if (active == .btm) bottom_bar.fill(.{ .style = .{ .bg = active_bg } }); 301 301 cmd_input.draw(bottom_bar);
+2 -2
examples/text_input.zig
··· 141 141 const child = win.child(.{ 142 142 .x_off = win.width / 2 - 20, 143 143 .y_off = win.height / 2 - 3, 144 - .width = .{ .limit = 40 }, 145 - .height = .{ .limit = 3 }, 144 + .width = 40, 145 + .height = 3, 146 146 .border = .{ 147 147 .where = .all, 148 148 .style = style,
+3 -3
examples/view.zig
··· 135 135 win.clear(); 136 136 137 137 const controls_win = win.child(.{ 138 - .height = .{ .limit = 1 }, 138 + .height = 1, 139 139 }); 140 140 _ = controls_win.print( 141 141 if (win.width >= 112) &.{ ··· 155 155 win.child(.{ 156 156 .y_off = controls_win.height, 157 157 .border = .{ .where = .top }, 158 - .width = .{ .limit = 45 }, 159 - .height = .{ .limit = 15 }, 158 + .width = 45, 159 + .height = 15, 160 160 }) 161 161 else 162 162 win.child(.{
+2 -2
examples/vt.zig
··· 94 94 const child = win.child(.{ 95 95 .x_off = 4, 96 96 .y_off = 2, 97 - .width = .{ .limit = win.width - 8 }, 98 - .height = .{ .limit = win.width - 6 }, 97 + .width = 8, 98 + .height = 6, 99 99 .border = .{ 100 100 .where = .all, 101 101 },
+18 -32
src/Window.zig
··· 9 9 10 10 const Window = @This(); 11 11 12 - pub const Size = union(enum) { 13 - expand, 14 - limit: u16, 15 - }; 16 - 17 12 /// horizontal offset from the screen 18 13 x_off: u16, 19 14 /// vertical offset from the screen ··· 32 27 self: Window, 33 28 x_off: u16, 34 29 y_off: u16, 35 - width: Size, 36 - height: Size, 30 + maybe_width: ?u16, 31 + maybe_height: ?u16, 37 32 ) Window { 38 - const resolved_width: u16 = switch (width) { 39 - .expand => self.width -| x_off, 40 - .limit => |w| blk: { 41 - if (w + x_off > self.width) { 42 - break :blk self.width -| x_off; 43 - } 44 - break :blk w; 45 - }, 46 - }; 47 - const resolved_height: u16 = switch (height) { 48 - .expand => self.height -| y_off, 49 - .limit => |h| blk: { 50 - if (h + y_off > self.height) { 51 - break :blk self.height -| y_off; 52 - } 53 - break :blk h; 54 - }, 55 - }; 33 + const resolved_width: u16 = if (maybe_width) |width| 34 + @min(width, self.width -| x_off) 35 + else 36 + self.width -| x_off; 37 + 38 + const resolved_height: u16 = if (maybe_height) |height| 39 + @min(height, self.height -| y_off) 40 + else 41 + self.height -| y_off; 56 42 return Window{ 57 43 .x_off = x_off + self.x_off, 58 44 .y_off = y_off + self.y_off, ··· 66 52 x_off: u16 = 0, 67 53 y_off: u16 = 0, 68 54 /// the width of the resulting child, including any borders 69 - width: Size = .expand, 55 + width: ?u16 = null, 70 56 /// the height of the resulting child, including any borders 71 - height: Size = .expand, 57 + height: ?u16 = null, 72 58 border: BorderOptions = .{}, 73 59 }; 74 60 ··· 180 166 const w_delt: u16 = if (loc.right) 1 else 0; 181 167 const h_ch: u16 = h -| y_off -| h_delt; 182 168 const w_ch: u16 = w -| x_off -| w_delt; 183 - return result.initChild(x_off, y_off, .{ .limit = w_ch }, .{ .limit = h_ch }); 169 + return result.initChild(x_off, y_off, w_ch, h_ch); 184 170 } 185 171 186 172 /// writes a cell to the location in the window ··· 479 465 .screen = undefined, 480 466 }; 481 467 482 - const ch = parent.initChild(1, 1, .expand, .expand); 468 + const ch = parent.initChild(1, 1, null, null); 483 469 try std.testing.expectEqual(19, ch.width); 484 470 try std.testing.expectEqual(19, ch.height); 485 471 } ··· 493 479 .screen = undefined, 494 480 }; 495 481 496 - const ch = parent.initChild(0, 0, .{ .limit = 21 }, .{ .limit = 21 }); 482 + const ch = parent.initChild(0, 0, 21, 21); 497 483 try std.testing.expectEqual(20, ch.width); 498 484 try std.testing.expectEqual(20, ch.height); 499 485 } ··· 507 493 .screen = undefined, 508 494 }; 509 495 510 - const ch = parent.initChild(10, 10, .{ .limit = 21 }, .{ .limit = 21 }); 496 + const ch = parent.initChild(10, 10, 21, 21); 511 497 try std.testing.expectEqual(10, ch.width); 512 498 try std.testing.expectEqual(10, ch.height); 513 499 } ··· 521 507 .screen = undefined, 522 508 }; 523 509 524 - const ch = parent.initChild(10, 10, .{ .limit = 21 }, .{ .limit = 21 }); 510 + const ch = parent.initChild(10, 10, 21, 21); 525 511 try std.testing.expectEqual(11, ch.x_off); 526 512 try std.testing.expectEqual(11, ch.y_off); 527 513 }
+2 -2
src/widgets/CodeView.zig
··· 39 39 nl.draw(win.child(.{ 40 40 .x_off = 0, 41 41 .y_off = 0, 42 - .width = .{ .limit = pad_left }, 43 - .height = .{ .limit = win.height }, 42 + .width = pad_left, 43 + .height = win.height, 44 44 }), self.scroll_view.scroll.y); 45 45 } 46 46 self.drawCode(win.child(.{ .x_off = pad_left }), buffer, opts);
+4 -4
src/widgets/ScrollView.zig
··· 65 65 }; 66 66 const bg = parent.child(.{ 67 67 .x_off = parent.width -| opts.character.width, 68 - .width = .{ .limit = opts.character.width }, 69 - .height = .{ .limit = parent.height }, 68 + .width = opts.character.width, 69 + .height = parent.height, 70 70 }); 71 71 bg.fill(.{ .char = opts.character, .style = opts.bg }); 72 72 vbar.draw(bg); ··· 115 115 pub fn writeCell(self: *@This(), parent: vaxis.Window, col: usize, row: usize, cell: vaxis.Cell) void { 116 116 const b = self.bounds(parent); 117 117 if (!b.inside(col, row)) return; 118 - const win = parent.child(.{ .width = .{ .limit = b.x2 - b.x1 }, .height = .{ .limit = b.y2 - b.y1 } }); 118 + const win = parent.child(.{ .width = b.x2 - b.x1, .height = b.y2 - b.y1 }); 119 119 win.writeCell(col -| self.scroll.x, row -| self.scroll.y, cell); 120 120 } 121 121 ··· 123 123 pub fn readCell(self: *@This(), parent: vaxis.Window, col: usize, row: usize) ?vaxis.Cell { 124 124 const b = self.bounds(parent); 125 125 if (!b.inside(col, row)) return; 126 - const win = parent.child(.{ .width = .{ .limit = b.width }, .height = .{ .limit = b.height } }); 126 + const win = parent.child(.{ .width = b.width, .height = b.height }); 127 127 return win.readCell(col -| self.scroll.x, row -| self.scroll.y); 128 128 }
+8 -8
src/widgets/Table.zig
··· 211 211 212 212 const table_win = win.child(.{ 213 213 .y_off = table_ctx.y_off, 214 - .width = .{ .limit = win.width }, 215 - .height = .{ .limit = win.height }, 214 + .width = win.width, 215 + .height = win.height, 216 216 }); 217 217 218 218 // Headers ··· 237 237 const hdr_win = table_win.child(.{ 238 238 .x_off = col_start, 239 239 .y_off = 0, 240 - .width = .{ .limit = col_width }, 241 - .height = .{ .limit = 1 }, 240 + .width = col_width, 241 + .height = 1, 242 242 .border = .{ .where = if (table_ctx.header_borders and idx > 0) .left else .none }, 243 243 }); 244 244 var hdr = switch (table_ctx.header_align) { ··· 297 297 var row_win = table_win.child(.{ 298 298 .x_off = 0, 299 299 .y_off = @intCast(1 + row + table_ctx.active_y_off), 300 - .width = .{ .limit = table_win.width }, 301 - .height = .{ .limit = 1 }, 300 + .width = table_win.width, 301 + .height = 1, 302 302 //.border = .{ .where = if (table_ctx.row_borders) .top else .none }, 303 303 }); 304 304 if (table_ctx.start + row == table_ctx.row) { ··· 328 328 const item_win = row_win.child(.{ 329 329 .x_off = col_start, 330 330 .y_off = 0, 331 - .width = .{ .limit = col_width }, 332 - .height = .{ .limit = 1 }, 331 + .width = col_width, 332 + .height = 1, 333 333 .border = .{ .where = if (table_ctx.col_borders and col_idx > 0) .left else .none }, 334 334 }); 335 335 const item_txt = switch (ItemT) {
+2 -2
src/widgets/View.zig
··· 115 115 x = @min(x, self.screen.width -| width); 116 116 y = @min(y, self.screen.height -| height); 117 117 const child = win.child(.{ 118 - .width = .{ .limit = width }, 119 - .height = .{ .limit = height }, 118 + .width = width, 119 + .height = height, 120 120 }); 121 121 self.draw(child, .{ .x_off = x, .y_off = y }); 122 122 return .{ x, y };
+2 -2
src/widgets/alignment.zig
··· 6 6 return parent.child(.{ 7 7 .x_off = x_off, 8 8 .y_off = y_off, 9 - .width = .{ .limit = cols }, 10 - .height = .{ .limit = rows }, 9 + .width = cols, 10 + .height = rows, 11 11 }); 12 12 }