[Bf-blender-cvs] [d161b5d204a] master: UI: Add padding to the left of tree-rows labels without icon

Julian Eisel noreply at git.blender.org
Wed Oct 27 12:15:07 CEST 2021


Commit: d161b5d204a585b910a47ca432544570ea10911e
Author: Julian Eisel
Date:   Wed Oct 27 12:06:31 2021 +0200
Branches: master
https://developer.blender.org/rBd161b5d204a585b910a47ca432544570ea10911e

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.

===================================================================

M	source/blender/editors/include/UI_tree_view.hh
M	source/blender/editors/interface/tree_view.cc
M	source/blender/editors/space_file/asset_catalog_tree_view.cc

===================================================================

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;



More information about the Bf-blender-cvs mailing list