use super::Model;
impl Model {
#[must_use]
pub const fn y_offset(&self) -> usize {
self.y_offset
}
pub fn set_y_offset(&mut self, n: usize) {
self.y_offset = n.min(self.max_y_offset());
}
#[must_use]
pub const fn x_offset(&self) -> usize {
self.x_offset
}
pub fn set_x_offset(&mut self, n: usize) {
if !self.soft_wrap {
self.x_offset = n.min(self.longest.saturating_sub(self.width));
}
}
pub const fn set_horizontal_step(&mut self, n: usize) {
self.horizontal_step = n;
}
pub fn page_down(&mut self) {
if !self.at_bottom() {
self.scroll_down(self.inner_height());
}
}
pub fn page_up(&mut self) {
if !self.at_top() {
self.scroll_up(self.inner_height());
}
}
pub fn half_page_down(&mut self) {
if !self.at_bottom() {
self.scroll_down(self.inner_height() / 2);
}
}
pub fn half_page_up(&mut self) {
if !self.at_top() {
self.scroll_up(self.inner_height() / 2);
}
}
pub fn scroll_down(&mut self, n: usize) {
if self.at_bottom() || n == 0 || self.lines.is_empty() {
return;
}
self.set_y_offset(self.y_offset + n);
}
pub fn scroll_up(&mut self, n: usize) {
if self.at_top() || n == 0 || self.lines.is_empty() {
return;
}
self.set_y_offset(self.y_offset.saturating_sub(n));
}
pub fn scroll_left(&mut self, n: usize) {
self.set_x_offset(self.x_offset.saturating_sub(n));
}
pub fn scroll_right(&mut self, n: usize) {
self.set_x_offset(self.x_offset + n);
}
pub const fn goto_top(&mut self) {
self.y_offset = 0;
}
pub fn goto_bottom(&mut self) {
self.y_offset = self.max_y_offset();
}
}