ui: add ListingTrait to get/set coordinates
parent
dcb62798f8
commit
c91f0d73a5
|
@ -30,6 +30,11 @@ pub use self::thread::*;
|
||||||
mod plain;
|
mod plain;
|
||||||
pub use self::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)]
|
#[derive(Debug)]
|
||||||
pub enum Listing {
|
pub enum Listing {
|
||||||
Plain(PlainListing),
|
Plain(PlainListing),
|
||||||
|
@ -74,25 +79,60 @@ impl Component for Listing {
|
||||||
UIEventType::Resize => self.set_dirty(),
|
UIEventType::Resize => self.set_dirty(),
|
||||||
UIEventType::Action(ref action) => match action {
|
UIEventType::Action(ref action) => match action {
|
||||||
Action::Listing(ListingAction::SetPlain) => {
|
Action::Listing(ListingAction::SetPlain) => {
|
||||||
if let Listing::Plain(_) = self {
|
let new_l = match self {
|
||||||
return true;
|
Listing::Plain(_) => {
|
||||||
}
|
return true;
|
||||||
*self = Listing::Plain(PlainListing::default());
|
}
|
||||||
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
Action::Listing(ListingAction::SetThreaded) => {
|
Action::Listing(ListingAction::SetThreaded) => {
|
||||||
if let Listing::Threaded(_) = self {
|
let new_l = match self {
|
||||||
return true;
|
Listing::Threaded(_) => {
|
||||||
}
|
return true;
|
||||||
self.set_dirty();
|
}
|
||||||
*self = Listing::Threaded(ThreadListing::default());
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
Action::Listing(ListingAction::SetCompact) => {
|
Action::Listing(ListingAction::SetCompact) => {
|
||||||
if let Listing::Compact(_) = self {
|
let new_l = match self {
|
||||||
return true;
|
Listing::Compact(_) => {
|
||||||
}
|
return true;
|
||||||
*self = Listing::Compact(CompactListing::default());
|
}
|
||||||
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
|
|
|
@ -47,6 +47,15 @@ pub struct CompactListing {
|
||||||
movement: Option<PageMovement>,
|
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 {
|
impl Default for CompactListing {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self::new()
|
Self::new()
|
||||||
|
|
|
@ -43,6 +43,15 @@ pub struct PlainListing {
|
||||||
view: Option<MailView>,
|
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 {
|
impl Default for PlainListing {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self::new()
|
Self::new()
|
||||||
|
|
|
@ -46,6 +46,15 @@ pub struct ThreadListing {
|
||||||
view: Option<MailView>,
|
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 {
|
impl Default for ThreadListing {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self::new()
|
Self::new()
|
||||||
|
|
Loading…
Reference in New Issue