summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSam Tay <sam.chong.tay@gmail.com>2020-06-16 03:30:44 -0700
committerSam Tay <sam.chong.tay@gmail.com>2020-06-16 03:36:16 -0700
commitf1be144cb9a598b50bb25bf76e57375035e29ae3 (patch)
tree39a86ea6e415e7337c77a5ab6f765696b13d6147
parent88a3f45defb509daf254efced585e945eb8f05c2 (diff)
Show MdView titles when in full screen
-rw-r--r--TODO.md8
-rw-r--r--src/tui/views.rs68
2 files changed, 46 insertions, 30 deletions
diff --git a/TODO.md b/TODO.md
index a21836a..ee4c148 100644
--- a/TODO.md
+++ b/TODO.md
@@ -9,10 +9,10 @@ changing [soon](https://meta.stackexchange.com/q/348746).
### v0.2.0
#### Cursive interface for viewing questions and answers
-2. Handle focus with tab and h,l
-4. Allow cycling layouts?
-5. Init with smaller layout if terminal size smaller? maybe cli --auto-resize
- option
+2. Handle focus with h,l
+5. Init with smaller layout if terminal size smaller?
+3. maybe cli --auto-resize option
+3. make the default colors.toml file have a banging RGB > Hex > Defaults fallback
6. Small text at bottom with '?' to bring up key mapping dialog
#### other
diff --git a/src/tui/views.rs b/src/tui/views.rs
index 403990d..a093eda 100644
--- a/src/tui/views.rs
+++ b/src/tui/views.rs
@@ -184,6 +184,7 @@ pub struct MdViewT<T: View> {
/// If the LayoutView is in full screen mode, MdView should always accept
/// focus.
force_take_focus: bool,
+ title: String,
}
impl<T: View> ViewWrapper for MdViewT<T> {
@@ -205,6 +206,7 @@ impl MdView {
let view = MdViewT {
view,
inner_name,
+ title: name.to_string(),
force_take_focus: false,
};
view.with_name(name)
@@ -222,6 +224,17 @@ impl MdView {
.expect("unwrap failed in MdView.set_content")
}
+ pub fn show_title(&mut self) {
+ self.view
+ .get_inner_mut()
+ .get_inner_mut()
+ .set_title(&self.title);
+ }
+
+ pub fn hide_title(&mut self) {
+ self.view.get_inner_mut().get_inner_mut().set_title("");
+ }
+
pub fn set_take_focus(&mut self, take: bool) {
self.force_take_focus = take;
}
@@ -348,14 +361,17 @@ impl LayoutView {
fn relayout(&mut self) {
match self.layout {
Layout::BothColumns => {
- self.call_on_list_views(|v| v.set_take_focus(false));
- self.call_on_md_views(|v| v.set_take_focus(false));
- self.call_on_list_views(|v| v.unhide());
- self.call_on_md_views(|v| v.unhide());
+ self.call_on_list_views(|v| {
+ v.set_take_focus(false);
+ v.unhide();
+ });
+ self.call_on_md_views(|v| {
+ v.set_take_focus(false);
+ v.unhide();
+ v.hide_title();
+ });
}
- // TODO see if call on column works
Layout::SingleColumn => {
- self.call_on_list_views(|v| v.set_take_focus(true));
self.call_on_md_views(|v| {
v.hide();
v.set_width(&SizeConstraint::Full);
@@ -363,32 +379,32 @@ impl LayoutView {
self.call_on_list_views(|v| {
v.hide();
v.set_width(&SizeConstraint::Full);
+ v.set_take_focus(true);
});
- match self.get_focused_index().x {
- 0 => {
- self.view
- .call_on_name(NAME_QUESTION_LIST, |v: &mut ListView| {
- v.unhide();
- });
- self.view
- .call_on_name(NAME_QUESTION_VIEW, |v: &mut MdView| {
- v.unhide();
- });
- }
- _ => {
- self.view
- .call_on_name(NAME_ANSWER_LIST, |v: &mut ListView| {
- v.unhide();
- });
- self.view.call_on_name(NAME_ANSWER_VIEW, |v: &mut MdView| {
+ let name = Self::xy_to_name(self.get_focused_index());
+ if name == NAME_QUESTION_LIST || name == NAME_QUESTION_VIEW {
+ self.view
+ .call_on_name(NAME_QUESTION_LIST, |v: &mut ListView| {
+ v.unhide();
+ });
+ self.view
+ .call_on_name(NAME_QUESTION_VIEW, |v: &mut MdView| {
v.unhide();
});
- }
- };
+ } else {
+ self.view
+ .call_on_name(NAME_ANSWER_LIST, |v: &mut ListView| {
+ v.unhide();
+ });
+ self.view.call_on_name(NAME_ANSWER_VIEW, |v: &mut MdView| {
+ v.unhide();
+ });
+ }
}
Layout::FullScreen => {
- self.call_on_md_views(|v| v.set_take_focus(true));
self.call_on_md_views(|v| {
+ v.show_title();
+ v.set_take_focus(true);
v.hide();
v.resize(&SizeConstraint::Full, &SizeConstraint::Full);
});