Blender V5.3
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.hh"
10#include "BLI_string_ref.hh"
11
12#include "RNA_access.hh"
13
15#include "interface_intern.hh"
16
17namespace blender::ui {
18
21 char propname[64]; /* XXX arbitrary */
22};
23/* NOTE: this is a block-menu, needs 0 events, otherwise the menu closes */
24static Block *component_menu(bContext *C, ARegion *region, void *args_v)
25{
26 ComponentMenuArgs *args = static_cast<ComponentMenuArgs *>(args_v);
27
28 Block *block = block_begin(C, region, __func__, EmbossType::Emboss);
30
31 Layout &layout = block_layout(block,
34 0,
35 0,
36 UI_UNIT_X * 6,
38 0,
39 style_get())
40 .column(false);
41
42 layout.prop(&args->ptr, args->propname, ITEM_R_EXPAND, "", ICON_NONE);
43
44 block_bounds_set_normal(block, 0.3f * U.widget_unit);
46
47 return block;
48}
50 PointerRNA *ptr,
51 const StringRefNull propname,
52 const StringRef name)
53{
54 ComponentMenuArgs *args = MEM_new<ComponentMenuArgs>(__func__);
55
56 args->ptr = *ptr;
57 STRNCPY(args->propname, propname.c_str());
58
59 Block *block = layout->block();
60 block_align_begin(block);
61
62 Button *but = uiDefBlockButN(block,
64 args,
65 name,
66 0,
67 0,
68 UI_UNIT_X * 6,
70 "",
73 /* set rna directly, uiDefBlockButN doesn't do this */
74 but->rnapoin = *ptr;
75 but->rnaprop = RNA_struct_find_property(ptr, propname.c_str());
76 but->rnaindex = 0;
77
78 block_align_end(block);
79}
80
81} // namespace blender::ui
#define C
Definition RandGen.cpp:29
#define UI_UNIT_Y
#define UI_UNIT_X
constexpr const char * c_str() const
void block_direction_set(Block *block, char direction)
const uiStyle * style_get()
void block_bounds_set_normal(Block *block, int addval)
Definition interface.cc:651
void block_align_begin(Block *block)
void block_flag_enable(Block *block, int flag)
Block * block_begin(const bContext *C, ARegion *region, std::string name, EmbossType emboss)
void template_component_menu(Layout *layout, PointerRNA *ptr, StringRefNull propname, StringRef name)
void * but_func_argN_copy(const void *argN)
void block_align_end(Block *block)
void but_func_argN_free(void *argN)
Button * uiDefBlockButN(Block *block, BlockCreateFunc func, void *argN, StringRef str, int x, int y, short width, short height, std::optional< StringRef > tip, ButtonArgNFree func_argN_free_fn=MEM_delete_void, ButtonArgNCopy func_argN_copy_fn=MEM_dupalloc_void)
Layout & block_layout(Block *block, LayoutDirection direction, LayoutType type, int x, int y, int size, int em, int padding, const uiStyle *style)
static Block * component_menu(bContext *C, ARegion *region, void *args_v)
UserDef U
Definition blender.cc:58
char * STRNCPY(char(&dst)[N], const char *src)
PropertyRNA * RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
void prop(PointerRNA *ptr, PropertyRNA *prop, int index, int value, eUI_Item_Flag flag, std::optional< StringRef > name_opt, int icon, std::optional< StringRef > placeholder=std::nullopt)
Layout & column(bool align)