DVUI

scrollBy

Scroll by a col and/or row offset. Accepts +ve and -ve offset. Scrolling off the end of a row will either stop at the start/end of the row or if wrap_curor is set to true, will wrap 1 cell.

Parameters

#
self:*KeyboardNavigation
*KeyboardNavigation
num_cols:isize
isize
num_rows:isize
isize

Source

Implementation

#
pub fn scrollBy(self: *KeyboardNavigation, num_cols: isize, num_rows: isize) void {
        var should_wrap: bool = false;
        if (num_cols < 0) {
            if (self.cursor.col_num >= -num_cols) {
                self.cursor.col_num -= @intCast(-num_cols);
            } else {
                self.cursor.col_num = 0;
                should_wrap = true;
            }
        } else if (num_cols > 0) {
            if (self.cursor.col_num < self.num_cols - 1) {
                self.cursor.col_num += @intCast(num_cols);
            } else {
                should_wrap = true;
            }
        }
        if (num_rows < 0) {
            if (self.cursor.row_num >= -num_rows) {
                self.cursor.row_num -= @intCast(-num_rows);
            } else {
                self.cursor.row_num = 0;
            }
        } else if (num_rows > 0) {
            if (self.cursor.row_num < self.num_rows - 1) {
                self.cursor.row_num += @intCast(num_rows);
            } else {
                self.cursor.row_num = self.num_rows - 1;
            }
        }
        if (should_wrap and self.wrap_cursor) {
            if (self.cursor.col_num == 0) {
                if (self.cursor.row_num > 0) {
                    self.cursor.col_num = self.num_cols - 1;
                    self.cursor.row_num -= 1;
                }
            } else if (self.cursor.col_num == self.num_cols - 1) {
                self.cursor.col_num = 0;
                if (self.cursor.row_num < self.num_rows - 1) {
                    self.cursor.row_num += 1;
                }
            }
        }
        self.enforceCursorLimits();
    }