style(tree): increase indentation

pull/9/head
wongjiahau 2 years ago
parent f0a4b109ad
commit 4dfa8696bd

@ -702,7 +702,6 @@ impl<T: TreeItem + Clone> TreeView<T> {
let params = RenderElemParams { let params = RenderElemParams {
tree: &self.tree, tree: &self.tree,
prefix: &"".to_string(), prefix: &"".to_string(),
is_last: true,
level: 0, level: 0,
selected: self.selected, selected: self.selected,
filter, filter,
@ -726,8 +725,7 @@ impl<T: TreeItem + Clone> TreeView<T> {
struct RenderElemParams<'a, T> { struct RenderElemParams<'a, T> {
tree: &'a Tree<T>, tree: &'a Tree<T>,
prefix: &'a String, prefix: &'a String,
is_last: bool, level: usize,
level: u16,
selected: usize, selected: usize,
filter: &'a str, filter: &'a str,
} }
@ -736,20 +734,25 @@ impl<T: TreeItem + Clone> TreeView<T> {
RenderElemParams { RenderElemParams {
tree, tree,
prefix, prefix,
is_last,
level, level,
selected, selected,
filter, filter,
}: RenderElemParams<T>, }: RenderElemParams<T>,
) -> Vec<(Indent, Node)> { ) -> Vec<(Indent, Node)> {
let indent = if level > 0 { let indent = if level > 0 {
let bar = if is_last { "└" } else { "├" }; let indicator = if tree.item().is_parent() {
let branch = if tree.is_opened { "┬" } else { "─" }; if tree.is_opened {
format!("{}{}{}", prefix, bar, branch) ""
} else {
""
}
} else {
" "
};
format!("{}{}", prefix, indicator)
} else { } else {
"".to_string() "".to_string()
}; };
let folded_length = tree.children.len();
let head = ( let head = (
Indent(indent), Indent(indent),
Node { Node {
@ -766,25 +769,18 @@ impl<T: TreeItem + Clone> TreeView<T> {
), ),
}, },
); );
let prefix = format!("{}{}", prefix, if is_last { " " } else { "│" }); let prefix = format!("{}{}", prefix, if level == 0 { "" } else { " " });
vec![head] vec![head]
.into_iter() .into_iter()
.chain( .chain(tree.children.iter().flat_map(|elem| {
tree.children
.iter()
.enumerate()
.flat_map(|(local_index, elem)| {
let is_last = local_index == folded_length - 1;
render_tree(RenderElemParams { render_tree(RenderElemParams {
tree: elem, tree: elem,
prefix: &prefix, prefix: &prefix,
is_last,
level: level + 1, level: level + 1,
selected, selected,
filter, filter,
}) })
}), }))
)
.collect() .collect()
} }
@ -798,8 +794,14 @@ impl<T: TreeItem + Clone> TreeView<T> {
} else { } else {
style style
}; };
let x = area.x.saturating_add(indent_len);
let x = if indent_len > 0 {
x.saturating_add(1)
} else {
x
};
surface.set_stringn( surface.set_stringn(
area.x.saturating_add(indent_len).saturating_add(1), x,
area.y, area.y,
node.name.clone(), node.name.clone(),
area.width area.width

Loading…
Cancel
Save