Blender V5.0
interface_template_component_menu.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2024 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "BLI_string.h"
10#include "BLI_string_ref.hh"
11
12#include "RNA_access.hh"
13
15#include "interface_intern.hh"
16
19
22 char propname[64]; /* XXX arbitrary */
23};
24/* NOTE: this is a block-menu, needs 0 events, otherwise the menu closes */
25static uiBlock *component_menu(bContext *C, ARegion *region, void *args_v)
26{
27 ComponentMenuArgs *args = (ComponentMenuArgs *)args_v;
28
29 uiBlock *block = UI_block_begin(C, region, __func__, blender::ui::EmbossType::Emboss);
31
32 uiLayout &layout = blender::ui::block_layout(block,
35 0,
36 0,
37 UI_UNIT_X * 6,
39 0,
41 .column(false);
42
43 layout.prop(&args->ptr, args->propname, UI_ITEM_R_EXPAND, "", ICON_NONE);
44
45 UI_block_bounds_set_normal(block, 0.3f * U.widget_unit);
47
48 return block;
49}
52 const StringRefNull propname,
53 const StringRef name)
54{
55 ComponentMenuArgs *args = MEM_new<ComponentMenuArgs>(__func__);
56
57 args->ptr = *ptr;
58 STRNCPY(args->propname, propname.c_str());
59
60 uiBlock *block = layout->block();
62
63 uiBut *but = uiDefBlockButN(block,
65 args,
66 name,
67 0,
68 0,
69 UI_UNIT_X * 6,
71 "",
74 /* set rna directly, uiDefBlockButN doesn't do this */
75 but->rnapoin = *ptr;
76 but->rnaprop = RNA_struct_find_property(ptr, propname.c_str());
77 but->rnaindex = 0;
78
79 UI_block_align_end(block);
80}
char * STRNCPY(char(&dst)[N], const char *src)
Definition BLI_string.h:693
#define C
Definition RandGen.cpp:29
void * but_func_argN_copy(const void *argN)
void but_func_argN_free(void *argN)
#define UI_UNIT_Y
@ UI_BLOCK_KEEP_OPEN
uiBlock * UI_block_begin(const bContext *C, ARegion *region, std::string name, blender::ui::EmbossType emboss)
void UI_block_bounds_set_normal(uiBlock *block, int addval)
Definition interface.cc:637
const uiStyle * UI_style_get()
void UI_block_align_begin(uiBlock *block)
void UI_block_direction_set(uiBlock *block, char direction)
#define UI_UNIT_X
void UI_block_flag_enable(uiBlock *block, int flag)
uiBut * uiDefBlockButN(uiBlock *block, uiBlockCreateFunc func, void *argN, blender::StringRef str, int x, int y, short width, short height, std::optional< blender::StringRef > tip, uiButArgNFree func_argN_free_fn=MEM_freeN, uiButArgNCopy func_argN_copy_fn=MEM_dupallocN)
@ UI_DIR_DOWN
void UI_block_align_end(uiBlock *block)
@ UI_ITEM_R_EXPAND
#define U
constexpr const char * c_str() const
void uiTemplateComponentMenu(uiLayout *layout, PointerRNA *ptr, const StringRefNull propname, const StringRef name)
static uiBlock * component_menu(bContext *C, ARegion *region, void *args_v)
uiLayout & block_layout(uiBlock *block, LayoutDirection direction, LayoutType type, int x, int y, int size, int em, int padding, const uiStyle *style)
const char * name
PropertyRNA * RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
PropertyRNA * rnaprop
PointerRNA rnapoin
uiBlock * block() const
uiLayout & column(bool align)
void prop(PointerRNA *ptr, PropertyRNA *prop, int index, int value, eUI_Item_Flag flag, std::optional< blender::StringRef > name_opt, int icon, std::optional< blender::StringRef > placeholder=std::nullopt)
PointerRNA * ptr
Definition wm_files.cc:4238