Skip to content

Commit ff8f1d8

Browse files
committed
Refactor tui::views::Layout
Separates refocus from relayout
1 parent ae58ddc commit ff8f1d8

File tree

3 files changed

+38
-31
lines changed

3 files changed

+38
-31
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
tags
12
/target
23
**/*.rs.bk

TODO.md

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
# TODO
22

33
### chores
4-
2. Add significant cursive TUI test
5-
3. Refactor layout handling (see TODO on `tui::views::LayoutView::relayout`)
6-
4. Move to `directories 3.0`; optionally migrate existing macos configs? Not
4+
1. Add significant cursive TUI test
5+
2. Move to `directories 3.0`; optionally migrate existing macos configs? Not
76
many people using this anyway...
8-
6. Move to github actions ASAP, travis & appveyor are a PITA. See resources below.
9-
7+
3. Move to github actions ASAP, travis & appveyor are a PITA. See resources below.
108

119
### bugs
1210
[ ] Support lack of persistent configuration:

src/tui/views.rs

+34-26
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,6 @@ impl LayoutView {
381381
self.call_on_md_views(move |v| v.resize(&width, &view_height));
382382
}
383383

384-
// TODO separate out resizing | relayout | refocus; these are separate
385384
// concerns and should have their own methods of invalidation
386385
fn relayout(&mut self) {
387386
match self.layout {
@@ -406,25 +405,7 @@ impl LayoutView {
406405
v.set_width(&SizeConstraint::Full);
407406
v.set_take_focus(true);
408407
});
409-
let name = Self::xy_to_name(self.get_focused_index());
410-
if name == NAME_QUESTION_LIST || name == NAME_QUESTION_VIEW {
411-
self.view
412-
.call_on_name(NAME_QUESTION_LIST, |v: &mut ListView| {
413-
v.unhide();
414-
});
415-
self.view
416-
.call_on_name(NAME_QUESTION_VIEW, |v: &mut MdView| {
417-
v.unhide();
418-
});
419-
} else {
420-
self.view
421-
.call_on_name(NAME_ANSWER_LIST, |v: &mut ListView| {
422-
v.unhide();
423-
});
424-
self.view.call_on_name(NAME_ANSWER_VIEW, |v: &mut MdView| {
425-
v.unhide();
426-
});
427-
}
408+
self.refocus();
428409
}
429410
Layout::FullScreen => {
430411
self.call_on_md_views(|v| {
@@ -437,17 +418,44 @@ impl LayoutView {
437418
v.hide();
438419
v.resize(&SizeConstraint::Full, &SizeConstraint::Full);
439420
});
440-
let name = Self::xy_to_name(self.get_focused_index());
441-
if name == NAME_QUESTION_LIST || name == NAME_ANSWER_LIST {
442-
self.view.call_on_name(name, |v: &mut ListView| {
421+
self.refocus();
422+
}
423+
}
424+
}
425+
426+
fn refocus(&mut self) {
427+
let name = Self::xy_to_name(self.get_focused_index());
428+
match self.layout {
429+
Layout::SingleColumn if name == NAME_QUESTION_LIST || name == NAME_QUESTION_VIEW => {
430+
self.view
431+
.call_on_name(NAME_QUESTION_LIST, |v: &mut ListView| {
443432
v.unhide();
444433
});
445-
} else {
446-
self.view.call_on_name(name, |v: &mut MdView| {
434+
self.view
435+
.call_on_name(NAME_QUESTION_VIEW, |v: &mut MdView| {
447436
v.unhide();
448437
});
449-
}
450438
}
439+
Layout::SingleColumn => {
440+
self.view
441+
.call_on_name(NAME_ANSWER_LIST, |v: &mut ListView| {
442+
v.unhide();
443+
});
444+
self.view.call_on_name(NAME_ANSWER_VIEW, |v: &mut MdView| {
445+
v.unhide();
446+
});
447+
}
448+
Layout::FullScreen if name == NAME_QUESTION_LIST || name == NAME_ANSWER_LIST => {
449+
self.view.call_on_name(name, |v: &mut ListView| {
450+
v.unhide();
451+
});
452+
}
453+
Layout::FullScreen => {
454+
self.view.call_on_name(name, |v: &mut MdView| {
455+
v.unhide();
456+
});
457+
}
458+
_ => (),
451459
}
452460
}
453461

0 commit comments

Comments
 (0)