ui: add ListingTrait to get/set coordinates

embed
Manos Pitsidianakis 2019-04-03 16:58:42 +03:00
parent dcb62798f8
commit c91f0d73a5
Signed by: Manos Pitsidianakis
GPG Key ID: 73627C2F690DF710
4 changed files with 80 additions and 13 deletions

View File

@ -30,6 +30,11 @@ pub use self::thread::*;
mod plain;
pub use self::plain::*;
trait ListingTrait {
fn coordinates(&self) -> (usize, usize, Option<EnvelopeHash>);
fn set_coordinates(&mut self, (usize, usize, Option<EnvelopeHash>));
}
#[derive(Debug)]
pub enum Listing {
Plain(PlainListing),
@ -74,25 +79,60 @@ impl Component for Listing {
UIEventType::Resize => self.set_dirty(),
UIEventType::Action(ref action) => match action {
Action::Listing(ListingAction::SetPlain) => {
if let Listing::Plain(_) = self {
return true;
}
*self = Listing::Plain(PlainListing::default());
let new_l = match self {
Listing::Plain(_) => {
return true;
}
Listing::Threaded(l) => {
let mut new_l = PlainListing::default();
new_l.set_coordinates(l.coordinates());
new_l
}
Listing::Compact(l) => {
let mut new_l = PlainListing::default();
new_l.set_coordinates(l.coordinates());
new_l
}
};
*self = Listing::Plain(new_l);
return true;
}
Action::Listing(ListingAction::SetThreaded) => {
if let Listing::Threaded(_) = self {
return true;
}
self.set_dirty();
*self = Listing::Threaded(ThreadListing::default());
let new_l = match self {
Listing::Threaded(_) => {
return true;
}
Listing::Plain(l) => {
let mut new_l = ThreadListing::default();
new_l.set_coordinates(l.coordinates());
new_l
}
Listing::Compact(l) => {
let mut new_l = ThreadListing::default();
new_l.set_coordinates(l.coordinates());
new_l
}
};
*self = Listing::Threaded(new_l);
return true;
}
Action::Listing(ListingAction::SetCompact) => {
if let Listing::Compact(_) = self {
return true;
}
*self = Listing::Compact(CompactListing::default());
let new_l = match self {
Listing::Compact(_) => {
return true;
}
Listing::Threaded(l) => {
let mut new_l = CompactListing::default();
new_l.set_coordinates(l.coordinates());
new_l
}
Listing::Plain(l) => {
let mut new_l = CompactListing::default();
new_l.set_coordinates(l.coordinates());
new_l
}
};
*self = Listing::Compact(new_l);
return true;
}
_ => {}

View File

@ -47,6 +47,15 @@ pub struct CompactListing {
movement: Option<PageMovement>,
}
impl ListingTrait for CompactListing {
fn coordinates(&self) -> (usize, usize, Option<EnvelopeHash>) {
(self.cursor_pos.0, self.cursor_pos.1, None)
}
fn set_coordinates(&mut self, coordinates: (usize, usize, Option<EnvelopeHash>)) {
self.new_cursor_pos = (coordinates.0, coordinates.1, 0);
}
}
impl Default for CompactListing {
fn default() -> Self {
Self::new()

View File

@ -43,6 +43,15 @@ pub struct PlainListing {
view: Option<MailView>,
}
impl ListingTrait for PlainListing {
fn coordinates(&self) -> (usize, usize, Option<EnvelopeHash>) {
(self.cursor_pos.0, self.cursor_pos.1, None)
}
fn set_coordinates(&mut self, coordinates: (usize, usize, Option<EnvelopeHash>)) {
self.new_cursor_pos = (coordinates.0, coordinates.1, 0);
}
}
impl Default for PlainListing {
fn default() -> Self {
Self::new()

View File

@ -46,6 +46,15 @@ pub struct ThreadListing {
view: Option<MailView>,
}
impl ListingTrait for ThreadListing {
fn coordinates(&self) -> (usize, usize, Option<EnvelopeHash>) {
(self.cursor_pos.0, self.cursor_pos.1, Some(self.locations[self.cursor_pos.2]))
}
fn set_coordinates(&mut self, coordinates: (usize, usize, Option<EnvelopeHash>)) {
self.new_cursor_pos = (coordinates.0, coordinates.1, 0);
}
}
impl Default for ThreadListing {
fn default() -> Self {
Self::new()