browse: fix fullscreen transition

This commit is contained in:
FliegendeWurst 2021-05-18 19:16:12 +02:00 committed by Arne Keller
parent 175695b22c
commit cf037127dc

View File

@ -287,7 +287,7 @@ fn show_listing(mailbox: &str) -> Result<()> {
let layer = s.pop_layer().unwrap(); let layer = s.pop_layer().unwrap();
if let Ok(textview) = layer.downcast::<ResizedView<MailScrollerView>>() { if let Ok(textview) = layer.downcast::<ResizedView<MailScrollerView>>() {
let mut it = textview.into_inner().unwrap_or_else(|_| panic!("?")); let mut it = textview.into_inner().unwrap_or_else(|_| panic!("?"));
it.get_inner_mut().get_mut().text.as_mut().unwrap().set_show_scrollbars(true); it.get_inner_mut().get_mut().set_scroll(true);
it.get_inner_mut().get_mut().set_wrap_method(WrapMethod::XiUnicode); it.get_inner_mut().get_mut().set_wrap_method(WrapMethod::XiUnicode);
dummy__.borrow_mut().replace(it); dummy__.borrow_mut().replace(it);
s.call_on_name("mail_scroller", move |this: &mut MailScrollerView| { s.call_on_name("mail_scroller", move |this: &mut MailScrollerView| {
@ -300,7 +300,7 @@ fn show_listing(mailbox: &str) -> Result<()> {
std::mem::swap(dummy__.borrow_mut().as_mut().unwrap(), this); std::mem::swap(dummy__.borrow_mut().as_mut().unwrap(), this);
}); });
let mut it = dummy_.borrow_mut().take().unwrap(); let mut it = dummy_.borrow_mut().take().unwrap();
it.get_inner_mut().get_mut().text.as_mut().unwrap().set_show_scrollbars(false); it.get_inner_mut().get_mut().set_scroll(false);
it.get_inner_mut().get_mut().set_wrap_method(WrapMethod::Newlines); it.get_inner_mut().get_mut().set_wrap_method(WrapMethod::Newlines);
eprintln!("adding fullscreen layer!"); eprintln!("adding fullscreen layer!");
s.add_fullscreen_layer(ResizedView::with_full_screen(it)); s.add_fullscreen_layer(ResizedView::with_full_screen(it));
@ -425,6 +425,7 @@ impl TreeEntry for MailPart {}
struct MailPartView { struct MailPartView {
part: Option<&'static ParsedMail<'static>>, part: Option<&'static ParsedMail<'static>>,
wrap: WrapMethod, wrap: WrapMethod,
scroll: bool,
text: Option<ScrollView<TextView>>, text: Option<ScrollView<TextView>>,
cached_size: Option<Vec2>, cached_size: Option<Vec2>,
expected_text_height: Option<usize>, expected_text_height: Option<usize>,
@ -436,6 +437,7 @@ impl MailPartView {
MailPartView { MailPartView {
part: None, part: None,
wrap: WrapMethod::XiUnicode, wrap: WrapMethod::XiUnicode,
scroll: true,
text: None, text: None,
cached_size: None, cached_size: None,
expected_text_height: None, expected_text_height: None,
@ -450,6 +452,13 @@ impl MailPartView {
self.wrap = wrap; self.wrap = wrap;
} }
fn set_scroll(&mut self, scroll: bool) {
self.scroll = scroll;
if let Some(text) = self.text.as_mut() {
text.set_show_scrollbars(scroll);
}
}
fn set_part(&mut self, part: &'static ParsedMail<'static>) { fn set_part(&mut self, part: &'static ParsedMail<'static>) {
self.part = Some(part); self.part = Some(part);
self.text = None; self.text = None;
@ -472,7 +481,9 @@ impl MailPartView {
}; };
let mut text = TextView::new(body); let mut text = TextView::new(body);
text.set_wrap_method(self.wrap); text.set_wrap_method(self.wrap);
self.text = Some(text.scrollable()); let text = text.scrollable()
.show_scrollbars(self.scroll);
self.text = Some(text);
} }
} }
@ -482,8 +493,6 @@ impl View for MailPartView {
eprintln!("have text {:?}", self.text.is_some()); eprintln!("have text {:?}", self.text.is_some());
if let Some(text) = self.text.as_ref() { if let Some(text) = self.text.as_ref() {
text.draw(printer) text.draw(printer)
} else {
printer.print((0, 0), "missing text cache");
} }
} }
@ -493,7 +502,7 @@ impl View for MailPartView {
if self.cached_size != Some(given_size) { if self.cached_size != Some(given_size) {
self.setup_text(given_size); self.setup_text(given_size);
} else { } else {
if !self.layouted_text_with_scroll && self.expected_text_height.unwrap_or(0) > given_size.y { if !self.layouted_text_with_scroll && self.scroll && self.expected_text_height.unwrap_or(0) > given_size.y {
eprintln!("reconsidering given {:?}", given_size); eprintln!("reconsidering given {:?}", given_size);
self.setup_text(given_size.map_x(|x| x-2)); self.setup_text(given_size.map_x(|x| x-2));
self.layouted_text_with_scroll = true; self.layouted_text_with_scroll = true;