From a46e3d2e78dc70aa4dcf7a4f01498ac00450c352 Mon Sep 17 00:00:00 2001 From: Guillermo Venegas Date: Wed, 7 May 2025 17:03:15 +0200 Subject: [PATCH] Refactor: UI: Replace uiLayoutAbsolute and uiLayoutAbsoluteBlock with uiLayout class methods This converts the public `uiLayoutAbsolute ` and `uiLayoutAbsoluteBlock` functions to an object oriented API (an `uiLayout::absolute` and `uiLayout::absolute_block` respectively), following recent changes. `uiLayout::absolute` now returns an uiLayout reference instead of a pointer. New calls to this method should use references too. Part of: #117604 Pull Request: https://projects.blender.org/blender/blender/pulls/138546 --- .../editors/include/UI_interface_layout.hh | 5 +++-- .../editors/interface/interface_layout.cc | 18 +++++++++--------- .../templates/interface_template_color_ramp.cc | 2 +- .../templates/interface_template_icon.cc | 4 ++-- .../templates/interface_template_status.cc | 4 ++-- .../interface/templates/interface_templates.cc | 2 +- .../blender/editors/space_clip/clip_buttons.cc | 6 +++--- .../editors/space_view3d/view3d_buttons.cc | 6 +++--- .../blender/editors/uvedit/uvedit_buttons.cc | 2 +- 9 files changed, 25 insertions(+), 24 deletions(-) diff --git a/source/blender/editors/include/UI_interface_layout.hh b/source/blender/editors/include/UI_interface_layout.hh index 534468bb8aa..e3ce231ac87 100644 --- a/source/blender/editors/include/UI_interface_layout.hh +++ b/source/blender/editors/include/UI_interface_layout.hh @@ -95,6 +95,9 @@ struct uiLayout : uiItem { float search_weight_; public: + uiLayout &absolute(bool align); + uiBlock *absolute_block(); + /** * 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. @@ -391,9 +394,7 @@ uiLayout *uiLayoutListBox(uiLayout *layout, uiList *ui_list, PointerRNA *actptr, PropertyRNA *actprop); -uiLayout *uiLayoutAbsolute(uiLayout *layout, bool align); uiLayout *uiLayoutOverlap(uiLayout *layout); -uiBlock *uiLayoutAbsoluteBlock(uiLayout *layout); /** Pie menu layout: Buttons are arranged around a center. */ uiLayout *uiLayoutRadial(uiLayout *layout); diff --git a/source/blender/editors/interface/interface_layout.cc b/source/blender/editors/interface/interface_layout.cc index e42b8bd0b6d..aa98f723165 100644 --- a/source/blender/editors/interface/interface_layout.cc +++ b/source/blender/editors/interface/interface_layout.cc @@ -542,7 +542,7 @@ static void ui_item_array(uiLayout *layout, uint layer_used = 0; uint layer_active = 0; - UI_block_layout_set_current(block, uiLayoutAbsolute(layout, false)); + UI_block_layout_set_current(block, &layout->absolute(false)); const int butw = UI_UNIT_X * 0.75; const int buth = UI_UNIT_X * 0.75; @@ -603,7 +603,7 @@ static void ui_item_array(uiLayout *layout, int totdim, dim_size[3]; /* 3 == RNA_MAX_ARRAY_DIMENSION */ int row, col; - UI_block_layout_set_current(block, uiLayoutAbsolute(layout, true)); + UI_block_layout_set_current(block, &layout->absolute(true)); totdim = RNA_property_array_dimension(ptr, prop, dim_size); if (totdim != 2) { @@ -5208,22 +5208,22 @@ uiLayout *uiLayoutListBox(uiLayout *layout, return (uiLayout *)box; } -uiLayout *uiLayoutAbsolute(uiLayout *layout, bool align) +uiLayout &uiLayout::absolute(bool align) { uiLayout *litem = MEM_new(__func__); - ui_litem_init_from_parent(litem, layout, align); + ui_litem_init_from_parent(litem, this, align); litem->type_ = uiItemType::LayoutAbsolute; - UI_block_layout_set_current(layout->root_->block, litem); + UI_block_layout_set_current(root_->block, litem); - return litem; + return *litem; } -uiBlock *uiLayoutAbsoluteBlock(uiLayout *layout) +uiBlock *uiLayout::absolute_block() { - uiBlock *block = uiLayoutGetBlock(layout); - uiLayoutAbsolute(layout, false); + uiBlock *block = uiLayoutGetBlock(this); + absolute(false); return block; } diff --git a/source/blender/editors/interface/templates/interface_template_color_ramp.cc b/source/blender/editors/interface/templates/interface_template_color_ramp.cc index 61aedf6e75c..f231e09fbd0 100644 --- a/source/blender/editors/interface/templates/interface_template_color_ramp.cc +++ b/source/blender/editors/interface/templates/interface_template_color_ramp.cc @@ -413,7 +413,7 @@ void uiTemplateColorRamp(uiLayout *layout, rect.ymin = 0; rect.ymax = 19.5f * UI_UNIT_X; - uiBlock *block = uiLayoutAbsoluteBlock(layout); + uiBlock *block = layout->absolute_block(); ID *id = cptr.owner_id; UI_block_lock_set(block, (id && !ID_IS_EDITABLE(id)), ERROR_LIBDATA_MESSAGE); diff --git a/source/blender/editors/interface/templates/interface_template_icon.cc b/source/blender/editors/interface/templates/interface_template_icon.cc index 13f33dfb58a..3c1b9f3af74 100644 --- a/source/blender/editors/interface/templates/interface_template_icon.cc +++ b/source/blender/editors/interface/templates/interface_template_icon.cc @@ -95,7 +95,7 @@ static uiBlock *ui_icon_view_menu_cb(bContext *C, ARegion *region, void *arg_lit void uiTemplateIcon(uiLayout *layout, int icon_value, float icon_scale) { - uiBlock *block = uiLayoutAbsoluteBlock(layout); + uiBlock *block = layout->absolute_block(); uiBut *but = uiDefIconBut(block, UI_BTYPE_LABEL, 0, @@ -127,7 +127,7 @@ void uiTemplateIconView(uiLayout *layout, return; } - uiBlock *block = uiLayoutAbsoluteBlock(layout); + uiBlock *block = layout->absolute_block(); int tot_items; bool free_items; diff --git a/source/blender/editors/interface/templates/interface_template_status.cc b/source/blender/editors/interface/templates/interface_template_status.cc index 3abbd8ccd60..e5987ce01c2 100644 --- a/source/blender/editors/interface/templates/interface_template_status.cc +++ b/source/blender/editors/interface/templates/interface_template_status.cc @@ -59,7 +59,7 @@ void uiTemplateReportsBanner(uiLayout *layout, bContext *C) return; } - uiLayout *ui_abs = uiLayoutAbsolute(layout, false); + uiLayout *ui_abs = &layout->absolute(false); uiBlock *block = uiLayoutGetBlock(ui_abs); blender::ui::EmbossType previous_emboss = UI_block_emboss_get(block); @@ -518,7 +518,7 @@ void uiTemplateStatusInfo(uiLayout *layout, bContext *C) } const uiStyle *style = UI_style_get(); - uiLayout *ui_abs = uiLayoutAbsolute(layout, false); + uiLayout *ui_abs = &layout->absolute(false); uiBlock *block = uiLayoutGetBlock(ui_abs); blender::ui::EmbossType previous_emboss = UI_block_emboss_get(block); diff --git a/source/blender/editors/interface/templates/interface_templates.cc b/source/blender/editors/interface/templates/interface_templates.cc index dc955dd5693..8d1724d817a 100644 --- a/source/blender/editors/interface/templates/interface_templates.cc +++ b/source/blender/editors/interface/templates/interface_templates.cc @@ -244,7 +244,7 @@ uiBlock *template_common_search_menu(const bContext *C, void uiTemplateHeader(uiLayout *layout, bContext *C) { - uiBlock *block = uiLayoutAbsoluteBlock(layout); + uiBlock *block = layout->absolute_block(); ED_area_header_switchbutton(C, block, 0); } diff --git a/source/blender/editors/space_clip/clip_buttons.cc b/source/blender/editors/space_clip/clip_buttons.cc index 0b72b14a97a..1f78d786a7e 100644 --- a/source/blender/editors/space_clip/clip_buttons.cc +++ b/source/blender/editors/space_clip/clip_buttons.cc @@ -452,7 +452,7 @@ void uiTemplateMarker(uiLayout *layout, if (track->flag & TRACK_LOCKED) { uiLayoutSetActive(layout, false); - uiBlock *block = uiLayoutAbsoluteBlock(layout); + uiBlock *block = layout->absolute_block(); uiDefBut(block, UI_BTYPE_LABEL, 0, @@ -488,7 +488,7 @@ void uiTemplateMarker(uiLayout *layout, cb->marker_flag = marker->flag; - uiBlock *block = uiLayoutAbsoluteBlock(layout); + uiBlock *block = layout->absolute_block(); UI_block_func_handle_set(block, marker_block_handler, cb); UI_block_funcN_set(block, marker_update_cb, cb, nullptr); @@ -520,7 +520,7 @@ void uiTemplateMarker(uiLayout *layout, uiLayout *col = &layout->column(true); uiLayoutSetActive(col, (cb->marker_flag & MARKER_DISABLED) == 0); - block = uiLayoutAbsoluteBlock(col); + block = col->absolute_block(); UI_block_align_begin(block); uiDefBut(block, diff --git a/source/blender/editors/space_view3d/view3d_buttons.cc b/source/blender/editors/space_view3d/view3d_buttons.cc index a1657f9150f..60da0d888b5 100644 --- a/source/blender/editors/space_view3d/view3d_buttons.cc +++ b/source/blender/editors/space_view3d/view3d_buttons.cc @@ -310,7 +310,7 @@ static void v3d_editvertex_buts( const bContext *C, uiLayout *layout, View3D *v3d, Object *ob, float lim) { using namespace blender; - uiBlock *block = (layout) ? uiLayoutAbsoluteBlock(layout) : nullptr; + uiBlock *block = (layout) ? layout->absolute_block() : nullptr; TransformProperties *tfp = v3d_transform_props_ensure(v3d); TransformMedian median_basis, ve_median_basis; int tot, totedgedata, totcurvedata, totlattdata, totcurvebweight; @@ -1311,7 +1311,7 @@ static void v3d_editvertex_buts( static void v3d_object_dimension_buts(bContext *C, uiLayout *layout, View3D *v3d, Object *ob) { - uiBlock *block = (layout) ? uiLayoutAbsoluteBlock(layout) : nullptr; + uiBlock *block = (layout) ? layout->absolute_block() : nullptr; TransformProperties *tfp = v3d_transform_props_ensure(v3d); const bool is_editable = ID_IS_EDITABLE(&ob->id); @@ -1428,7 +1428,7 @@ static void update_active_vertex_weight(bContext *C, void *arg1, void * /*arg2*/ static void view3d_panel_vgroup(const bContext *C, Panel *panel) { - uiBlock *block = uiLayoutAbsoluteBlock(panel->layout); + uiBlock *block = panel->layout->absolute_block(); Scene *scene = CTX_data_scene(C); ViewLayer *view_layer = CTX_data_view_layer(C); BKE_view_layer_synced_ensure(scene, view_layer); diff --git a/source/blender/editors/uvedit/uvedit_buttons.cc b/source/blender/editors/uvedit/uvedit_buttons.cc index f5a5a56be48..14f45901dcd 100644 --- a/source/blender/editors/uvedit/uvedit_buttons.cc +++ b/source/blender/editors/uvedit/uvedit_buttons.cc @@ -239,7 +239,7 @@ static void image_panel_uv(const bContext *C, Panel *panel) { uiBlock *block; - block = uiLayoutAbsoluteBlock(panel->layout); + block = panel->layout->absolute_block(); UI_block_func_handle_set(block, do_uvedit_vertex, nullptr); uvedit_vertex_buttons(C, block);