Refactor: UI: Replace uiLayoutBox with class method uiLayout::box

This converts the public `uiLayoutBox` function to an object oriented
API (`uiLayout::box`), matching the python API.
This reduces the difference between the C++ API with the python version,
its also helps while converting code from python to C++ code (or vice-versa),
making it almost seamless.

`uiLayout::box` now returns an `uiLayout` reference instead of a pointer.
New calls to this method should use references too.

Pull Request: https://projects.blender.org/blender/blender/pulls/138334
This commit is contained in:
Guillermo Venegas
2025-05-02 19:46:26 +02:00
committed by Hans Goudey
parent b1fd91c2c0
commit 5dc86dacda
8 changed files with 33 additions and 24 deletions

View File

@@ -90,6 +90,11 @@ struct uiLayout : uiItem {
float search_weight_;
public:
/**
* Add a new box sub-layout, items placed in this sub-layout are added vertically one under
* each other in a column and are surrounded by a box.
*/
uiLayout &box();
/**
* Add a new column sub-layout, items placed in this sub-layout are added vertically one under
* each other in a column.
@@ -384,7 +389,6 @@ uiLayout *uiLayoutPanel(const bContext *C,
bool uiLayoutEndsWithPanelHeader(const uiLayout &layout);
uiLayout *uiLayoutBox(uiLayout *layout);
uiLayout *uiLayoutListBox(uiLayout *layout,
uiList *ui_list,
PointerRNA *actptr,

View File

@@ -5173,9 +5173,9 @@ uiLayout *uiLayoutRadial(uiLayout *layout)
return litem;
}
uiLayout *uiLayoutBox(uiLayout *layout)
uiLayout &uiLayout::box()
{
return (uiLayout *)ui_layout_box(layout, UI_BTYPE_ROUNDBOX);
return *ui_layout_box(this, UI_BTYPE_ROUNDBOX);
}
void ui_layout_list_set_labels_active(uiLayout *layout)

View File

@@ -48,7 +48,7 @@ static void template_keymap_item_properties(uiLayout *layout, const char *title,
}
}
uiLayout *box = uiLayoutBox(flow);
uiLayout *box = &flow->box();
uiLayoutSetActive(box, is_set);
uiLayout *row = &box->row(false);

View File

@@ -799,7 +799,7 @@ void TreeViewLayoutBuilder::build_from_tree(AbstractTreeView &tree_view)
uiLayout *col = nullptr;
if (add_box_) {
uiLayout *box = uiLayoutBox(&parent_layout);
uiLayout *box = &parent_layout.box();
col = &box->column(true);
}
else {

View File

@@ -253,7 +253,7 @@ static void uiCollada_exportSettings(uiLayout *layout, PointerRNA *imfptr)
if (ui_section == BC_UI_SECTION_MAIN) {
/* Export data options. */
box = uiLayoutBox(layout);
box = &layout->box();
col = &box->column(false);
uiItemR(col, imfptr, "selected", UI_ITEM_NONE, std::nullopt, ICON_NONE);
sub = &col->column(false);
@@ -262,7 +262,7 @@ static void uiCollada_exportSettings(uiLayout *layout, PointerRNA *imfptr)
uiItemR(sub, imfptr, "include_armatures", UI_ITEM_NONE, std::nullopt, ICON_NONE);
uiItemR(sub, imfptr, "include_shapekeys", UI_ITEM_NONE, std::nullopt, ICON_NONE);
box = uiLayoutBox(layout);
box = &layout->box();
row = &box->row(false);
uiItemL(row, IFACE_("Global Orientation"), ICON_ORIENTATION_GLOBAL);
@@ -276,7 +276,7 @@ static void uiCollada_exportSettings(uiLayout *layout, PointerRNA *imfptr)
uiItemR(box, imfptr, "export_global_up_selection", UI_ITEM_NONE, IFACE_("Up Axis"), ICON_NONE);
/* Texture options */
box = uiLayoutBox(layout);
box = &layout->box();
uiItemL(box, IFACE_("Texture Options"), ICON_TEXTURE_DATA);
col = &box->column(false);
@@ -285,7 +285,7 @@ static void uiCollada_exportSettings(uiLayout *layout, PointerRNA *imfptr)
uiItemR(row, imfptr, "active_uv_only", UI_ITEM_NONE, IFACE_("Only Selected Map"), ICON_NONE);
}
else if (ui_section == BC_UI_SECTION_GEOMETRY) {
box = uiLayoutBox(layout);
box = &layout->box();
uiItemL(box, IFACE_("Export Data Options"), ICON_MESH_DATA);
col = &box->column(false);
@@ -317,7 +317,7 @@ static void uiCollada_exportSettings(uiLayout *layout, PointerRNA *imfptr)
}
else if (ui_section == BC_UI_SECTION_ARMATURE) {
/* Armature options */
box = uiLayoutBox(layout);
box = &layout->box();
uiItemL(box, IFACE_("Armature Options"), ICON_ARMATURE_DATA);
col = &box->column(false);
@@ -326,7 +326,7 @@ static void uiCollada_exportSettings(uiLayout *layout, PointerRNA *imfptr)
}
else if (ui_section == BC_UI_SECTION_ANIMATION) {
/* Animation options. */
box = uiLayoutBox(layout);
box = &layout->box();
uiItemR(box, imfptr, "include_animations", UI_ITEM_NONE, std::nullopt, ICON_NONE);
col = &box->column(false);
@@ -372,7 +372,7 @@ static void uiCollada_exportSettings(uiLayout *layout, PointerRNA *imfptr)
}
else if (ui_section == BC_UI_SECTION_COLLADA) {
/* Collada options: */
box = uiLayoutBox(layout);
box = &layout->box();
row = &box->row(false);
uiItemL(row, IFACE_("Collada Options"), ICON_MODIFIER);
@@ -775,13 +775,13 @@ static void wm_collada_import_settings(uiLayout *layout, PointerRNA *imfptr)
uiLayoutSetPropDecorate(layout, false);
/* Import Options: */
box = uiLayoutBox(layout);
box = &layout->box();
uiItemL(box, IFACE_("Import Data Options"), ICON_MESH_DATA);
uiItemR(box, imfptr, "import_units", UI_ITEM_NONE, std::nullopt, ICON_NONE);
uiItemR(box, imfptr, "custom_normals", UI_ITEM_NONE, std::nullopt, ICON_NONE);
box = uiLayoutBox(layout);
box = &layout->box();
uiItemL(box, IFACE_("Armature Options"), ICON_ARMATURE_DATA);
col = &box->column(false);
@@ -790,7 +790,7 @@ static void wm_collada_import_settings(uiLayout *layout, PointerRNA *imfptr)
uiItemR(col, imfptr, "auto_connect", UI_ITEM_NONE, std::nullopt, ICON_NONE);
uiItemR(col, imfptr, "min_chain_length", UI_ITEM_NONE, std::nullopt, ICON_NONE);
box = uiLayoutBox(layout);
box = &layout->box();
uiItemR(box, imfptr, "keep_bind_info", UI_ITEM_NONE, std::nullopt, ICON_NONE);
}

View File

@@ -176,7 +176,7 @@ static void grease_pencil_import_svg_draw(bContext * /*C*/, wmOperator *op)
uiLayout *layout = op->layout;
uiLayoutSetPropSep(layout, true);
uiLayoutSetPropDecorate(layout, false);
uiLayout *box = uiLayoutBox(layout);
uiLayout *box = &layout->box();
uiLayout *col = &box->column(false);
uiItemR(col, op->ptr, "resolution", UI_ITEM_NONE, std::nullopt, ICON_NONE);
uiItemR(col, op->ptr, "scale", UI_ITEM_NONE, std::nullopt, ICON_NONE);
@@ -338,7 +338,7 @@ static void grease_pencil_export_svg_draw(bContext * /*C*/, wmOperator *op)
uiLayoutSetPropSep(layout, true);
uiLayoutSetPropDecorate(layout, false);
box = uiLayoutBox(layout);
box = &layout->box();
row = &box->row(false);
uiItemL(row, IFACE_("Scene Options"), ICON_NONE);
@@ -346,7 +346,7 @@ static void grease_pencil_export_svg_draw(bContext * /*C*/, wmOperator *op)
row = &box->row(false);
uiItemR(row, op->ptr, "selected_object_type", UI_ITEM_NONE, std::nullopt, ICON_NONE);
box = uiLayoutBox(layout);
box = &layout->box();
row = &box->row(false);
uiItemL(row, IFACE_("Export Options"), ICON_NONE);
@@ -497,7 +497,7 @@ static void ui_gpencil_export_pdf_settings(uiLayout *layout, PointerRNA *imfptr)
uiLayoutSetPropSep(layout, true);
uiLayoutSetPropDecorate(layout, false);
box = uiLayoutBox(layout);
box = &layout->box();
row = &box->row(false);
uiItemL(row, IFACE_("Scene Options"), ICON_NONE);
@@ -505,7 +505,7 @@ static void ui_gpencil_export_pdf_settings(uiLayout *layout, PointerRNA *imfptr)
row = &box->row(false);
uiItemR(row, imfptr, "selected_object_type", UI_ITEM_NONE, std::nullopt, ICON_NONE);
box = uiLayoutBox(layout);
box = &layout->box();
row = &box->row(false);
uiItemL(row, IFACE_("Export Options"), ICON_NONE);

View File

@@ -1141,7 +1141,7 @@ static void graph_draw_driver_settings_panel(uiLayout *layout,
col = &layout->column(true);
/* 1) header panel */
box = uiLayoutBox(col);
box = &col->box();
PointerRNA dvar_ptr = RNA_pointer_create_discrete(id, &RNA_DriverVariable, dvar);
row = &box->row(false);
@@ -1206,7 +1206,7 @@ static void graph_draw_driver_settings_panel(uiLayout *layout,
UI_block_emboss_set(block, blender::ui::EmbossType::Emboss);
/* 2) variable type settings */
box = uiLayoutBox(col);
box = &col->box();
/* controls to draw depends on the type of variable */
switch (dvar->type) {
case DVAR_TYPE_SINGLE_PROP: /* single property */
@@ -1230,7 +1230,7 @@ static void graph_draw_driver_settings_panel(uiLayout *layout,
{
char valBuf[32];
box = uiLayoutBox(col);
box = &col->box();
row = &box->row(true);
uiItemL(row, IFACE_("Value:"), ICON_NONE);

View File

@@ -867,6 +867,11 @@ static const EnumPropertyItem *rna_uiTemplateAssetView_filter_id_types_itemf(
return items;
}
static uiLayout *rna_uiLayoutBox(uiLayout *layout)
{
return &layout->box();
}
static uiLayout *rna_uiLayoutRowWithHeading(
uiLayout *layout, bool align, const char *heading, const char *heading_ctxt, bool translate)
{
@@ -1367,7 +1372,7 @@ void RNA_api_ui_layout(StructRNA *srna)
RNA_def_function_return(func, parm);
/* box layout */
func = RNA_def_function(srna, "box", "uiLayoutBox");
func = RNA_def_function(srna, "box", "rna_uiLayoutBox");
parm = RNA_def_pointer(func, "layout", "UILayout", "", "Sub-layout to put items in");
RNA_def_function_return(func, parm);
RNA_def_function_ui_description(func,