ui: add pageup-dn movements in compact listing

embed
Manos Pitsidianakis 2018-09-19 10:26:17 +03:00
parent 3b4e4195d6
commit 3f9ea25899
Signed by: Manos Pitsidianakis
GPG Key ID: 73627C2F690DF710
2 changed files with 42 additions and 7 deletions

View File

@ -20,6 +20,7 @@
*/ */
use super::*; use super::*;
use components::utilities::PageMovement;
//use melib::mailbox::backends::BackendOp; //use melib::mailbox::backends::BackendOp;
@ -42,6 +43,8 @@ pub struct CompactListing {
/// If `self.view` exists or not. /// If `self.view` exists or not.
unfocused: bool, unfocused: bool,
view: Option<ThreadView>, view: Option<ThreadView>,
movement: Option<PageMovement>,
} }
impl Default for CompactListing { impl Default for CompactListing {
@ -60,6 +63,9 @@ impl CompactListing {
/// Helper function to format entry strings for CompactListing */ /// Helper function to format entry strings for CompactListing */
/* TODO: Make this configurable */ /* TODO: Make this configurable */
fn make_entry_string(e: &Envelope, len: usize, idx: usize) -> String { fn make_entry_string(e: &Envelope, len: usize, idx: usize) -> String {
if e.subject().contains("https://custory.com") {
eprintln!("it's {:?}", e.subject());
}
if len > 1 { if len > 1 {
format!( format!(
"{} {} {:.85} ({})", "{} {} {:.85} ({})",
@ -85,11 +91,13 @@ impl CompactListing {
new_cursor_pos: (0, 0, 0), new_cursor_pos: (0, 0, 0),
length: 0, length: 0,
sort: (Default::default(), Default::default()), sort: (Default::default(), Default::default()),
subsort: (SortField::Subject, SortOrder::Desc), subsort: (SortField::Date, SortOrder::Desc),
content, content,
dirty: true, dirty: true,
unfocused: false, unfocused: false,
view: None, view: None,
movement: None,
} }
} }
/// Fill the `self.content` `CellBuffer` with the contents of the account folder the user has /// Fill the `self.content` `CellBuffer` with the contents of the account folder the user has
@ -243,6 +251,25 @@ impl CompactListing {
return; return;
} }
let rows = get_y(bottom_right) - get_y(upper_left) + 1; let rows = get_y(bottom_right) - get_y(upper_left) + 1;
if let Some(mvm) = self.movement.take() {
match mvm {
PageMovement::PageUp => {
self.new_cursor_pos.2 = self.new_cursor_pos.2.saturating_sub(rows);
}
PageMovement::PageDown => {
/* This might "overflow" beyond the max_cursor_pos boundary if it's not yet
* set. TODO: Rework the page up/down stuff
*/
if self.new_cursor_pos.2 + 2 * rows + 1 < self.length {
self.new_cursor_pos.2 += rows;
} else {
self.new_cursor_pos.2 = self.length.saturating_sub(rows).saturating_sub(1);
}
}
}
}
let prev_page_no = (self.cursor_pos.2).wrapping_div(rows); let prev_page_no = (self.cursor_pos.2).wrapping_div(rows);
let page_no = (self.new_cursor_pos.2).wrapping_div(rows); let page_no = (self.new_cursor_pos.2).wrapping_div(rows);
@ -356,6 +383,14 @@ impl Component for CompactListing {
self.dirty = true; self.dirty = true;
return true; return true;
} }
UIEventType::Input(Key::PageUp) => {
self.movement = Some(PageMovement::PageUp);
self.set_dirty();
}
UIEventType::Input(Key::PageDown) => {
self.movement = Some(PageMovement::PageDown);
self.set_dirty();
}
UIEventType::Input(Key::Char('i')) if self.unfocused => { UIEventType::Input(Key::Char('i')) if self.unfocused => {
self.unfocused = false; self.unfocused = false;
self.dirty = true; self.dirty = true;

View File

@ -184,7 +184,7 @@ impl Component for VSplit {
} }
#[derive(Debug)] #[derive(Debug)]
enum PagerMovement { pub enum PageMovement {
PageUp, PageUp,
PageDown, PageDown,
} }
@ -201,7 +201,7 @@ pub struct Pager {
width: usize, width: usize,
dirty: bool, dirty: bool,
content: CellBuffer, content: CellBuffer,
movement: Option<PagerMovement>, movement: Option<PageMovement>,
} }
impl fmt::Display for Pager { impl fmt::Display for Pager {
@ -328,10 +328,10 @@ impl Component for Pager {
let height = height!(area); let height = height!(area);
if let Some(mvm) = self.movement.take() { if let Some(mvm) = self.movement.take() {
match mvm { match mvm {
PagerMovement::PageUp => { PageMovement::PageUp => {
self.cursor_pos = self.cursor_pos.saturating_sub(height); self.cursor_pos = self.cursor_pos.saturating_sub(height);
} }
PagerMovement::PageDown => { PageMovement::PageDown => {
/* This might "overflow" beyond the max_cursor_pos boundary if it's not yet /* This might "overflow" beyond the max_cursor_pos boundary if it's not yet
* set. TODO: Rework the page up/down stuff * set. TODO: Rework the page up/down stuff
*/ */
@ -391,11 +391,11 @@ impl Component for Pager {
} }
} }
UIEventType::Input(Key::PageUp) => { UIEventType::Input(Key::PageUp) => {
self.movement = Some(PagerMovement::PageUp); self.movement = Some(PageMovement::PageUp);
self.dirty = true; self.dirty = true;
} }
UIEventType::Input(Key::PageDown) => { UIEventType::Input(Key::PageDown) => {
self.movement = Some(PagerMovement::PageDown); self.movement = Some(PageMovement::PageDown);
self.dirty = true; self.dirty = true;
} }
UIEventType::ChangeMode(UIMode::Normal) => { UIEventType::ChangeMode(UIMode::Normal) => {