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
This commit is contained in:
committed by
Harley Acheson
parent
6d992ff071
commit
d30d8b4bfa
@@ -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="")
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
/** \} */
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user