browse: workaround ScrollView issues

This commit is contained in:
FliegendeWurst 2021-04-09 11:59:59 +02:00 committed by Arne Keller
parent 39a63ad966
commit 636e103303

View File

@ -2,12 +2,12 @@
use std::{cell::RefCell, cmp, collections::{HashMap, HashSet}, env, fmt::Display, io, sync::Arc};
use cursive::{Cursive, CursiveExt, Vec2};
use cursive::{Cursive, Vec2};
use cursive::align::HAlign;
use cursive::event::{Event, Key};
use cursive::traits::Identifiable;
use cursive::view::{Scrollable, ScrollStrategy, SizeConstraint, View};
use cursive::views::{Checkbox, LinearLayout, OnEventView, Panel, ResizedView, SelectView, TextView};
use cursive::view::{Scrollable, SizeConstraint, View};
use cursive::views::{Checkbox, LinearLayout, NamedView, OnEventView, Panel, ResizedView, ScrollView, SelectView, TextView};
use cursive_tree_view::{Placement, TreeEntry, TreeView};
use inboxid::*;
use io::Write;
@ -221,12 +221,10 @@ fn show_listing(mailbox: &str) -> Result<()> {
});
}
};
tree.set_on_select(tree_on_select);
tree.set_on_submit(|siv, _row| {
siv.focus_name("mail").unwrap();
});
let mut tree = tree.with_name("tree").scrollable();
tree.set_scroll_strategy(ScrollStrategy::StickToBottom);
let tree = tree.on_select(tree_on_select).with_name("tree").scrollable().with_name("tree_scroller");
let update_flags2 = Arc::clone(&update_flags);
let update_flags3 = Arc::clone(&update_flags);
let tree = OnEventView::new(tree)
@ -330,7 +328,16 @@ fn show_listing(mailbox: &str) -> Result<()> {
siv.add_global_callback('q', |s| s.quit());
siv.run();
// manual event loop (to scroll to end of ScrollView)
let mut siv = siv.into_runner(cursive::backends::termion::Backend::init()?);
siv.refresh();
siv.call_on_name("tree_scroller", |tree: &mut ScrollView<NamedView<MailTreeView>>| {
tree.on_event(Event::Key(Key::End))
}).unwrap().process(&mut siv);
siv.refresh();
while siv.is_running() {
siv.step();
}
Ok(())
}