Refactor: UI: Add uiLayout context_store methods

This replaces uiLayout context_store API with uiLayout methods,
following uiLayout refactors, following the Python API naming.

Pull Request: https://projects.blender.org/blender/blender/pulls/140566
This commit is contained in:
Guillermo Venegas
2025-06-18 06:32:40 +02:00
committed by Pratik Borhade
parent 43216b03eb
commit aa1dcddb3d
29 changed files with 123 additions and 79 deletions

View File

@@ -140,7 +140,7 @@ void draw_menu_for_catalog(const asset_system::AssetCatalogTreeItem &item,
uiLayout &layout)
{
uiLayout *col = &layout.column(false);
uiLayoutSetContextString(col, "asset_catalog_path", item.catalog_path().c_str());
col->context_string_set("asset_catalog_path", item.catalog_path().c_str());
col->menu(menu_name, IFACE_(item.get_name()), ICON_NONE);
}

View File

@@ -238,7 +238,7 @@ static void popover_panel_draw(const bContext *C, Panel *panel)
bScreen *screen = CTX_wm_screen(C);
PointerRNA library_ref_ptr = RNA_pointer_create_discrete(
&screen->id, &RNA_AssetLibraryReference, &shelf->settings.asset_library_reference);
uiLayoutSetContextPointer(layout, "asset_library_reference", &library_ref_ptr);
layout->context_ptr_set("asset_library_reference", &library_ref_ptr);
uiLayout *row = &layout->row(false);
uiLayout *catalogs_col = &row->column(false);

View File

@@ -1530,7 +1530,7 @@ void ui_template_node_operator_asset_menu_items(uiLayout &layout,
return;
}
uiLayout *col = &layout.column(false);
uiLayoutSetContextString(col, "asset_catalog_path", item->catalog_path().str());
col->context_string_set("asset_catalog_path", item->catalog_path().str());
uiItemMContents(col, "GEO_MT_node_operator_catalog_assets");
}

View File

@@ -129,6 +129,22 @@ struct uiLayout : uiItem {
uiBlock *block() const;
void context_copy(const bContextStore *context);
const PointerRNA *context_ptr_get(const blender::StringRef name, const StructRNA *type) const;
void context_ptr_set(blender::StringRef name, const PointerRNA *ptr);
std::optional<blender::StringRefNull> context_string_get(const blender::StringRef name) const;
void context_string_set(blender::StringRef name, blender::StringRef value);
std::optional<int64_t> context_int_get(const blender::StringRef name) const;
void context_int_set(blender::StringRef name, int64_t value);
/** Only for convenience. */
void context_set_from_but(const uiBut *but);
bContextStore *context_store() const;
bool enabled() const;
/**
* Sets the enabled state of the layout and its items.
@@ -426,6 +442,11 @@ inline void uiLayout::activate_init_set(bool activate_init)
activate_init_ = activate_init;
}
inline bContextStore *uiLayout::context_store() const
{
return context_;
}
inline bool uiLayout::enabled() const
{
return enabled_;
@@ -558,11 +579,6 @@ void UI_block_layout_free(uiBlock *block);
bool UI_block_apply_search_filter(uiBlock *block, const char *search_filter);
void uiLayoutSetFunc(uiLayout *layout, uiMenuHandleFunc handlefunc, void *argv);
void uiLayoutSetContextPointer(uiLayout *layout, blender::StringRef name, PointerRNA *ptr);
void uiLayoutSetContextString(uiLayout *layout, blender::StringRef name, blender::StringRef value);
void uiLayoutSetContextInt(uiLayout *layout, blender::StringRef name, int64_t value);
bContextStore *uiLayoutGetContextStore(uiLayout *layout);
void uiLayoutContextCopy(uiLayout *layout, const bContextStore *context);
/**
* Set tooltip function for all buttons in the layout.
@@ -588,9 +604,6 @@ void UI_menutype_draw(bContext *C, MenuType *mt, uiLayout *layout);
*/
void UI_paneltype_draw(bContext *C, PanelType *pt, uiLayout *layout);
/* Only for convenience. */
void uiLayoutSetContextFromBut(uiLayout *layout, uiBut *but);
void uiLayoutSetRedAlert(uiLayout *layout, bool redalert);
void uiLayoutSetAlignment(uiLayout *layout, char alignment);
void uiLayoutSetFixedSize(uiLayout *layout, bool fixed_size);

View File

@@ -514,8 +514,8 @@ static void set_layout_context_from_button(bContext *C, uiLayout *layout, uiBut
if (!but->context) {
return;
}
uiLayoutContextCopy(layout, but->context);
CTX_store_set(C, uiLayoutGetContextStore(layout));
layout->context_copy(but->context);
CTX_store_set(C, layout->context_store());
}
bool ui_popup_context_menu_for_button(bContext *C, uiBut *but, const wmEvent *event)
@@ -575,7 +575,7 @@ bool ui_popup_context_menu_for_button(bContext *C, uiBut *but, const wmEvent *ev
/* Set the (button_pointer, button_prop)
* and pointer data for Python access to the hovered UI element. */
uiLayoutSetContextFromBut(layout, but);
layout->context_set_from_but(but);
/* Keyframes */
if (but->flag & UI_BUT_ANIMATED_KEY) {
@@ -1226,7 +1226,7 @@ bool ui_popup_context_menu_for_button(bContext *C, uiBut *but, const wmEvent *ev
shortcut_free_operator_property(prop);
/* Set the operator pointer for python access */
uiLayoutSetContextFromBut(layout, but);
layout->context_set_from_but(but);
layout->separator();
}

View File

@@ -1345,7 +1345,7 @@ static void ui_item_menu_hold(bContext *C, ARegion *butregion, uiBut *but)
const char *menu_id = static_cast<const char *>(but->hold_argN);
MenuType *mt = WM_menutype_find(menu_id, true);
if (mt) {
uiLayoutSetContextFromBut(layout, but);
layout->context_set_from_but(but);
UI_menutype_draw(C, mt, layout);
}
else {
@@ -5851,33 +5851,53 @@ bool UI_block_layout_needs_resolving(const uiBlock *block)
return !BLI_listbase_is_empty(&block->layouts);
}
void uiLayoutSetContextPointer(uiLayout *layout, StringRef name, PointerRNA *ptr)
const PointerRNA *uiLayout::context_ptr_get(const blender::StringRef name,
const StructRNA *type) const
{
uiBlock *block = layout->block();
layout->context_ = CTX_store_add(block->contexts, name, ptr);
if (!context_) {
return nullptr;
}
return CTX_store_ptr_lookup(context_, name, type);
}
void uiLayoutSetContextString(uiLayout *layout, StringRef name, blender::StringRef value)
void uiLayout::context_ptr_set(StringRef name, const PointerRNA *ptr)
{
uiBlock *block = layout->block();
layout->context_ = CTX_store_add(block->contexts, name, value);
uiBlock *block = this->block();
context_ = CTX_store_add(block->contexts, name, ptr);
}
std::optional<blender::StringRefNull> uiLayout::context_string_get(
const blender::StringRef name) const
{
if (!context_) {
return std::nullopt;
}
return CTX_store_string_lookup(context_, name);
}
void uiLayoutSetContextInt(uiLayout *layout, StringRef name, int64_t value)
void uiLayout::context_string_set(StringRef name, blender::StringRef value)
{
uiBlock *block = layout->block();
layout->context_ = CTX_store_add(block->contexts, name, value);
uiBlock *block = this->block();
context_ = CTX_store_add(block->contexts, name, value);
}
bContextStore *uiLayoutGetContextStore(uiLayout *layout)
std::optional<int64_t> uiLayout::context_int_get(const blender::StringRef name) const
{
return layout->context_;
if (!context_) {
return std::nullopt;
}
return CTX_store_int_lookup(context_, name);
}
void uiLayoutContextCopy(uiLayout *layout, const bContextStore *context)
void uiLayout::context_int_set(blender::StringRef name, int64_t value)
{
uiBlock *block = layout->block();
layout->context_ = CTX_store_add_all(block->contexts, context);
uiBlock *block = this->block();
context_ = CTX_store_add(block->contexts, name, value);
}
void uiLayout::context_copy(const bContextStore *context)
{
uiBlock *block = this->block();
context_ = CTX_store_add_all(block->contexts, context);
}
void uiLayoutSetTooltipFunc(uiLayout *layout,
@@ -5915,17 +5935,17 @@ void uiLayoutSetTooltipFunc(uiLayout *layout,
}
}
void uiLayoutSetContextFromBut(uiLayout *layout, uiBut *but)
void uiLayout::context_set_from_but(const uiBut *but)
{
if (but->opptr) {
uiLayoutSetContextPointer(layout, "button_operator", but->opptr);
this->context_ptr_set("button_operator", but->opptr);
}
if (but->rnapoin.data && but->rnaprop) {
/* TODO: index could be supported as well */
PointerRNA ptr_prop = RNA_pointer_create_discrete(nullptr, &RNA_Property, but->rnaprop);
uiLayoutSetContextPointer(layout, "button_prop", &ptr_prop);
uiLayoutSetContextPointer(layout, "button_pointer", &but->rnapoin);
this->context_ptr_set("button_prop", &ptr_prop);
this->context_ptr_set("button_pointer", &but->rnapoin);
}
}

View File

@@ -2699,8 +2699,8 @@ static void ui_panel_custom_data_set_recursive(Panel *panel, PointerRNA *custom_
void UI_panel_context_pointer_set(Panel *panel, const char *name, PointerRNA *ptr)
{
uiLayoutSetContextPointer(panel->layout, name, ptr);
panel->runtime->context = uiLayoutGetContextStore(panel->layout);
panel->layout->context_ptr_set(name, ptr);
panel->runtime->context = panel->layout->context_store();
}
void UI_panel_custom_data_set(Panel *panel, PointerRNA *custom_data)

View File

@@ -213,7 +213,7 @@ static void ui_popup_menu_create_block(bContext *C,
if (pup->but) {
if (pup->but->context) {
uiLayoutContextCopy(pup->layout, pup->but->context);
pup->layout->context_copy(pup->but->context);
}
}
}

View File

@@ -100,7 +100,7 @@ static void ui_popover_create_block(bContext *C,
if (pup->but) {
if (pup->but->context) {
uiLayoutContextCopy(pup->layout, pup->but->context);
pup->layout->context_copy(pup->but->context);
}
}
}

View File

@@ -42,7 +42,7 @@ void template_asset_shelf_popover(uiLayout &layout,
const bool use_big_size = !RGN_TYPE_IS_HEADER_ANY(region->regiontype);
const bool use_preview_icon = use_big_size;
uiLayoutSetContextString(row, "asset_shelf_idname", asset_shelf_id);
row->context_string_set("asset_shelf_idname", asset_shelf_id);
if (use_big_size) {
row->scale_x_set(6);
row->scale_y_set(6);
@@ -86,7 +86,7 @@ bool asset_shelf_popover_invoke(bContext &C, StringRef asset_shelf_idname, Repor
nullptr,
nullptr,
[asset_shelf_id_str](bContext *C, uiLayout *layout, void *arg_pt) {
uiLayoutSetContextString(layout, "asset_shelf_idname", asset_shelf_id_str);
layout->context_string_set("asset_shelf_idname", asset_shelf_id_str);
ui_item_paneltype_func(C, layout, arg_pt);
},
pt);

View File

@@ -37,7 +37,7 @@ void uiTemplateCacheFileVelocity(uiLayout *layout, PointerRNA *fileptr)
}
/* Ensure that the context has a CacheFile as this may not be set inside of modifiers panels. */
uiLayoutSetContextPointer(layout, "edit_cachefile", fileptr);
layout->context_ptr_set("edit_cachefile", fileptr);
layout->prop(fileptr, "velocity_name", UI_ITEM_NONE, std::nullopt, ICON_NONE);
layout->prop(fileptr, "velocity_unit", UI_ITEM_NONE, std::nullopt, ICON_NONE);
@@ -50,7 +50,7 @@ void uiTemplateCacheFileProcedural(uiLayout *layout, const bContext *C, PointerR
}
/* Ensure that the context has a CacheFile as this may not be set inside of modifiers panels. */
uiLayoutSetContextPointer(layout, "edit_cachefile", fileptr);
layout->context_ptr_set("edit_cachefile", fileptr);
uiLayout *row, *sub;
@@ -105,7 +105,7 @@ void uiTemplateCacheFileTimeSettings(uiLayout *layout, PointerRNA *fileptr)
}
/* Ensure that the context has a CacheFile as this may not be set inside of modifiers panels. */
uiLayoutSetContextPointer(layout, "edit_cachefile", fileptr);
layout->context_ptr_set("edit_cachefile", fileptr);
uiLayout *row, *sub, *subsub;
@@ -159,7 +159,7 @@ void uiTemplateCacheFileLayers(uiLayout *layout, const bContext *C, PointerRNA *
}
/* Ensure that the context has a CacheFile as this may not be set inside of modifiers panels. */
uiLayoutSetContextPointer(layout, "edit_cachefile", fileptr);
layout->context_ptr_set("edit_cachefile", fileptr);
uiLayout *row = &layout->row(false);
uiLayout *col = &row->column(true);
@@ -233,7 +233,7 @@ void uiTemplateCacheFile(uiLayout *layout,
CacheFile *file = static_cast<CacheFile *>(fileptr.data);
uiLayoutSetContextPointer(layout, "edit_cachefile", &fileptr);
layout->context_ptr_set("edit_cachefile", &fileptr);
uiTemplateID(layout, C, ptr, propname, nullptr, "CACHEFILE_OT_open", nullptr);

View File

@@ -84,7 +84,7 @@ static uiBlock *colorband_tools_fn(bContext *C, ARegion *region, void *cb_v)
style);
UI_block_layout_set_current(block, layout);
{
uiLayoutSetContextPointer(layout, "color_ramp", &coba_ptr);
layout->context_ptr_set("color_ramp", &coba_ptr);
}
/* We could move these to operators,

View File

@@ -46,7 +46,7 @@ static void constraint_ops_extra_draw(bContext *C, uiLayout *layout, void *con_v
Object *ob = blender::ed::object::context_active_object(C);
PointerRNA ptr = RNA_pointer_create_discrete(&ob->id, &RNA_Constraint, con);
uiLayoutSetContextPointer(layout, "constraint", &ptr);
layout->context_ptr_set("constraint", &ptr);
layout->operator_context_set(WM_OP_INVOKE_DEFAULT);
layout->ui_units_x_set(4.0f);
@@ -110,7 +110,7 @@ static void draw_constraint_header(uiLayout *layout, Object *ob, bConstraint *co
UI_panel_context_pointer_set(block->panel, "constraint", &ptr);
}
else {
uiLayoutSetContextPointer(layout, "constraint", &ptr);
layout->context_ptr_set("constraint", &ptr);
}
/* Constraint type icon. */

View File

@@ -1038,7 +1038,7 @@ static void template_ID(const bContext *C,
// lb = template_ui->idlb;
/* Allow operators to take the ID from context. */
uiLayoutSetContextPointer(layout, "id", &idptr);
layout->context_ptr_set("id", &idptr);
uiBlock *block = layout->block();
UI_block_align_begin(block);

View File

@@ -238,8 +238,8 @@ class CollectionViewItem : public BasicTreeViewItem {
PointerRNA id_ptr = RNA_id_pointer_create(&id_);
PointerRNA collection_ptr = RNA_id_pointer_create(&collection_.id);
uiLayoutSetContextPointer(&context_layout_, "id", &id_ptr);
uiLayoutSetContextPointer(&context_layout_, "collection", &collection_ptr);
context_layout_.context_ptr_set("id", &id_ptr);
context_layout_.context_ptr_set("collection", &collection_ptr);
}
add_label(row);

View File

@@ -792,7 +792,7 @@ static void ui_template_list_layout_draw(const bContext *C,
/* Items should be able to set context pointers for the layout. But the list-row button
* swallows events, so it needs the context storage too for handlers to see it. */
but->context = uiLayoutGetContextStore(sub);
but->context = sub->context_store();
/* If we are "drawing" active item, set all labels as active. */
if (i == items->active_item_idx) {
@@ -1041,7 +1041,7 @@ static void ui_template_list_layout_draw(const bContext *C,
/* Items should be able to set context pointers for the layout. But the list-row button
* swallows events, so it needs the context storage too for handlers to see it. */
but->context = uiLayoutGetContextStore(col);
but->context = col->context_store();
/* If we are "drawing" active item, set all labels as active. */
if (i == items->active_item_idx) {

View File

@@ -671,7 +671,7 @@ static MenuSearch_Data *menu_items_from_ui_create(bContext *C,
UI_block_flag_enable(block, UI_BLOCK_SHOW_SHORTCUT_ALWAYS);
if (current_menu.context.has_value()) {
uiLayoutContextCopy(layout, &*current_menu.context);
layout->context_copy(&*current_menu.context);
}
layout->operator_context_set(WM_OP_INVOKE_REGION_WIN);
UI_menutype_draw(C, mt, layout);

View File

@@ -396,7 +396,7 @@ void ui_template_modifier_asset_menu_items(uiLayout &layout, const StringRef cat
}
layout.separator();
uiLayout *col = &layout.column(false);
uiLayoutSetContextString(col, "asset_catalog_path", item->catalog_path().str());
col->context_string_set("asset_catalog_path", item->catalog_path().str());
uiItemMContents(col, "OBJECT_MT_add_modifier_catalog_assets");
}

View File

@@ -119,7 +119,7 @@ void uiTemplateMovieClip(uiLayout *layout,
PointerRNA clipptr = RNA_property_pointer_get(ptr, prop);
MovieClip *clip = static_cast<MovieClip *>(clipptr.data);
uiLayoutSetContextPointer(layout, "edit_movieclip", &clipptr);
layout->context_ptr_set("edit_movieclip", &clipptr);
if (!compact) {
uiTemplateID(layout, C, ptr, propname, nullptr, "CLIP_OT_open", nullptr);

View File

@@ -1347,14 +1347,14 @@ static void graph_panel_drivers_popover(const bContext *C, Panel *panel)
* this panel is getting spawned from, so that things like the "Open Drivers Editor"
* button will work.
*/
uiLayoutSetContextFromBut(layout, but);
layout->context_set_from_but(but);
/* Populate Panel - With a combination of the contents of the Driven and Driver panels */
if (fcu && fcu->driver) {
ID *id = ptr.owner_id;
PointerRNA ptr_fcurve = RNA_pointer_create_discrete(id, &RNA_FCurve, fcu);
uiLayoutSetContextPointer(layout, "active_editable_fcurve", &ptr_fcurve);
layout->context_ptr_set("active_editable_fcurve", &ptr_fcurve);
/* Driven Property Settings */
layout->label(IFACE_("Driven Property:"), ICON_NONE);

View File

@@ -772,8 +772,8 @@ void uiTemplateImage(uiLayout *layout,
Scene *scene = CTX_data_scene(C);
BKE_image_user_frame_calc(ima, iuser, scene->r.cfra);
uiLayoutSetContextPointer(layout, "edit_image", &imaptr);
uiLayoutSetContextPointer(layout, "edit_image_user", userptr);
layout->context_ptr_set("edit_image", &imaptr);
layout->context_ptr_set("edit_image_user", userptr);
SpaceImage *space_image = CTX_wm_space_image(C);
if (!compact && (space_image == nullptr || iuser != &space_image->iuser)) {

View File

@@ -1678,8 +1678,9 @@ static wmOperatorStatus image_file_browse_invoke(bContext *C, wmOperator *op, co
}
/* The image is typically passed to the operator via layout/button context (e.g.
* #uiLayoutSetContextPointer()). The File Browser doesn't support restoring this context
* when calling `exec()` though, so we have to pass it the image via custom data. */
* #uiLayout::context_ptr_set. The File Browser doesn't support
* restoring this context when calling `exec()` though, so we have to pass it the image via
* custom data. */
op->customdata = ima;
image_filesel(C, op, filepath);

View File

@@ -495,8 +495,8 @@ static void nla_panel_actclip(const bContext *C, Panel *panel)
ID &animated_id = *strip_ptr.owner_id;
if (!blender::animrig::legacy::action_treat_as_legacy(action)) {
PointerRNA animated_id_ptr = RNA_id_pointer_create(&animated_id);
uiLayoutSetContextPointer(column, "animated_id", &animated_id_ptr);
uiLayoutSetContextPointer(column, "nla_strip", &strip_ptr);
column->context_ptr_set("animated_id", &animated_id_ptr);
column->context_ptr_set("nla_strip", &strip_ptr);
uiTemplateSearch(column,
C,
&strip_ptr,

View File

@@ -323,7 +323,7 @@ void ui_template_node_asset_menu_items(uiLayout &layout,
return;
}
uiLayout *col = &layout.column(false);
uiLayoutSetContextString(col, "asset_catalog_path", item->catalog_path().str());
col->context_string_set("asset_catalog_path", item->catalog_path().str());
uiItemMContents(col, "NODE_MT_node_add_catalog_assets");
}

View File

@@ -356,7 +356,7 @@ static void node_shader_buts_tex_image(uiLayout *layout, bContext *C, PointerRNA
PointerRNA imaptr = RNA_pointer_get(ptr, "image");
PointerRNA iuserptr = RNA_pointer_get(ptr, "image_user");
uiLayoutSetContextPointer(layout, "image_user", &iuserptr);
layout->context_ptr_set("image_user", &iuserptr);
uiTemplateID(layout, C, ptr, "image", "IMAGE_OT_new", "IMAGE_OT_open", nullptr);
layout->prop(ptr, "interpolation", DEFAULT_FLAGS, "", ICON_NONE);
layout->prop(ptr, "projection", DEFAULT_FLAGS, "", ICON_NONE);
@@ -384,7 +384,7 @@ static void node_shader_buts_tex_environment(uiLayout *layout, bContext *C, Poin
PointerRNA imaptr = RNA_pointer_get(ptr, "image");
PointerRNA iuserptr = RNA_pointer_get(ptr, "image_user");
uiLayoutSetContextPointer(layout, "image_user", &iuserptr);
layout->context_ptr_set("image_user", &iuserptr);
uiTemplateID(layout, C, ptr, "image", "IMAGE_OT_new", "IMAGE_OT_open", nullptr);
layout->prop(ptr, "interpolation", DEFAULT_FLAGS, "", ICON_NONE);
@@ -508,7 +508,7 @@ static void node_composit_buts_image(uiLayout *layout, bContext *C, PointerRNA *
bNode *node = (bNode *)ptr->data;
PointerRNA iuserptr = RNA_pointer_create_discrete(ptr->owner_id, &RNA_ImageUser, node->storage);
uiLayoutSetContextPointer(layout, "image_user", &iuserptr);
layout->context_ptr_set("image_user", &iuserptr);
uiTemplateID(layout, C, ptr, "image", "IMAGE_OT_new", "IMAGE_OT_open", nullptr);
if (!node->id) {
return;
@@ -526,7 +526,7 @@ static void node_composit_buts_image_ex(uiLayout *layout, bContext *C, PointerRN
bNode *node = (bNode *)ptr->data;
PointerRNA iuserptr = RNA_pointer_create_discrete(ptr->owner_id, &RNA_ImageUser, node->storage);
uiLayoutSetContextPointer(layout, "image_user", &iuserptr);
layout->context_ptr_set("image_user", &iuserptr);
uiTemplateImage(layout, C, ptr, "image", &iuserptr, false, true);
}
@@ -603,7 +603,7 @@ static void node_composit_buts_cryptomatte(uiLayout *layout, bContext *C, Pointe
PointerRNA imaptr = RNA_pointer_get(ptr, "image");
PointerRNA iuserptr = RNA_pointer_create_discrete(
ptr->owner_id, &RNA_ImageUser, &crypto->iuser);
uiLayoutSetContextPointer(layout, "image_user", &iuserptr);
layout->context_ptr_set("image_user", &iuserptr);
node_buts_image_user(col, C, ptr, &imaptr, &iuserptr, false, false);
node_buts_image_views(col, C, ptr, &imaptr);

View File

@@ -441,7 +441,7 @@ static bool node_update_basis_buttons(const bContext &C,
layout->active_set(false);
}
uiLayoutSetContextPointer(layout, "node", &nodeptr);
layout->context_ptr_set("node", &nodeptr);
draw_buttons(layout, (bContext *)&C, &nodeptr);
@@ -526,12 +526,12 @@ static bool node_update_basis_socket(const bContext &C,
uiLayout *row = &layout->row(true);
PointerRNA nodeptr = RNA_pointer_create_discrete(&ntree.id, &RNA_Node, &node);
uiLayoutSetContextPointer(row, "node", &nodeptr);
row->context_ptr_set("node", &nodeptr);
if (input_socket) {
/* Context pointers for current node and socket. */
PointerRNA sockptr = RNA_pointer_create_discrete(&ntree.id, &RNA_NodeSocket, input_socket);
uiLayoutSetContextPointer(row, "socket", &sockptr);
row->context_ptr_set("socket", &sockptr);
uiLayoutSetAlignment(row, UI_LAYOUT_ALIGN_EXPAND);
@@ -541,7 +541,7 @@ static bool node_update_basis_socket(const bContext &C,
else {
/* Context pointers for current node and socket. */
PointerRNA sockptr = RNA_pointer_create_discrete(&ntree.id, &RNA_NodeSocket, output_socket);
uiLayoutSetContextPointer(row, "socket", &sockptr);
row->context_ptr_set("socket", &sockptr);
/* Align output buttons to the right. */
uiLayoutSetAlignment(row, UI_LAYOUT_ALIGN_RIGHT);
@@ -1157,7 +1157,7 @@ static void node_update_basis_from_declaration(
layout->active_set(false);
}
PointerRNA node_ptr = RNA_pointer_create_discrete(&ntree.id, &RNA_Node, &node);
uiLayoutSetContextPointer(layout, "node", &node_ptr);
layout->context_ptr_set("node", &node_ptr);
decl.draw(layout, const_cast<bContext *>(&C), &node_ptr);
UI_block_align_end(&block);
int buty;

View File

@@ -543,6 +543,16 @@ static void rna_uiItemSeparator(uiLayout *layout, float factor, int type)
layout->separator(factor, LayoutSeparatorType(type));
}
static void rna_uiLayoutContextPointerSet(uiLayout *layout, const char *name, PointerRNA *ptr)
{
layout->context_ptr_set(name, ptr);
}
static void rna_uiLayoutContextStringSet(uiLayout *layout, const char *name, const char *value)
{
layout->context_string_set(name, value);
}
static void rna_uiTemplateID(uiLayout *layout,
bContext *C,
PointerRNA *ptr,
@@ -1604,13 +1614,13 @@ void RNA_api_ui_layout(StructRNA *srna)
"The type of progress indicator");
/* context */
func = RNA_def_function(srna, "context_pointer_set", "uiLayoutSetContextPointer");
func = RNA_def_function(srna, "context_pointer_set", "rna_uiLayoutContextPointerSet");
parm = RNA_def_string(func, "name", nullptr, 0, "Name", "Name of entry in the context");
RNA_def_parameter_flags(parm, PropertyFlag(0), PARM_REQUIRED);
parm = RNA_def_pointer(func, "data", "AnyType", "", "Pointer to put in context");
RNA_def_parameter_flags(parm, PropertyFlag(0), PARM_REQUIRED | PARM_RNAPTR);
func = RNA_def_function(srna, "context_string_set", "uiLayoutSetContextString");
func = RNA_def_function(srna, "context_string_set", "rna_uiLayoutContextStringSet");
parm = RNA_def_string(func, "name", nullptr, 0, "Name", "Name of entry in the context");
RNA_def_parameter_flags(parm, PropertyFlag(0), PARM_REQUIRED);
parm = RNA_def_string(func, "value", nullptr, 0, "Value", "String to put in context");

View File

@@ -215,7 +215,7 @@ static void modifier_ops_extra_draw(bContext *C, uiLayout *layout, void *md_v)
Object *ob = blender::ed::object::context_active_object(C);
PointerRNA ptr = RNA_pointer_create_discrete(&ob->id, &RNA_Modifier, md);
uiLayoutSetContextPointer(layout, "modifier", &ptr);
layout->context_ptr_set("modifier", &ptr);
layout->operator_context_set(WM_OP_INVOKE_DEFAULT);
layout->ui_units_x_set(4.0f);

View File

@@ -115,7 +115,7 @@ static void gpencil_shaderfx_ops_extra_draw(bContext *C, uiLayout *layout, void
Object *ob = blender::ed::object::context_active_object(C);
PointerRNA ptr = RNA_pointer_create_discrete(&ob->id, &RNA_ShaderFx, fx);
uiLayoutSetContextPointer(layout, "shaderfx", &ptr);
layout->context_ptr_set("shaderfx", &ptr);
layout->operator_context_set(WM_OP_INVOKE_DEFAULT);
layout->ui_units_x_set(4.0f);