summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastian Thiel <sebastian.thiel@icloud.com>2023-12-10 09:25:41 +0100
committerSebastian Thiel <sebastian.thiel@icloud.com>2023-12-10 09:25:41 +0100
commit2da2e2e7d264d19cc67ccee6bd8658f7a87901c1 (patch)
tree7bbc90d15244e95cefd270c394ce3f8b2a4886a5
parent98d5b5a2728e640f9d553648812df379c5534395 (diff)
parent49772d17dca72006e602f8707121b3378f948981 (diff)
Merge branch 'main_windows_render_refactor'
-rw-r--r--src/interactive/widgets/main.rs108
1 files changed, 63 insertions, 45 deletions
diff --git a/src/interactive/widgets/main.rs b/src/interactive/widgets/main.rs
index 2b5d2c3..d4b15bc 100644
--- a/src/interactive/widgets/main.rs
+++ b/src/interactive/widgets/main.rs
@@ -50,58 +50,22 @@ impl MainWindow {
state,
} = props.borrow();
- let (entries_style, help_style, mark_style) = {
- let grey = Style {
- fg: Color::DarkGray.into(),
- bg: Color::Reset.into(),
- add_modifier: Modifier::empty(),
- ..Style::default()
- };
- let bold = Style::default().add_modifier(Modifier::BOLD);
- match state.focussed {
- Main => (bold, grey, grey),
- Help => (grey, bold, grey),
- Mark => (grey, grey, bold),
- }
- };
+ let (entries_style, help_style, mark_style) = pane_border_style(state.focussed);
+ let (header_area, content_area, footer_area) = main_window_layout(area);
+
+ let header_bg_color = header_background_color(self.is_anything_marked(), state.focussed);
+ Header.render(header_bg_color, header_area, buf);
- let (header_area, entries_area, footer_area) = {
- let regions = Layout::default()
- .direction(Direction::Vertical)
- .constraints([Length(1), Max(256), Length(1)].as_ref())
- .split(area);
- (regions[0], regions[1], regions[2])
- };
- {
- let marked = self.mark_pane.as_ref().map(|p| p.marked());
- let bg_color = match (marked.map_or(true, |m| m.is_empty()), state.focussed) {
- (false, FocussedPane::Mark) => Color::LightRed,
- (false, _) => COLOR_MARKED,
- (_, _) => Color::White,
- };
- Header.render(bg_color, header_area, buf);
- }
let (entries_area, help_pane, mark_pane) = {
- let regions = Layout::default()
- .direction(Direction::Horizontal)
- .constraints([Percentage(50), Percentage(50)].as_ref())
- .split(entries_area);
- let (left_pane, right_pane) = (regions[0], regions[1]);
+ let (left_pane, right_pane) = content_layout(content_area);
match (&mut self.help_pane, &mut self.mark_pane) {
(Some(ref mut pane), None) => (left_pane, Some((right_pane, pane)), None),
(None, Some(ref mut pane)) => (left_pane, None, Some((right_pane, pane))),
(Some(ref mut help), Some(ref mut mark)) => {
- let regions = Layout::default()
- .direction(Direction::Vertical)
- .constraints([Percentage(50), Percentage(50)].as_ref())
- .split(right_pane);
- (
- left_pane,
- Some((regions[0], help)),
- Some((regions[1], mark)),
- )
+ let (top_area, bottom_area) = right_pane_layout(right_pane);
+ (left_pane, Some((top_area, help)), Some((bottom_area, mark)))
}
- (None, None) => (entries_area, None, None),
+ (None, None) => (content_area, None, None),
}
};
@@ -149,4 +113,58 @@ impl MainWindow {
buf,
);
}
+
+ fn is_anything_marked(&self) -> bool {
+ self.mark_pane
+ .as_ref()
+ .map(|p| p.marked())
+ .map_or(true, |m| m.is_empty())
+ }
+}
+
+fn right_pane_layout(right_pane: Rect) -> (Rect, Rect) {
+ let regions = Layout::default()
+ .direction(Direction::Vertical)
+ .constraints([Percentage(50), Percentage(50)].as_ref())
+ .split(right_pane);
+ (regions[0], regions[1])
+}
+
+fn content_layout(content_area: Rect) -> (Rect, Rect) {
+ let regions = Layout::default()
+ .direction(Direction::Horizontal)
+ .constraints([Percentage(50), Percentage(50)].as_ref())
+ .split(content_area);
+ (regions[0], regions[1])
+}
+
+fn header_background_color(is_marked: bool, focused_pane: FocussedPane) -> Color {
+ match (is_marked, focused_pane) {
+ (false, Mark) => Color::LightRed,
+ (false, _) => COLOR_MARKED,
+ (_, _) => Color::White,
+ }
+}
+
+fn main_window_layout(area: Rect) -> (Rect, Rect, Rect) {
+ let regions = Layout::default()
+ .direction(Direction::Vertical)
+ .constraints([Length(1), Max(256), Length(1)].as_ref())
+ .split(area);
+ (regions[0], regions[1], regions[2])
+}
+
+fn pane_border_style(focused_pane: FocussedPane) -> (Style, Style, Style) {
+ let grey = Style {
+ fg: Color::DarkGray.into(),
+ bg: Color::Reset.into(),
+ add_modifier: Modifier::empty(),
+ ..Style::default()
+ };
+ let bold = Style::default().add_modifier(Modifier::BOLD);
+ match focused_pane {
+ Main => (bold, grey, grey),
+ Help => (grey, bold, grey),
+ Mark => (grey, grey, bold),
+ }
}