Fix some invalid area calculations

jmap-eventsource
Manos Pitsidianakis 2020-11-24 02:02:03 +02:00
parent 2ef2add67f
commit f69f623818
Signed by: Manos Pitsidianakis
GPG Key ID: 73627C2F690DF710
2 changed files with 39 additions and 25 deletions

View File

@ -716,8 +716,14 @@ impl Component for Composer {
); );
let body_area = ( let body_area = (
pos_inc(upper_left, (mid, header_height + 1)), (
pos_dec(bottom_right, (mid, 5 + attachments_no)), get_x(upper_left!(header_area)),
get_y(bottom_right!(header_area)) + 1,
),
(
get_x(bottom_right!(header_area)),
get_y(upper_left!(attachment_area)) - 1,
),
); );
let (x, y) = write_string_to_grid( let (x, y) = write_string_to_grid(
@ -1274,7 +1280,7 @@ impl Component for Composer {
context context
.replies .replies
.push_back(UIEvent::ChangeMode(UIMode::Normal)); .push_back(UIEvent::ChangeMode(UIMode::Normal));
self.dirty = true; self.set_dirty(true);
} }
UIEvent::EmbedInput((ref k, ref b)) => { UIEvent::EmbedInput((ref k, ref b)) => {
use std::io::Write; use std::io::Write;
@ -1318,10 +1324,11 @@ impl Component for Composer {
self.has_changes = true; self.has_changes = true;
} }
} }
self.initialized = false;
} }
self.embed = None; self.embed = None;
self.initialized = false;
self.mode = ViewMode::Edit; self.mode = ViewMode::Edit;
self.set_dirty(true);
context context
.replies .replies
.push_back(UIEvent::ChangeMode(UIMode::Normal)); .push_back(UIEvent::ChangeMode(UIMode::Normal));
@ -1341,7 +1348,7 @@ impl Component for Composer {
context context
.replies .replies
.push_back(UIEvent::ChangeMode(UIMode::Normal)); .push_back(UIEvent::ChangeMode(UIMode::Normal));
self.dirty = true; self.set_dirty(true);
return true; return true;
} }
Ok(WaitStatus::Stopped(_, _)) => { Ok(WaitStatus::Stopped(_, _)) => {
@ -1357,7 +1364,7 @@ impl Component for Composer {
context context
.replies .replies
.push_back(UIEvent::ChangeMode(UIMode::Normal)); .push_back(UIEvent::ChangeMode(UIMode::Normal));
self.dirty = true; self.set_dirty(true);
return true; return true;
} }
Ok(WaitStatus::Continued(_)) | Ok(WaitStatus::StillAlive) => { Ok(WaitStatus::Continued(_)) | Ok(WaitStatus::StillAlive) => {
@ -1375,6 +1382,7 @@ impl Component for Composer {
melib::error::ErrorKind::External, melib::error::ErrorKind::External,
)), )),
)); ));
self.initialized = false;
self.embed = None; self.embed = None;
self.mode = ViewMode::Edit; self.mode = ViewMode::Edit;
context context
@ -1390,6 +1398,7 @@ impl Component for Composer {
)), )),
)); ));
drop(embed_guard); drop(embed_guard);
self.initialized = false;
self.embed = None; self.embed = None;
self.mode = ViewMode::Edit; self.mode = ViewMode::Edit;
context context
@ -1553,7 +1562,7 @@ impl Component for Composer {
.unwrap(), .unwrap(),
f, f,
)); ));
self.dirty = true; self.set_dirty(true);
context context
.replies .replies
.push_back(UIEvent::ChangeMode(UIMode::Embed)); .push_back(UIEvent::ChangeMode(UIMode::Embed));
@ -1620,7 +1629,7 @@ impl Component for Composer {
} }
} }
self.initialized = false; self.initialized = false;
self.dirty = true; self.set_dirty(true);
return true; return true;
} }
UIEvent::Action(ref a) => match a { UIEvent::Action(ref a) => match a {
@ -1661,13 +1670,13 @@ impl Component for Composer {
melib::error::ErrorKind::None, melib::error::ErrorKind::None,
)), )),
)); ));
self.dirty = true; self.set_dirty(true);
return true; return true;
} }
}; };
self.draft.attachments_mut().push(attachment); self.draft.attachments_mut().push(attachment);
self.has_changes = true; self.has_changes = true;
self.dirty = true; self.set_dirty(true);
return true; return true;
} }
Err(err) => { Err(err) => {
@ -1689,13 +1698,13 @@ impl Component for Composer {
err.to_string(), err.to_string(),
Some(NotificationType::Error(melib::error::ErrorKind::None)), Some(NotificationType::Error(melib::error::ErrorKind::None)),
)); ));
self.dirty = true; self.set_dirty(true);
return true; return true;
} }
}; };
self.draft.attachments_mut().push(attachment); self.draft.attachments_mut().push(attachment);
self.has_changes = true; self.has_changes = true;
self.dirty = true; self.set_dirty(true);
return true; return true;
} }
Action::Compose(ComposeAction::AddAttachmentFilePicker(ref command)) => { Action::Compose(ComposeAction::AddAttachmentFilePicker(ref command)) => {
@ -1766,7 +1775,7 @@ impl Component for Composer {
} }
} }
context.replies.push_back(UIEvent::Fork(ForkType::Finished)); context.replies.push_back(UIEvent::Fork(ForkType::Finished));
self.dirty = true; self.set_dirty(true);
return true; return true;
} }
Action::Compose(ComposeAction::RemoveAttachment(idx)) => { Action::Compose(ComposeAction::RemoveAttachment(idx)) => {
@ -1776,7 +1785,7 @@ impl Component for Composer {
"attachment with given index does not exist".to_string(), "attachment with given index does not exist".to_string(),
), ),
)); ));
self.dirty = true; self.set_dirty(true);
return true; return true;
} }
self.draft.attachments_mut().remove(*idx); self.draft.attachments_mut().remove(*idx);
@ -1785,7 +1794,7 @@ impl Component for Composer {
.push_back(UIEvent::StatusEvent(StatusEvent::DisplayMessage( .push_back(UIEvent::StatusEvent(StatusEvent::DisplayMessage(
"attachment removed".to_string(), "attachment removed".to_string(),
))); )));
self.dirty = true; self.set_dirty(true);
return true; return true;
} }
Action::Compose(ComposeAction::SaveDraft) => { Action::Compose(ComposeAction::SaveDraft) => {
@ -1802,14 +1811,14 @@ impl Component for Composer {
Action::Compose(ComposeAction::ToggleSign) => { Action::Compose(ComposeAction::ToggleSign) => {
let is_true = self.gpg_state.sign_mail.is_true(); let is_true = self.gpg_state.sign_mail.is_true();
self.gpg_state.sign_mail = ToggleFlag::from(!is_true); self.gpg_state.sign_mail = ToggleFlag::from(!is_true);
self.dirty = true; self.set_dirty(true);
return true; return true;
} }
#[cfg(feature = "gpgme")] #[cfg(feature = "gpgme")]
Action::Compose(ComposeAction::ToggleEncrypt) => { Action::Compose(ComposeAction::ToggleEncrypt) => {
let is_true = self.gpg_state.encrypt_mail.is_true(); let is_true = self.gpg_state.encrypt_mail.is_true();
self.gpg_state.encrypt_mail = ToggleFlag::from(!is_true); self.gpg_state.encrypt_mail = ToggleFlag::from(!is_true);
self.dirty = true; self.set_dirty(true);
return true; return true;
} }
_ => {} _ => {}

View File

@ -530,14 +530,13 @@ impl<T: 'static + std::fmt::Debug + Copy + Default + Send + Sync> Component for
context, context,
); );
} }
clear_area( if length + 4 < height!(area) {
grid, clear_area(
( grid,
set_y(upper_left, length + 4 + get_y(upper_left)), (pos_inc(upper_left, (0, length + 4)), bottom_right),
bottom_right, theme_default,
), );
theme_default, }
);
self.set_dirty(false); self.set_dirty(false);
context.dirty_areas.push_back(area); context.dirty_areas.push_back(area);
} }
@ -1073,6 +1072,9 @@ impl ScrollBar {
upper_left = pos_inc(upper_left, (0, scrollbar_offset)); upper_left = pos_inc(upper_left, (0, scrollbar_offset));
for _ in 0..scrollbar_height { for _ in 0..scrollbar_height {
if get_y(upper_left) >= get_y(bottom_right) {
break;
}
grid[upper_left].set_bg(crate::conf::value(context, "widgets.options.highlighted").bg); grid[upper_left].set_bg(crate::conf::value(context, "widgets.options.highlighted").bg);
upper_left = pos_inc(upper_left, (0, 1)); upper_left = pos_inc(upper_left, (0, 1));
} }
@ -1118,6 +1120,9 @@ impl ScrollBar {
upper_left = pos_inc(upper_left, (scrollbar_offset, 0)); upper_left = pos_inc(upper_left, (scrollbar_offset, 0));
for _ in 0..scrollbar_width { for _ in 0..scrollbar_width {
if get_x(upper_left) >= get_x(bottom_right) {
break;
}
grid[upper_left] grid[upper_left]
.set_ch(if ascii_drawing { 'H' } else { '█' }) .set_ch(if ascii_drawing { 'H' } else { '█' })
.set_fg(crate::conf::value(context, "widgets.options.highlighted").bg); .set_fg(crate::conf::value(context, "widgets.options.highlighted").bg);