From d30d8b4bfa0c5d586af54ddbac439e392081ca70 Mon Sep 17 00:00:00 2001 From: Leon Schittek Date: Mon, 29 Jul 2024 23:52:38 +0200 Subject: [PATCH] UI: Add padding to items in ui lists and tree views Add a utility function to add horizontal padding to the left and right of items in UI lists and tree views to make them more consistent with other buttons like menu entries. Pull Request: https://projects.blender.org/blender/blender/pulls/125498 --- .../startup/bl_ui/properties_data_armature.py | 1 - .../blender/editors/include/UI_interface_c.hh | 3 +++ .../editors/interface/interface_layout.cc | 18 ++++++++++++++++++ .../templates/interface_template_list.cc | 6 +++++- .../interface/templates/interface_templates.cc | 1 - .../editors/interface/views/tree_view.cc | 11 ++++++++--- 6 files changed, 34 insertions(+), 6 deletions(-) diff --git a/scripts/startup/bl_ui/properties_data_armature.py b/scripts/startup/bl_ui/properties_data_armature.py index 98583da6bdb..5bb62fea796 100644 --- a/scripts/startup/bl_ui/properties_data_armature.py +++ b/scripts/startup/bl_ui/properties_data_armature.py @@ -378,7 +378,6 @@ class POSE_PT_selection_sets(Panel): class POSE_UL_selection_set(UIList): def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index): row = layout.row() - row.separator() row.prop(item, "name", text="", emboss=False) if self.layout_type in ('DEFAULT', 'COMPACT'): row.prop(item, "is_selected", text="") diff --git a/source/blender/editors/include/UI_interface_c.hh b/source/blender/editors/include/UI_interface_c.hh index 7fee02db9fb..fec0ade2743 100644 --- a/source/blender/editors/include/UI_interface_c.hh +++ b/source/blender/editors/include/UI_interface_c.hh @@ -2331,6 +2331,9 @@ bool uiLayoutGetPropDecorate(uiLayout *layout); Panel *uiLayoutGetRootPanel(uiLayout *layout); float uiLayoutGetSearchWeight(uiLayout *layout); +int uiLayoutListItemPaddingWidth(); +void uiLayoutListItemAddPadding(uiLayout *layout); + /* Layout create functions. */ uiLayout *uiLayoutRow(uiLayout *layout, bool align); diff --git a/source/blender/editors/interface/interface_layout.cc b/source/blender/editors/interface/interface_layout.cc index 240b9fbe97f..6b0934f5807 100644 --- a/source/blender/editors/interface/interface_layout.cc +++ b/source/blender/editors/interface/interface_layout.cc @@ -5396,6 +5396,24 @@ eUIEmbossType uiLayoutGetEmboss(uiLayout *layout) return layout->emboss; } +int uiLayoutListItemPaddingWidth() +{ + return 5 * UI_SCALE_FAC; +} + +void uiLayoutListItemAddPadding(uiLayout *layout) +{ + uiBlock *block = uiLayoutGetBlock(layout); + uiLayout *row = uiLayoutRow(layout, true); + uiLayoutSetFixedSize(row, true); + + uiDefBut( + block, UI_BTYPE_SEPR, 0, "", 0, 0, uiLayoutListItemPaddingWidth(), 0, nullptr, 0.0, 0.0, ""); + + /* Restore. */ + UI_block_layout_set_current(block, layout); +} + /** \} */ /* -------------------------------------------------------------------- */ diff --git a/source/blender/editors/interface/templates/interface_template_list.cc b/source/blender/editors/interface/templates/interface_template_list.cc index a770853e179..453e0c9bcfb 100644 --- a/source/blender/editors/interface/templates/interface_template_list.cc +++ b/source/blender/editors/interface/templates/interface_template_list.cc @@ -794,8 +794,11 @@ static void ui_template_list_layout_draw(const bContext *C, UI_but_func_tooltip_set(but, uilist_item_tooltip_func, dyntip_data, MEM_freeN); } - sub = uiLayoutRow(overlap, false); + uiLayout *item_row = uiLayoutRow(overlap, true); + uiLayoutListItemAddPadding(item_row); + + sub = uiLayoutRow(item_row, false); icon = UI_icon_from_rnaptr(C, itemptr, rnaicon, false); if (icon == ICON_DOT) { icon = ICON_NONE; @@ -820,6 +823,7 @@ static void ui_template_list_layout_draw(const bContext *C, ui_layout_list_set_labels_active(sub); } + uiLayoutListItemAddPadding(item_row); UI_block_flag_disable(subblock, UI_BLOCK_LIST_ITEM); } } diff --git a/source/blender/editors/interface/templates/interface_templates.cc b/source/blender/editors/interface/templates/interface_templates.cc index f1a9e4f7cd3..1312b020730 100644 --- a/source/blender/editors/interface/templates/interface_templates.cc +++ b/source/blender/editors/interface/templates/interface_templates.cc @@ -2962,7 +2962,6 @@ static void draw_exporter_item(uiList * /*ui_list*/, RNA_string_get(itemptr, "name", name); uiLayout *row = uiLayoutRow(layout, false); - uiItemS(row); uiItemL(row, name, ICON_NONE); } diff --git a/source/blender/editors/interface/views/tree_view.cc b/source/blender/editors/interface/views/tree_view.cc index f2186d1423f..29a80c23185 100644 --- a/source/blender/editors/interface/views/tree_view.cc +++ b/source/blender/editors/interface/views/tree_view.cc @@ -171,9 +171,10 @@ void AbstractTreeView::draw_hierarchy_lines_recursive(const ARegion ®ion, rcti last_child_rect; ui_but_to_pixelrect(&last_child_rect, ®ion, block, &last_child_but); - const float x = first_child_rect.xmin + ((first_descendant->indent_width() - - (0.5f * UI_ICON_SIZE) + U.pixelsize + UI_SCALE_FAC) / - aspect); + const float x = first_child_rect.xmin + + ((first_descendant->indent_width() + uiLayoutListItemPaddingWidth() - + (0.5f * UI_ICON_SIZE) + U.pixelsize) / + aspect); const int first_child_top = first_child_rect.ymax - (2.0f * UI_SCALE_FAC / aspect); const int last_child_bottom = last_child_rect.ymin + (4.0f * UI_SCALE_FAC / aspect); immBegin(GPU_PRIM_LINES, 2); @@ -695,6 +696,8 @@ void TreeViewLayoutBuilder::build_row(AbstractTreeViewItem &item) const uiDefBut(&block_, UI_BTYPE_LABEL, 0, "", 0, 0, UI_UNIT_X, margin_top, nullptr, 0, 0, ""); } row = uiLayoutRow(content_col, true); + + uiLayoutListItemAddPadding(row); item.add_indent(*row); item.add_collapse_chevron(block_); @@ -705,6 +708,8 @@ void TreeViewLayoutBuilder::build_row(AbstractTreeViewItem &item) const item.build_row(*row); } + uiLayoutListItemAddPadding(row); + UI_block_emboss_set(&block_, previous_emboss); UI_block_layout_set_current(&block_, &prev_layout); }