this repo has no description
13
fork

Configure Feed

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

view: continued initial implementation

- Added proper bounds checking to fit the View within the provided Window.
- Added a simple x/y return Type to the `toWin()` function so users can more easily maintain scrolling bounds.

authored by

00JCIV00 and committed by
Tim Culverhouse
a7fcbe2d 94bec1ec

+17 -14
+17 -14
src/View.zig
··· 57 57 self.alloc.destroy(self.screen); 58 58 } 59 59 60 - ///Render Config f/ `toWin()` 60 + /// Render Config f/ `toWin()` 61 61 pub const RenderConfig = struct { 62 62 x: usize = 0, 63 63 y: usize = 0, ··· 70 70 }; 71 71 }; 72 72 /// Render a portion of this View to the provided Window (`win`). 73 - pub fn toWin(self: *View, win: *const Window, config: RenderConfig) !void { 74 - //if (config.x >= self.screen.width or config.y >= self.screen.height) 75 - // return error.PositionOutOfBounds; 76 - const x = @min(self.screen.width - 1, config.x); 77 - const y = @min(self.screen.height - 1, config.y); 73 + /// This will return the bounded X (col), Y (row) coordinates based on the rendering. 74 + pub fn toWin(self: *View, win: *const Window, config: RenderConfig) !struct{ usize, usize } { 75 + var x = @min(self.screen.width - 1, config.x); 76 + var y = @min(self.screen.height - 1, config.y); 78 77 const width = width: { 79 - const width = switch (config.width) { 78 + var width = switch (config.width) { 80 79 .fit => win.width, 81 80 .max => |w| @min(win.width, w), 82 81 }; 83 - break :width @min(width, self.screen.width -| x); 82 + width = @min(width, self.screen.width); 83 + break :width @min(width, self.screen.width -| 1 -| x +| win.width); 84 84 }; 85 85 const height = height: { 86 - const height = switch (config.height) { 86 + var height = switch (config.height) { 87 87 .fit => win.height, 88 88 .max => |h| @min(win.height, h), 89 89 }; 90 - break :height @min(height, self.screen.height -| y); 90 + height = @min(height, self.screen.height); 91 + break :height @min(height, self.screen.height -| 1 -| y +| win.height); 91 92 }; 92 - //win.clear(); 93 + x = @min(x, self.screen.width -| width); 94 + y = @min(y, self.screen.height -| height); 95 + 93 96 for (0..height) |row| { 94 97 for (0..width) |col| { 95 98 win.writeCell( 96 99 col, 97 100 row, 98 101 self.win.readCell( 99 - @min(self.screen.width, x +| col), 100 - //self.screen.height -| 1 -| @min(self.screen.height, y +| row), 101 - @min(self.screen.height, y +| row), 102 + @min(self.screen.width -| 1, x +| col), 103 + @min(self.screen.height -| 1, y +| row), 102 104 ) orelse { 103 105 std.log.err( 104 106 \\ Position Out of Bounds: ··· 114 116 ); 115 117 } 116 118 } 119 + return .{ x, y }; 117 120 } 118 121 119 122 /// Writes a cell to the location in the View