From d161b5d204a585b910a47ca432544570ea10911e Mon Sep 17 00:00:00 2001 From: Julian Eisel Date: Wed, 27 Oct 2021 12:06:31 +0200 Subject: 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. --- source/blender/editors/include/UI_tree_view.hh | 1 + source/blender/editors/interface/tree_view.cc | 13 ++++++++++++- .../blender/editors/space_file/asset_catalog_tree_view.cc | 8 ++------ 3 files changed, 15 insertions(+), 7 deletions(-) (limited to 'source/blender/editors') diff --git a/source/blender/editors/include/UI_tree_view.hh b/source/blender/editors/include/UI_tree_view.hh index 5a7f16c4db6..905181a7251 100644 --- a/source/blender/editors/include/UI_tree_view.hh +++ b/source/blender/editors/include/UI_tree_view.hh @@ -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: diff --git a/source/blender/editors/interface/tree_view.cc b/source/blender/editors/interface/tree_view.cc index 0eeb32bcc69..04d7a066b36 100644 --- a/source/blender/editors/interface/tree_view.cc +++ b/source/blender/editors/interface/tree_view.cc @@ -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() diff --git a/source/blender/editors/space_file/asset_catalog_tree_view.cc b/source/blender/editors/space_file/asset_catalog_tree_view.cc index 354ee742598..53981ca244d 100644 --- a/source/blender/editors/space_file/asset_catalog_tree_view.cc +++ b/source/blender/editors/space_file/asset_catalog_tree_view.cc @@ -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; -- cgit v1.2.3