summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorManos Pitsidianakis <el13635@mail.ntua.gr>2019-04-03 16:58:42 +0300
committerManos Pitsidianakis <el13635@mail.ntua.gr>2019-06-10 19:40:42 +0300
commitc91f0d73a53b325d015be47b1f8103d34860b24c (patch)
tree946fb46038e3cc4be12dc79aebaa546b0e9ccb91
parentdcb62798f83d804b8165544971dd341346863177 (diff)
ui: add ListingTrait to get/set coordinates
-rw-r--r--ui/src/components/mail/listing.rs66
-rw-r--r--ui/src/components/mail/listing/compact.rs9
-rw-r--r--ui/src/components/mail/listing/plain.rs9
-rw-r--r--ui/src/components/mail/listing/thread.rs9
4 files changed, 80 insertions, 13 deletions
diff --git a/ui/src/components/mail/listing.rs b/ui/src/components/mail/listing.rs
index 35f57a0f..3f538483 100644
--- a/ui/src/components/mail/listing.rs
+++ b/ui/src/components/mail/listing.rs
@@ -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;
}
_ => {}
diff --git a/ui/src/components/mail/listing/compact.rs b/ui/src/components/mail/listing/compact.rs
index 66854208..8097ce53 100644
--- a/ui/src/components/mail/listing/compact.rs
+++ b/ui/src/components/mail/listing/compact.rs
@@ -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()
diff --git a/ui/src/components/mail/listing/plain.rs b/ui/src/components/mail/listing/plain.rs
index 807494a0..4e8862a2 100644
--- a/ui/src/components/mail/listing/plain.rs
+++ b/ui/src/components/mail/listing/plain.rs
@@ -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()
diff --git a/ui/src/components/mail/listing/thread.rs b/ui/src/components/mail/listing/thread.rs
index 5bd7c47d..029e5a1c 100644
--- a/ui/src/components/mail/listing/thread.rs
+++ b/ui/src/components/mail/listing/thread.rs
@@ -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()