this repo has no description
13
fork

Configure Feed

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

window: fix negative offset clip

Accumulate any negative offsets in order to properly clip windows to
their parents. Previously, we only clipped if the window would be off
the screen from a negative offset. In the diagram below, we should
expect that if B is a child of A, it can't print in the non-overlapping
area. That is, B can only print in the overlapping region with A because
it is a child of A. This patch fixes this.

+-----------------------------------------------------+
| |
| +--------+ |
| | B | |
| | +---|-----+ |
| | | | | |
| +--------+ | |
| | | |
| | A | |
| +---------+ |
| |
| |
| |
+-----------------------------------------------------+

+54 -6
+2
src/Vaxis.zig
··· 205 205 return .{ 206 206 .x_off = 0, 207 207 .y_off = 0, 208 + .parent_x_off = 0, 209 + .parent_y_off = 0, 208 210 .width = self.screen.width, 209 211 .height = self.screen.height, 210 212 .screen = &self.screen,
+52 -6
src/Window.zig
··· 9 9 10 10 const Window = @This(); 11 11 12 - /// horizontal offset from the screen 12 + /// absolute horizontal offset from the screen 13 13 x_off: i17, 14 - /// vertical offset from the screen 14 + /// absolute vertical offset from the screen 15 15 y_off: i17, 16 + /// relative horizontal offset, from parent window. This only accumulates if it is negative so that 17 + /// we can clip the window correctly 18 + parent_x_off: i17, 19 + /// relative vertical offset, from parent window. This only accumulates if it is negative so that 20 + /// we can clip the window correctly 21 + parent_y_off: i17, 16 22 /// width of the window. This can't be larger than the terminal screen 17 23 width: u16, 18 24 /// height of the window. This can't be larger than the terminal screen ··· 36 42 return Window{ 37 43 .x_off = x_off + self.x_off, 38 44 .y_off = y_off + self.y_off, 45 + .parent_x_off = @min(self.parent_x_off + x_off, 0), 46 + .parent_y_off = @min(self.parent_y_off + y_off, 0), 39 47 .width = width, 40 48 .height = height, 41 49 .screen = self.screen, ··· 165 173 166 174 /// writes a cell to the location in the window 167 175 pub fn writeCell(self: Window, col: u16, row: u16, cell: Cell) void { 168 - if (self.height <= row or self.width <= col) return; 169 - if (self.x_off + col < 0) return; 170 - if (self.y_off + row < 0) return; 176 + if (self.height <= row or 177 + self.width <= col or 178 + self.x_off + col < 0 or 179 + self.y_off + row < 0 or 180 + self.parent_x_off + col < 0 or 181 + self.parent_y_off + row < 0) 182 + return; 183 + 171 184 self.screen.writeCell(@intCast(col + self.x_off), @intCast(row + self.y_off), cell); 172 185 } 173 186 ··· 176 189 if (self.height <= row or 177 190 self.width <= col or 178 191 self.x_off + col < 0 or 179 - self.y_off + row < 0) 192 + self.y_off + row < 0 or 193 + self.parent_x_off + col < 0 or 194 + self.parent_y_off + row < 0) 180 195 return null; 181 196 return self.screen.readCell(@intCast(col + self.x_off), @intCast(row + self.y_off)); 182 197 } ··· 465 480 var parent = Window{ 466 481 .x_off = 0, 467 482 .y_off = 0, 483 + .parent_x_off = 0, 484 + .parent_y_off = 0, 468 485 .width = 20, 469 486 .height = 20, 470 487 .screen = undefined, ··· 479 496 var parent = Window{ 480 497 .x_off = 0, 481 498 .y_off = 0, 499 + .parent_x_off = 0, 500 + .parent_y_off = 0, 482 501 .width = 20, 483 502 .height = 20, 484 503 .screen = undefined, ··· 493 512 var parent = Window{ 494 513 .x_off = 0, 495 514 .y_off = 0, 515 + .parent_x_off = 0, 516 + .parent_y_off = 0, 496 517 .width = 20, 497 518 .height = 20, 498 519 .screen = undefined, ··· 507 528 var parent = Window{ 508 529 .x_off = 1, 509 530 .y_off = 1, 531 + .parent_x_off = 0, 532 + .parent_y_off = 0, 510 533 .width = 20, 511 534 .height = 20, 512 535 .screen = undefined, ··· 517 540 try std.testing.expectEqual(11, ch.y_off); 518 541 } 519 542 543 + test "Window offsets" { 544 + var parent = Window{ 545 + .x_off = 0, 546 + .y_off = 0, 547 + .parent_x_off = 0, 548 + .parent_y_off = 0, 549 + .width = 20, 550 + .height = 20, 551 + .screen = undefined, 552 + }; 553 + 554 + const ch = parent.initChild(10, 10, 21, 21); 555 + const ch2 = ch.initChild(-4, -4, null, null); 556 + // Reading ch2 at row 0 should be null 557 + try std.testing.expect(ch2.readCell(0, 0) == null); 558 + // Should not panic us 559 + ch2.writeCell(0, 0, undefined); 560 + } 561 + 520 562 test "print: grapheme" { 521 563 const alloc = std.testing.allocator_instance.allocator(); 522 564 const unicode = try Unicode.init(alloc); ··· 525 567 const win: Window = .{ 526 568 .x_off = 0, 527 569 .y_off = 0, 570 + .parent_x_off = 0, 571 + .parent_y_off = 0, 528 572 .width = 4, 529 573 .height = 2, 530 574 .screen = &screen, ··· 592 636 const win: Window = .{ 593 637 .x_off = 0, 594 638 .y_off = 0, 639 + .parent_x_off = 0, 640 + .parent_y_off = 0, 595 641 .width = 4, 596 642 .height = 2, 597 643 .screen = &screen,