diff options
author | Sam Tay <sam.chong.tay@gmail.com> | 2020-07-11 00:51:30 -0700 |
---|---|---|
committer | Sam Tay <sam.chong.tay@gmail.com> | 2020-07-12 12:05:40 -0700 |
commit | ff8f1d878cdd226e14f22a3320df5fd4b2825c77 (patch) | |
tree | 41c72ad78ab428c81d2f888a7312c6bf9a6fe25c | |
parent | ae58ddce2d6e6b37110cc9405a38eec090ea0716 (diff) |
Refactor tui::views::Layout
Separates refocus from relayout
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | TODO.md | 8 | ||||
-rw-r--r-- | src/tui/views.rs | 60 |
3 files changed, 38 insertions, 31 deletions
@@ -1,2 +1,3 @@ +tags /target **/*.rs.bk @@ -1,12 +1,10 @@ # TODO ### chores -2. Add significant cursive TUI test -3. Refactor layout handling (see TODO on `tui::views::LayoutView::relayout`) -4. Move to `directories 3.0`; optionally migrate existing macos configs? Not +1. Add significant cursive TUI test +2. Move to `directories 3.0`; optionally migrate existing macos configs? Not many people using this anyway... -6. Move to github actions ASAP, travis & appveyor are a PITA. See resources below. - +3. Move to github actions ASAP, travis & appveyor are a PITA. See resources below. ### bugs [ ] Support lack of persistent configuration: diff --git a/src/tui/views.rs b/src/tui/views.rs index d7c7af9..7d1593d 100644 --- a/src/tui/views.rs +++ b/src/tui/views.rs @@ -381,7 +381,6 @@ impl LayoutView { self.call_on_md_views(move |v| v.resize(&width, &view_height)); } - // TODO separate out resizing | relayout | refocus; these are separate // concerns and should have their own methods of invalidation fn relayout(&mut self) { match self.layout { @@ -406,25 +405,7 @@ impl LayoutView { v.set_width(&SizeConstraint::Full); v.set_take_focus(true); }); - 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(); - }); - } + self.refocus(); } Layout::FullScreen => { self.call_on_md_views(|v| { @@ -437,17 +418,44 @@ impl LayoutView { v.hide(); v.resize(&SizeConstraint::Full, &SizeConstraint::Full); }); - let name = Self::xy_to_name(self.get_focused_index()); - if name == NAME_QUESTION_LIST || name == NAME_ANSWER_LIST { - self.view.call_on_name(name, |v: &mut ListView| { + self.refocus(); + } + } + } + + fn refocus(&mut self) { + let name = Self::xy_to_name(self.get_focused_index()); + match self.layout { + Layout::SingleColumn if name == NAME_QUESTION_LIST || name == NAME_QUESTION_VIEW => { + self.view + .call_on_name(NAME_QUESTION_LIST, |v: &mut ListView| { v.unhide(); }); - } else { - self.view.call_on_name(name, |v: &mut MdView| { + self.view + .call_on_name(NAME_QUESTION_VIEW, |v: &mut MdView| { v.unhide(); }); - } } + Layout::SingleColumn => { + 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 if name == NAME_QUESTION_LIST || name == NAME_ANSWER_LIST => { + self.view.call_on_name(name, |v: &mut ListView| { + v.unhide(); + }); + } + Layout::FullScreen => { + self.view.call_on_name(name, |v: &mut MdView| { + v.unhide(); + }); + } + _ => (), } } |