summaryrefslogtreecommitdiffstats
path: root/ui/src/components
diff options
context:
space:
mode:
authorManos Pitsidianakis <el13635@mail.ntua.gr>2019-09-25 23:14:24 +0300
committerManos Pitsidianakis <el13635@mail.ntua.gr>2019-09-26 13:11:49 +0300
commit91ae539de1730d735f6137f36e2f5da57225cfce (patch)
tree01a385311fa33f18d63a27d9e599a10a3cab59db /ui/src/components
parentf27b815aa79e234c299a4a1255c7f001ec68e1cd (diff)
Small fixes
Diffstat (limited to 'ui/src/components')
-rw-r--r--ui/src/components/mail/view.rs3
-rw-r--r--ui/src/components/mail/view/thread.rs32
-rw-r--r--ui/src/components/notifications.rs6
-rw-r--r--ui/src/components/utilities.rs5
-rw-r--r--ui/src/components/utilities/widgets.rs70
5 files changed, 72 insertions, 44 deletions
diff --git a/ui/src/components/mail/view.rs b/ui/src/components/mail/view.rs
index 154bd01a..315970aa 100644
--- a/ui/src/components/mail/view.rs
+++ b/ui/src/components/mail/view.rs
@@ -341,6 +341,7 @@ impl Component for MailView {
if !account.contains_key(self.coordinates.2) {
/* The envelope has been renamed or removed, so wait for the appropriate event to
* arrive */
+ self.dirty = false;
return;
}
let (hash, is_seen) = {
@@ -638,7 +639,6 @@ impl Component for MailView {
self.subview = None;
}
};
- self.dirty = false;
}
match self.mode {
ViewMode::Subview if self.subview.is_some() => {
@@ -656,6 +656,7 @@ impl Component for MailView {
}
}
}
+ self.dirty = false;
}
fn process_event(&mut self, event: &mut UIEvent, context: &mut Context) -> bool {
diff --git a/ui/src/components/mail/view/thread.rs b/ui/src/components/mail/view/thread.rs
index b3cf3e27..f84ad207 100644
--- a/ui/src/components/mail/view/thread.rs
+++ b/ui/src/components/mail/view/thread.rs
@@ -414,11 +414,14 @@ impl ThreadView {
let bottom_right = bottom_right!(area);
let (width, height) = self.content.size();
if height == 0 {
- clear_area(grid, area);
context.dirty_areas.push_back(area);
return;
}
let rows = (get_y(bottom_right) - get_y(upper_left)).wrapping_div(2);
+ if rows == 0 {
+ context.dirty_areas.push_back(area);
+ return;
+ }
if let Some(mvm) = self.movement.take() {
match mvm {
PageMovement::PageUp => {
@@ -751,7 +754,10 @@ impl ThreadView {
let upper_left = upper_left!(area);
let bottom_right = bottom_right!(area);
- let rows = (get_y(bottom_right) - get_y(upper_left) + 1) / 2;
+ let rows = (get_y(bottom_right).saturating_sub(get_y(upper_left) + 1)) / 2;
+ if rows == 0 {
+ return;
+ }
let page_no = (self.new_cursor_pos).wrapping_div(rows);
let top_idx = page_no * rows;
@@ -765,7 +771,10 @@ impl ThreadView {
let area = (set_y(upper_left, y), bottom_right);
let upper_left = upper_left!(area);
- let rows = (get_y(bottom_right) - get_y(upper_left) + 1) / 2;
+ let rows = (get_y(bottom_right).saturating_sub(get_y(upper_left) + 1)) / 2;
+ if rows == 0 {
+ return;
+ }
let page_no = (self.new_cursor_pos).wrapping_div(rows);
let top_idx = page_no * rows;
copy_area(
@@ -875,6 +884,7 @@ impl Component for ThreadView {
fn draw(&mut self, grid: &mut CellBuffer, area: Area, context: &mut Context) {
let total_cols = width!(area);
if self.entries.is_empty() {
+ self.dirty = false;
return;
}
@@ -891,6 +901,7 @@ impl Component for ThreadView {
if self.entries.len() == 1 {
self.mailview.draw(grid, area, context);
+ self.dirty = false;
return;
}
@@ -899,6 +910,7 @@ impl Component for ThreadView {
} else {
self.draw_horz(grid, area, context);
}
+ self.dirty = false;
}
fn process_event(&mut self, event: &mut UIEvent, context: &mut Context) -> bool {
match event {
@@ -959,6 +971,7 @@ impl Component for ThreadView {
UIEvent::Input(Key::Up) => {
if self.cursor_pos > 0 {
self.new_cursor_pos = self.new_cursor_pos.saturating_sub(1);
+ self.dirty = true;
}
return true;
}
@@ -966,24 +979,25 @@ impl Component for ThreadView {
let height = self.visible_entries.iter().flat_map(|v| v.iter()).count();
if height > 0 && self.new_cursor_pos + 1 < height {
self.new_cursor_pos += 1;
+ self.dirty = true;
}
return true;
}
UIEvent::Input(ref key) if *key == shortcuts["prev_page"] => {
self.movement = Some(PageMovement::PageUp);
- self.set_dirty();
+ self.dirty = true;
}
UIEvent::Input(ref key) if *key == shortcuts["next_page"] => {
self.movement = Some(PageMovement::PageDown);
- self.set_dirty();
+ self.dirty = true;
}
UIEvent::Input(ref key) if *key == Key::Home => {
self.movement = Some(PageMovement::Home);
- self.set_dirty();
+ self.dirty = true;
}
UIEvent::Input(ref key) if *key == Key::End => {
self.movement = Some(PageMovement::End);
- self.set_dirty();
+ self.dirty = true;
}
UIEvent::Input(Key::Char('\n')) => {
if self.entries.len() < 2 {
@@ -1066,9 +1080,7 @@ impl Component for ThreadView {
false
}
fn is_dirty(&self) -> bool {
- (self.cursor_pos != self.new_cursor_pos)
- || self.dirty
- || (self.show_mailview && self.mailview.is_dirty())
+ self.dirty || (self.show_mailview && self.mailview.is_dirty())
}
fn set_dirty(&mut self) {
self.dirty = true;
diff --git a/ui/src/components/notifications.rs b/ui/src/components/notifications.rs
index 8f9b11c1..5b0acf17 100644
--- a/ui/src/components/notifications.rs
+++ b/ui/src/components/notifications.rs
@@ -73,6 +73,9 @@ impl Component for XDGNotifications {
false
}
fn set_dirty(&mut self) {}
+ fn is_dirty(&self) -> bool {
+ false
+ }
fn id(&self) -> ComponentId {
ComponentId::nil()
@@ -174,6 +177,9 @@ impl Component for NotificationFilter {
fn id(&self) -> ComponentId {
ComponentId::nil()
}
+ fn is_dirty(&self) -> bool {
+ false
+ }
fn set_dirty(&mut self) {}
fn set_id(&mut self, _id: ComponentId) {}
}
diff --git a/ui/src/components/utilities.rs b/ui/src/components/utilities.rs
index 626c10c6..db8c54f6 100644
--- a/ui/src/components/utilities.rs
+++ b/ui/src/components/utilities.rs
@@ -554,7 +554,7 @@ impl Component for Pager {
"Pager text piped to '{}{}{}'",
&bin,
if args.is_empty() { "" } else { " " },
- args.join(", ")
+ args.join(" ")
))));
return true;
}
@@ -1121,6 +1121,9 @@ impl Component for Progress {
false
}
fn set_dirty(&mut self) {}
+ fn is_dirty(&self) -> bool {
+ false
+ }
fn id(&self) -> ComponentId {
self.id
diff --git a/ui/src/components/utilities/widgets.rs b/ui/src/components/utilities/widgets.rs
index 387fd906..749e63fa 100644
--- a/ui/src/components/utilities/widgets.rs
+++ b/ui/src/components/utilities/widgets.rs
@@ -195,7 +195,7 @@ impl Component for Field {
true
}
fn is_dirty(&self) -> bool {
- true
+ false
}
fn set_dirty(&mut self) {}
@@ -477,6 +477,7 @@ where
result: Option<T>,
cursor: usize,
+ dirty: bool,
id: ComponentId,
}
@@ -499,6 +500,7 @@ where
buttons: vec![init_val].into_iter().collect(),
result: None,
cursor: 0,
+ dirty: true,
id: ComponentId::new_v4(),
}
}
@@ -518,28 +520,31 @@ where
T: std::fmt::Debug + Default + Send,
{
fn draw(&mut self, grid: &mut CellBuffer, area: Area, _context: &mut Context) {
- let upper_left = upper_left!(area);
-
- let mut len = 0;
- for (i, k) in self.layout.iter().enumerate() {
- let cur_len = k.len();
- write_string_to_grid(
- k.as_str(),
- grid,
- Color::Default,
- if i == self.cursor {
- Color::Byte(246)
- } else {
- Color::Default
- },
- Attr::Default,
- (
- pos_inc(upper_left, (len, 0)),
- pos_inc(upper_left, (cur_len + len, 0)),
- ),
- false,
- );
- len += cur_len + 3;
+ if self.dirty {
+ let upper_left = upper_left!(area);
+
+ let mut len = 0;
+ for (i, k) in self.layout.iter().enumerate() {
+ let cur_len = k.len();
+ write_string_to_grid(
+ k.as_str(),
+ grid,
+ Color::Default,
+ if i == self.cursor {
+ Color::Byte(246)
+ } else {
+ Color::Default
+ },
+ Attr::Default,
+ (
+ pos_inc(upper_left, (len, 0)),
+ pos_inc(upper_left, (cur_len + len, 0)),
+ ),
+ false,
+ );
+ len += cur_len + 3;
+ }
+ self.dirty = false;
}
}
fn process_event(&mut self, event: &mut UIEvent, _context: &mut Context) -> bool {
@@ -550,25 +555,26 @@ where
.remove(&self.layout[self.cursor])
.unwrap_or_default(),
);
- return true;
}
UIEvent::Input(Key::Left) => {
self.cursor = self.cursor.saturating_sub(1);
- return true;
}
UIEvent::Input(Key::Right) if self.cursor < self.layout.len().saturating_sub(1) => {
self.cursor += 1;
- return true;
}
- _ => {}
+ _ => {
+ return false;
+ }
}
-
- false
+ self.set_dirty();
+ true
}
fn is_dirty(&self) -> bool {
- true
+ self.dirty
+ }
+ fn set_dirty(&mut self) {
+ self.dirty = true;
}
- fn set_dirty(&mut self) {}
fn id(&self) -> ComponentId {
self.id
@@ -695,7 +701,7 @@ impl AutoComplete {
pub fn set_suggestions(&mut self, entries: Vec<AutoCompleteEntry>) -> bool {
if entries.len() == self.entries.len() && entries == self.entries {
- return false;;
+ return false;
}
let mut content = CellBuffer::new(