Skip to content

Commit

Permalink
Color header based on mark and pane focus state, for dramatic effect!
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Thiel committed Jun 6, 2019
1 parent 98aa1df commit f54a5aa
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
8 changes: 1 addition & 7 deletions src/interactive/widgets/header.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use crate::interactive::widgets::COLOR_MARKED_LIGHT;
use tui::{
buffer::Buffer,
layout::Rect,
Expand All @@ -9,12 +8,7 @@ use tui::{
pub struct Header;

impl Header {
pub fn render(&self, has_marked_entries: bool, area: Rect, buf: &mut Buffer) {
let bg_color = if has_marked_entries {
COLOR_MARKED_LIGHT
} else {
Color::White
};
pub fn render(&self, bg_color: Color, area: Rect, buf: &mut Buffer) {
let text_color = Color::Black;
let standard = Style {
fg: text_color,
Expand Down
12 changes: 10 additions & 2 deletions src/interactive/widgets/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::interactive::{
widgets::{
Entries, EntriesProps, Footer, FooterProps, Header, HelpPane, HelpPaneProps, MarkPane,
MarkPaneProps,
MarkPaneProps, COLOR_MARKED_LIGHT,
},
AppState, DisplayOptions, FocussedPane,
};
Expand Down Expand Up @@ -47,6 +47,7 @@ impl MainWindow {
display,
state,
} = props.borrow();

let regions = Layout::default()
.direction(Direction::Vertical)
.constraints([Length(1), Max(256), Length(1)].as_ref())
Expand Down Expand Up @@ -75,6 +76,7 @@ impl MainWindow {
(None, None) => (entries_area, None, None),
}
};

let grey = Style {
fg: Color::DarkGray,
bg: Color::Reset,
Expand All @@ -90,7 +92,13 @@ impl MainWindow {
Mark => (grey, grey, white),
};

Header.render(!state.marked.is_empty(), header_area, buf);
let bg_color = match (state.marked.is_empty(), state.focussed) {
(false, FocussedPane::Mark) => Color::LightRed,
(false, _) => COLOR_MARKED_LIGHT,
(true, _) => Color::White,
};
Header.render(bg_color, header_area, buf);

let props = EntriesProps {
tree: &tree,
root: state.root,
Expand Down

0 comments on commit f54a5aa

Please sign in to comment.