From 5dc86dacda57fd885ee5154ad29c882a15ed702b Mon Sep 17 00:00:00 2001 From: Guillermo Venegas Date: Fri, 2 May 2025 19:46:26 +0200 Subject: [PATCH] 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 --- .../editors/include/UI_interface_layout.hh | 6 +++++- .../editors/interface/interface_layout.cc | 4 ++-- .../templates/interface_template_keymap.cc | 2 +- .../editors/interface/views/tree_view.cc | 2 +- source/blender/editors/io/io_collada.cc | 20 +++++++++---------- source/blender/editors/io/io_grease_pencil.cc | 10 +++++----- .../editors/space_graph/graph_buttons.cc | 6 +++--- source/blender/makesrna/intern/rna_ui_api.cc | 7 ++++++- 8 files changed, 33 insertions(+), 24 deletions(-) diff --git a/source/blender/editors/include/UI_interface_layout.hh b/source/blender/editors/include/UI_interface_layout.hh index e1f71479cb8..b7e6c40df4c 100644 --- a/source/blender/editors/include/UI_interface_layout.hh +++ b/source/blender/editors/include/UI_interface_layout.hh @@ -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, diff --git a/source/blender/editors/interface/interface_layout.cc b/source/blender/editors/interface/interface_layout.cc index f8ac2dc0ad5..07de140024e 100644 --- a/source/blender/editors/interface/interface_layout.cc +++ b/source/blender/editors/interface/interface_layout.cc @@ -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) diff --git a/source/blender/editors/interface/templates/interface_template_keymap.cc b/source/blender/editors/interface/templates/interface_template_keymap.cc index 3a85f3901c2..61ddb09a761 100644 --- a/source/blender/editors/interface/templates/interface_template_keymap.cc +++ b/source/blender/editors/interface/templates/interface_template_keymap.cc @@ -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); diff --git a/source/blender/editors/interface/views/tree_view.cc b/source/blender/editors/interface/views/tree_view.cc index b12ab188867..541a61a82ac 100644 --- a/source/blender/editors/interface/views/tree_view.cc +++ b/source/blender/editors/interface/views/tree_view.cc @@ -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 { diff --git a/source/blender/editors/io/io_collada.cc b/source/blender/editors/io/io_collada.cc index 7bd128e112d..5bb3d3aff07 100644 --- a/source/blender/editors/io/io_collada.cc +++ b/source/blender/editors/io/io_collada.cc @@ -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); } diff --git a/source/blender/editors/io/io_grease_pencil.cc b/source/blender/editors/io/io_grease_pencil.cc index feab81aee5e..4fb3ffb36a9 100644 --- a/source/blender/editors/io/io_grease_pencil.cc +++ b/source/blender/editors/io/io_grease_pencil.cc @@ -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); diff --git a/source/blender/editors/space_graph/graph_buttons.cc b/source/blender/editors/space_graph/graph_buttons.cc index 066ac3f2fcd..cc684c18aad 100644 --- a/source/blender/editors/space_graph/graph_buttons.cc +++ b/source/blender/editors/space_graph/graph_buttons.cc @@ -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); diff --git a/source/blender/makesrna/intern/rna_ui_api.cc b/source/blender/makesrna/intern/rna_ui_api.cc index 25a6021d691..52d005ce6f4 100644 --- a/source/blender/makesrna/intern/rna_ui_api.cc +++ b/source/blender/makesrna/intern/rna_ui_api.cc @@ -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,