Refactor: UI: Replace uiLayoutRadial with class method uiLayout::menu_pie
This converts the public `uiLayoutRadial` function to an object oriented API (`uiLayout::menu_pie`), 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::menu_pie` 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/138563
This commit is contained in:
committed by
Hans Goudey
parent
1fd958fe7c
commit
a76753ca55
@@ -155,6 +155,13 @@ struct uiLayout : uiItem {
|
||||
/** Add a new list box sub-layout. */
|
||||
uiLayout &list_box(uiList *ui_list, PointerRNA *actptr, PropertyRNA *actprop);
|
||||
|
||||
/**
|
||||
* Add a pie menu layout, buttons are arranged around a center.
|
||||
* Only one pie menu per layout root can be added, if it's already initialized it will be
|
||||
* returned instead of adding a new one.
|
||||
*/
|
||||
uiLayout &menu_pie();
|
||||
|
||||
/** Add a new overlap sub-layout. */
|
||||
uiLayout &overlap();
|
||||
|
||||
@@ -396,9 +403,6 @@ void uiLayoutListItemAddPadding(uiLayout *layout);
|
||||
|
||||
bool uiLayoutEndsWithPanelHeader(const uiLayout &layout);
|
||||
|
||||
/** Pie menu layout: Buttons are arranged around a center. */
|
||||
uiLayout *uiLayoutRadial(uiLayout *layout);
|
||||
|
||||
enum class LayoutSeparatorType : int8_t {
|
||||
Auto,
|
||||
Space,
|
||||
|
||||
@@ -106,7 +106,7 @@ enum class ItemType : int8_t {
|
||||
LayoutAbsolute,
|
||||
LayoutSplit,
|
||||
LayoutOverlap,
|
||||
LayoutRadial,
|
||||
LayoutRadial, /* AKA: menu pie. */
|
||||
|
||||
LayoutRoot,
|
||||
#if 0
|
||||
@@ -837,7 +837,7 @@ static void ui_item_enum_expand_exec(uiLayout *layout,
|
||||
uiLayout *layout_radial = nullptr;
|
||||
if (radial) {
|
||||
if (layout->root_->layout == layout) {
|
||||
layout_radial = uiLayoutRadial(layout);
|
||||
layout_radial = &layout->menu_pie();
|
||||
UI_block_layout_set_current(block, layout_radial);
|
||||
}
|
||||
else {
|
||||
@@ -1486,7 +1486,7 @@ void uiItemsFullEnumO_items(uiLayout *layout,
|
||||
const bool radial = ui_layout_is_radial(layout);
|
||||
|
||||
if (radial) {
|
||||
target = uiLayoutRadial(layout);
|
||||
target = &layout->menu_pie();
|
||||
}
|
||||
else if ((uiLayoutGetLocalDir(layout) == UI_LAYOUT_HORIZONTAL) && (flag & UI_ITEM_R_ICON_ONLY)) {
|
||||
target = layout;
|
||||
@@ -5141,30 +5141,30 @@ static uiLayoutItemBx *ui_layout_box(uiLayout *layout, int type)
|
||||
return box;
|
||||
}
|
||||
|
||||
uiLayout *uiLayoutRadial(uiLayout *layout)
|
||||
uiLayout &uiLayout::menu_pie()
|
||||
{
|
||||
/* radial layouts are only valid for radial menus */
|
||||
if (layout->root_->type != UI_LAYOUT_PIEMENU) {
|
||||
return ui_item_local_sublayout(layout, layout, false);
|
||||
if (root_->type != UI_LAYOUT_PIEMENU) {
|
||||
return *ui_item_local_sublayout(this, this, false);
|
||||
}
|
||||
|
||||
/* only one radial wheel per root layout is allowed, so check and return that, if it exists */
|
||||
for (uiItem *item : layout->root_->layout->items_) {
|
||||
for (uiItem *item : root_->layout->items_) {
|
||||
if (item->type_ == uiItemType::LayoutRadial) {
|
||||
uiLayout *litem = static_cast<uiLayout *>(item);
|
||||
UI_block_layout_set_current(layout->root_->block, litem);
|
||||
return litem;
|
||||
UI_block_layout_set_current(root_->block, litem);
|
||||
return *litem;
|
||||
}
|
||||
}
|
||||
|
||||
uiLayout *litem = MEM_new<uiLayout>(__func__);
|
||||
ui_litem_init_from_parent(litem, layout, false);
|
||||
ui_litem_init_from_parent(litem, this, false);
|
||||
|
||||
litem->type_ = uiItemType::LayoutRadial;
|
||||
|
||||
UI_block_layout_set_current(layout->root_->block, litem);
|
||||
UI_block_layout_set_current(root_->block, litem);
|
||||
|
||||
return litem;
|
||||
return *litem;
|
||||
}
|
||||
|
||||
uiLayout &uiLayout::box()
|
||||
|
||||
@@ -232,7 +232,7 @@ wmOperatorStatus UI_pie_menu_invoke_from_operator_enum(bContext *C,
|
||||
pie = UI_pie_menu_begin(C, IFACE_(title.c_str()), ICON_NONE, event);
|
||||
layout = UI_pie_menu_layout(pie);
|
||||
|
||||
layout = uiLayoutRadial(layout);
|
||||
layout = &layout->menu_pie();
|
||||
uiItemsEnumO(layout, opname, propname);
|
||||
|
||||
UI_pie_menu_end(C, pie);
|
||||
@@ -266,7 +266,7 @@ wmOperatorStatus UI_pie_menu_invoke_from_rna_enum(bContext *C,
|
||||
|
||||
layout = UI_pie_menu_layout(pie);
|
||||
|
||||
layout = uiLayoutRadial(layout);
|
||||
layout = &layout->menu_pie();
|
||||
uiItemFullR(layout, &r_ptr, r_prop, RNA_NO_INDEX, 0, UI_ITEM_R_EXPAND, std::nullopt, ICON_NONE);
|
||||
|
||||
UI_pie_menu_end(C, pie);
|
||||
@@ -316,7 +316,7 @@ static void ui_pie_menu_level_invoke(bContext *C, void *argN, void *arg2)
|
||||
uiPieMenu *pie = UI_pie_menu_begin(C, IFACE_(lvl->title), lvl->icon, win->eventstate);
|
||||
uiLayout *layout = UI_pie_menu_layout(pie);
|
||||
|
||||
layout = uiLayoutRadial(layout);
|
||||
layout = &layout->menu_pie();
|
||||
|
||||
PointerRNA ptr;
|
||||
|
||||
|
||||
@@ -910,6 +910,11 @@ static uiLayout *rna_uiLayoutGridFlow(uiLayout *layout,
|
||||
return &layout->grid_flow(row_major, columns_len, even_columns, even_rows, align);
|
||||
}
|
||||
|
||||
static uiLayout *rna_uiLayoutMenuPie(uiLayout *layout)
|
||||
{
|
||||
return &layout->menu_pie();
|
||||
}
|
||||
|
||||
void rna_uiLayoutPanelProp(uiLayout *layout,
|
||||
bContext *C,
|
||||
ReportList *reports,
|
||||
@@ -1400,7 +1405,7 @@ void RNA_api_ui_layout(StructRNA *srna)
|
||||
RNA_def_boolean(func, "align", false, "", "Align buttons to each other");
|
||||
|
||||
/* radial/pie layout */
|
||||
func = RNA_def_function(srna, "menu_pie", "uiLayoutRadial");
|
||||
func = RNA_def_function(srna, "menu_pie", "rna_uiLayoutMenuPie");
|
||||
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,
|
||||
|
||||
Reference in New Issue
Block a user