meli/src/components.rs

111 lines
3.0 KiB
Rust
Raw Normal View History

2018-07-11 17:07:51 +03:00
/*
* meli
2018-07-11 17:07:51 +03:00
*
* Copyright 2017-2018 Manos Pitsidianakis
*
* This file is part of meli.
*
* meli is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* meli is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with meli. If not, see <http://www.gnu.org/licenses/>.
*/
/*! Components visual and logical separations of application interfaces.
*
* They can draw on the terminal and receive events, but also do other stuff as well. (For example, see the `notifications` module.)
* See the `Component` Trait for more details.
*/
2018-07-18 10:42:52 +03:00
use super::*;
use crate::melib::text_processing::{TextProcessing, Truncate};
use crate::terminal::boundaries::*;
2018-08-06 16:53:23 +03:00
2018-07-11 17:07:51 +03:00
pub mod mail;
2019-06-18 21:13:58 +03:00
pub use crate::mail::*;
2018-08-06 16:53:23 +03:00
pub mod notifications;
2018-07-11 17:07:51 +03:00
2018-08-06 16:53:23 +03:00
pub mod utilities;
2018-08-03 13:46:08 +03:00
pub use self::utilities::*;
2018-07-11 17:07:51 +03:00
2019-02-15 09:06:42 +02:00
pub mod contacts;
2019-06-18 21:13:58 +03:00
pub use crate::contacts::*;
2019-02-15 09:06:42 +02:00
#[cfg(feature = "svgscreenshot")]
pub mod svg;
use std::fmt;
2018-08-23 15:36:52 +03:00
use std::fmt::{Debug, Display};
use indexmap::IndexMap;
use uuid::Uuid;
pub type ComponentId = Uuid;
2018-07-11 17:07:51 +03:00
pub type ShortcutMap = IndexMap<&'static str, Key>;
pub type ShortcutMaps = IndexMap<&'static str, ShortcutMap>;
2019-03-02 19:25:11 +02:00
#[derive(Debug, Clone, Copy)]
pub enum PageMovement {
Up(usize),
Right(usize),
Left(usize),
Down(usize),
PageUp(usize),
PageDown(usize),
Home,
End,
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct ScrollContext {
shown_lines: usize,
total_lines: usize,
has_more_lines: bool,
}
#[derive(Debug, Clone, Copy)]
pub enum ScrollUpdate {
End(ComponentId),
Update {
id: ComponentId,
context: ScrollContext,
},
}
2018-07-11 18:58:57 +03:00
/// Types implementing this Trait can draw on the terminal and receive events.
/// If a type wants to skip drawing if it has not changed anything, it can hold some flag in its
/// fields (eg self.dirty = false) and act upon that in their `draw` implementation.
pub trait Component: Display + Debug + Send + Sync {
2018-07-14 15:04:42 +03:00
fn draw(&mut self, grid: &mut CellBuffer, area: Area, context: &mut Context);
2019-02-26 17:50:47 +02:00
fn process_event(&mut self, event: &mut UIEvent, context: &mut Context) -> bool;
2019-09-25 23:14:24 +03:00
fn is_dirty(&self) -> bool;
2019-03-26 16:59:35 +02:00
fn is_visible(&self) -> bool {
true
}
fn can_quit_cleanly(&mut self, _context: &Context) -> bool {
true
}
fn set_dirty(&mut self, value: bool);
fn kill(&mut self, _id: ComponentId, _context: &mut Context) {}
2019-04-10 22:01:02 +03:00
fn set_id(&mut self, _id: ComponentId) {}
fn id(&self) -> ComponentId;
2019-03-02 19:25:11 +02:00
fn get_shortcuts(&self, _context: &Context) -> ShortcutMaps {
2019-03-14 12:19:25 +02:00
Default::default()
}
fn get_status(&self, _context: &Context) -> String {
String::new()
}
2018-07-11 17:07:51 +03:00
}