Fix UI style priority

Fixes: https://github.com/sayanarijit/xplr/issues/68
This commit is contained in:
Arijit Basu 2021-04-15 14:43:15 +05:30 committed by Arijit Basu
parent 54bad4aa09
commit 3ab9bcb4c9
2 changed files with 22 additions and 19 deletions

View File

@ -38,7 +38,7 @@ pub struct NodeTypeConfig {
impl NodeTypeConfig { impl NodeTypeConfig {
pub fn extend(mut self, other: Self) -> Self { pub fn extend(mut self, other: Self) -> Self {
self.style = other.style.extend(self.style); self.style = self.style.extend(other.style);
self.meta.extend(other.meta); self.meta.extend(other.meta);
self self
} }

View File

@ -180,14 +180,6 @@ fn draw_table<B: Backend>(f: &mut Frame<B>, rect: Rect, app: &app::App, hb: &Han
// TODO : Optimize // TODO : Optimize
let is_selected = app.selection().contains(&node); let is_selected = app.selection().contains(&node);
let ui = if is_focused {
&config.general.focus_ui
} else if is_selected {
&config.general.selection_ui
} else {
&config.general.default_ui
};
let is_first = index == 0; let is_first = index == 0;
let is_last = index == dir.total.max(1) - 1; let is_last = index == dir.total.max(1) - 1;
@ -230,6 +222,25 @@ fn draw_table<B: Backend>(f: &mut Frame<B>, rect: Rect, app: &app::App, hb: &Han
Ordering::Equal => (0, false, false), Ordering::Equal => (0, false, false),
}; };
let (mut prefix, mut suffix, mut style) = {
let ui = config.general.default_ui.clone();
(ui.prefix, ui.suffix, ui.style.extend(node_type.style))
};
if is_selected {
let ui = config.general.selection_ui.clone();
prefix = ui.prefix.or(prefix);
suffix = ui.suffix.or(suffix);
style = style.extend(ui.style);
};
if is_focused {
let ui = config.general.focus_ui.clone();
prefix = ui.prefix.or(prefix);
suffix = ui.suffix.or(suffix);
style = style.extend(ui.style);
};
let meta = NodeUiMetadata::new( let meta = NodeUiMetadata::new(
&node, &node,
index, index,
@ -237,8 +248,8 @@ fn draw_table<B: Backend>(f: &mut Frame<B>, rect: Rect, app: &app::App, hb: &Han
is_before_focus, is_before_focus,
is_after_focus, is_after_focus,
tree.unwrap_or_default(), tree.unwrap_or_default(),
ui.prefix.to_owned().unwrap_or_default(), prefix.unwrap_or_default(),
ui.suffix.to_owned().unwrap_or_default(), suffix.unwrap_or_default(),
is_selected, is_selected,
is_focused, is_focused,
dir.total, dir.total,
@ -253,14 +264,6 @@ fn draw_table<B: Backend>(f: &mut Frame<B>, rect: Rect, app: &app::App, hb: &Han
.map(|x| Cell::from(x.to_string())) .map(|x| Cell::from(x.to_string()))
.collect::<Vec<Cell>>(); .collect::<Vec<Cell>>();
let style = if is_focused {
config.general.focus_ui.style.extend(node_type.style)
} else if is_selected {
config.general.selection_ui.style.extend(node_type.style)
} else {
config.general.default_ui.style.extend(node_type.style)
};
Row::new(cols).style(style.into()) Row::new(cols).style(style.into())
}) })
.collect::<Vec<Row>>() .collect::<Vec<Row>>()