UI: Add padding to the left of tree-rows labels without icon

The label was placed right at the left border of the row highlight,
which looked weird. So add some padding to tree-row labels without icon
or collapse chevron, which makes it look more polished. As additional
benefit, it alignes the labels better with icons of other rows on the
same tree level. And the padding makes it more clear that a child is
indeed a child, not just a sibling without icon.
This commit is contained in:
Julian Eisel 2021-10-27 12:06:31 +02:00
parent e16bc136f9
commit d161b5d204
3 changed files with 15 additions and 7 deletions

View File

@ -404,6 +404,7 @@ class BasicTreeViewItem : public AbstractTreeViewItem {
explicit BasicTreeViewItem(StringRef label, BIFIconID icon = ICON_NONE);
void build_row(uiLayout &row) override;
void add_label(uiLayout &layout, StringRefNull label_override = "");
void on_activate(ActivateFn fn);
protected:

View File

@ -641,7 +641,18 @@ BasicTreeViewItem::BasicTreeViewItem(StringRef label, BIFIconID icon_) : icon(ic
void BasicTreeViewItem::build_row(uiLayout &row)
{
uiItemL(&row, label_.c_str(), icon);
add_label(row);
}
void BasicTreeViewItem::add_label(uiLayout &layout, StringRefNull label_override)
{
const StringRefNull label = label_override.is_empty() ? StringRefNull(label_) : label_override;
/* Some padding for labels without collapse chevron and no icon. Looks weird without. */
if (icon == ICON_NONE && !is_collapsible()) {
uiItemS_ex(&layout, 0.8f);
}
uiItemL(&layout, label.c_str(), icon);
}
void BasicTreeViewItem::on_activate()

View File

@ -233,12 +233,8 @@ void AssetCatalogTreeViewItem::on_activate()
void AssetCatalogTreeViewItem::build_row(uiLayout &row)
{
if (catalog_item_.has_unsaved_changes()) {
uiItemL(&row, (label_ + "*").c_str(), icon);
}
else {
uiItemL(&row, label_.c_str(), icon);
}
const std::string label_override = catalog_item_.has_unsaved_changes() ? (label_ + "*") : label_;
add_label(row, label_override);
if (!is_hovered()) {
return;