mirror of
https://github.com/ratatui/ratatui.git
synced 2025-09-30 06:21:31 +00:00
feat(widgets): add offset() and offset_mut() for table and list state (#12)
This commit is contained in:
parent
3e54ac3aca
commit
bc66a27baf
@ -14,6 +14,14 @@ pub struct ListState {
|
||||
}
|
||||
|
||||
impl ListState {
|
||||
pub fn offset(&self) -> usize {
|
||||
self.offset
|
||||
}
|
||||
|
||||
pub fn offset_mut(&mut self) -> &mut usize {
|
||||
&mut self.offset
|
||||
}
|
||||
|
||||
pub fn with_selected(mut self, selected: Option<usize>) -> Self {
|
||||
self.selected = selected;
|
||||
self
|
||||
|
@ -343,6 +343,24 @@ pub struct TableState {
|
||||
}
|
||||
|
||||
impl TableState {
|
||||
pub fn offset(&self) -> usize {
|
||||
self.offset
|
||||
}
|
||||
|
||||
pub fn offset_mut(&mut self) -> &mut usize {
|
||||
&mut self.offset
|
||||
}
|
||||
|
||||
pub fn with_selected(mut self, selected: Option<usize>) -> Self {
|
||||
self.selected = selected;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_offset(mut self, offset: usize) -> Self {
|
||||
self.offset = offset;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn selected(&self) -> Option<usize> {
|
||||
self.selected
|
||||
}
|
||||
@ -353,13 +371,6 @@ impl TableState {
|
||||
self.offset = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns a copy of the receiver's scroll offset.
|
||||
///
|
||||
/// This is useful, for example, if you need to "synchronize" the scrolling of a `Table` and a `Paragraph`.
|
||||
pub fn offset(&self) -> usize {
|
||||
self.offset
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> StatefulWidget for Table<'a> {
|
||||
|
Loading…
x
Reference in New Issue
Block a user