UI: Use new C++ button apply function #2

Closed
Julian Eisel wants to merge 1 commits from temp-but-cpp-apply-func-usages into temp-but-cpp-apply-func

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
4 changed files with 32 additions and 55 deletions

View File

@ -31,6 +31,7 @@
#include "ED_screen.h" #include "ED_screen.h"
#include "UI_interface.h" #include "UI_interface.h"
#include "UI_interface.hh"
#include "interface_intern.hh" #include "interface_intern.hh"
@ -276,15 +277,8 @@ static void menu_add_shortcut_cancel(bContext *C, void *arg1)
WM_keymap_remove_item(km, kmi); WM_keymap_remove_item(km, kmi);
} }
static void popup_change_shortcut_func(bContext *C, void *arg1, void * /*arg2*/) static void remove_shortcut_func(bContext *C, uiBut *but)
{ {
uiBut *but = (uiBut *)arg1;
UI_popup_block_invoke(C, menu_change_shortcut, but, nullptr);
}
static void remove_shortcut_func(bContext *C, void *arg1, void * /*arg2*/)
{
uiBut *but = (uiBut *)arg1;
IDProperty *prop; IDProperty *prop;
const char *idname = shortcut_get_operator_property(C, but, &prop); const char *idname = shortcut_get_operator_property(C, but, &prop);
@ -305,12 +299,6 @@ static void remove_shortcut_func(bContext *C, void *arg1, void * /*arg2*/)
but_shortcut_name_func(C, but, 0); but_shortcut_name_func(C, but, 0);
} }
static void popup_add_shortcut_func(bContext *C, void *arg1, void * /*arg2*/)
{
uiBut *but = (uiBut *)arg1;
UI_popup_block_ex(C, menu_add_shortcut, nullptr, menu_add_shortcut_cancel, but, nullptr);
}
static bool ui_but_is_user_menu_compatible(bContext *C, uiBut *but) static bool ui_but_is_user_menu_compatible(bContext *C, uiBut *but)
{ {
bool result = false; bool result = false;
@ -444,22 +432,6 @@ static void ui_but_user_menu_add(bContext *C, uiBut *but, bUserMenu *um)
} }
} }
static void popup_user_menu_add_or_replace_func(bContext *C, void *arg1, void * /*arg2*/)
{
uiBut *but = static_cast<uiBut *>(arg1);
bUserMenu *um = ED_screen_user_menu_ensure(C);
U.runtime.is_dirty = true;
ui_but_user_menu_add(C, but, um);
}
static void popup_user_menu_remove_func(bContext * /*C*/, void *arg1, void *arg2)
{
bUserMenu *um = static_cast<bUserMenu *>(arg1);
bUserMenuItem *umi = static_cast<bUserMenuItem *>(arg2);
U.runtime.is_dirty = true;
ED_screen_user_menu_item_remove(&um->items, umi);
}
static void ui_but_menu_add_path_operators(uiLayout *layout, PointerRNA *ptr, PropertyRNA *prop) static void ui_but_menu_add_path_operators(uiLayout *layout, PointerRNA *ptr, PropertyRNA *prop)
{ {
const PropertySubType subtype = RNA_property_subtype(prop); const PropertySubType subtype = RNA_property_subtype(prop);
@ -1043,8 +1015,10 @@ bool ui_popup_context_menu_for_button(bContext *C, uiBut *but, const wmEvent *ev
0, 0,
0, 0,
""); "");
UI_but_func_set(but2, popup_user_menu_remove_func, um, umi); UI_but_func_set(but2, [um, umi](bContext &) {
item_found = true; U.runtime.is_dirty = true;
ED_screen_user_menu_item_remove(&um->items, umi);
});
} }
} }
if (um_array) { if (um_array) {
@ -1068,7 +1042,11 @@ bool ui_popup_context_menu_for_button(bContext *C, uiBut *but, const wmEvent *ev
0, 0,
0, 0,
"Add to a user defined context menu (stored in the user preferences)"); "Add to a user defined context menu (stored in the user preferences)");
UI_but_func_set(but2, popup_user_menu_add_or_replace_func, but, nullptr); UI_but_func_set(but2, [but](bContext &C) {
bUserMenu *um = ED_screen_user_menu_ensure(&C);
U.runtime.is_dirty = true;
ui_but_user_menu_add(&C, but, um);
});
} }
uiItemS(layout); uiItemS(layout);
@ -1117,7 +1095,9 @@ bool ui_popup_context_menu_for_button(bContext *C, uiBut *but, const wmEvent *ev
0, 0,
0, 0,
""); "");
UI_but_func_set(but2, popup_change_shortcut_func, but, nullptr); UI_but_func_set(but2, [but](bContext &C) {
UI_popup_block_invoke(&C, menu_change_shortcut, but, nullptr);
});
} }
else { else {
uiBut *but2 = uiDefIconTextBut(block, uiBut *but2 = uiDefIconTextBut(block,
@ -1155,7 +1135,7 @@ bool ui_popup_context_menu_for_button(bContext *C, uiBut *but, const wmEvent *ev
0, 0,
0, 0,
""); "");
UI_but_func_set(but2, remove_shortcut_func, but, nullptr); UI_but_func_set(but2, [but](bContext &C) { remove_shortcut_func(&C, but); });
} }
/* only show 'assign' if there's a suitable key map for it to go in */ /* only show 'assign' if there's a suitable key map for it to go in */
else if (WM_keymap_guess_opname(C, idname)) { else if (WM_keymap_guess_opname(C, idname)) {
@ -1175,7 +1155,9 @@ bool ui_popup_context_menu_for_button(bContext *C, uiBut *but, const wmEvent *ev
0, 0,
0, 0,
""); "");
UI_but_func_set(but2, popup_add_shortcut_func, but, nullptr); UI_but_func_set(but2, [but](bContext &C) {
UI_popup_block_ex(&C, menu_add_shortcut, nullptr, menu_add_shortcut_cancel, but, nullptr);
});
} }
shortcut_free_operator_property(prop); shortcut_free_operator_property(prop);

View File

@ -131,13 +131,8 @@ class CollectionViewItem : public BasicTreeViewItem {
return ICON_NONE; return ICON_NONE;
} }
static void link_state_toggle_cb(bContext * /*C*/, static void link_state_toggle(CollectionLightLinking &collection_light_linking)
void * /*collection_v*/,
void *collection_light_linking_v)
{ {
CollectionLightLinking &collection_light_linking = *static_cast<CollectionLightLinking *>(
collection_light_linking_v);
switch (collection_light_linking.link_state) { switch (collection_light_linking.link_state) {
case COLLECTION_LIGHT_LINKING_STATE_INCLUDE: case COLLECTION_LIGHT_LINKING_STATE_INCLUDE:
collection_light_linking.link_state = COLLECTION_LIGHT_LINKING_STATE_EXCLUDE; collection_light_linking.link_state = COLLECTION_LIGHT_LINKING_STATE_EXCLUDE;
@ -178,7 +173,7 @@ class CollectionViewItem : public BasicTreeViewItem {
0.0f, 0.0f,
nullptr); nullptr);
UI_but_func_set(button, link_state_toggle_cb, &collection_, &collection_light_linking_); UI_but_func_set(button, [this](bContext &) { link_state_toggle(collection_light_linking_); });
} }
void build_remove_button(uiLayout &row) void build_remove_button(uiLayout &row)

View File

@ -610,9 +610,8 @@ static void uilist_prepare(uiList *ui_list,
items->tot_items); items->tot_items);
} }
static void uilist_resize_update_cb(bContext *C, void *arg1, void * /*arg2*/) static void uilist_resize_update(bContext *C, uiList *ui_list)
{ {
uiList *ui_list = static_cast<uiList *>(arg1);
uiListDyn *dyn_data = ui_list->dyn_data; uiListDyn *dyn_data = ui_list->dyn_data;
/* This way we get diff in number of additional items to show (positive) or hide (negative). */ /* This way we get diff in number of additional items to show (positive) or hide (negative). */
@ -1148,7 +1147,7 @@ static void ui_template_list_layout_draw(const bContext *C,
0, 0,
0, 0,
""); "");
UI_but_func_set(but, uilist_resize_update_cb, ui_list, nullptr); UI_but_func_set(but, [ui_list](bContext &C) { uilist_resize_update(&C, ui_list); });
} }
UI_block_emboss_set(subblock, UI_EMBOSS); UI_block_emboss_set(subblock, UI_EMBOSS);
@ -1205,7 +1204,7 @@ static void ui_template_list_layout_draw(const bContext *C,
0, 0,
0, 0,
""); "");
UI_but_func_set(but, uilist_resize_update_cb, ui_list, nullptr); UI_but_func_set(but, [ui_list](bContext &C) { uilist_resize_update(&C, ui_list); });
} }
UI_block_emboss_set(subblock, UI_EMBOSS); UI_block_emboss_set(subblock, UI_EMBOSS);

View File

@ -109,6 +109,7 @@
#include "GPU_context.h" #include "GPU_context.h"
#include "UI_interface.h" #include "UI_interface.h"
#include "UI_interface.hh"
#include "UI_resources.h" #include "UI_resources.h"
#include "UI_view2d.h" #include "UI_view2d.h"
@ -3483,13 +3484,11 @@ static void wm_block_autorun_warning_ignore(bContext *C, void *arg_block, void *
wm_test_autorun_revert_action_set(nullptr, nullptr); wm_test_autorun_revert_action_set(nullptr, nullptr);
} }
static void wm_block_autorun_warning_reload_with_scripts(bContext *C, static void wm_block_autorun_warning_reload_with_scripts(bContext *C, uiBlock *block)
void *arg_block,
void * /*arg*/)
{ {
wmWindow *win = CTX_wm_window(C); wmWindow *win = CTX_wm_window(C);
UI_popup_block_close(C, win, static_cast<uiBlock *>(arg_block)); UI_popup_block_close(C, win, block);
/* Save user preferences for permanent execution. */ /* Save user preferences for permanent execution. */
if ((U.flag & USER_SCRIPT_AUTOEXEC_DISABLE) == 0) { if ((U.flag & USER_SCRIPT_AUTOEXEC_DISABLE) == 0) {
@ -3501,12 +3500,12 @@ static void wm_block_autorun_warning_reload_with_scripts(bContext *C,
wm_test_autorun_revert_action_exec(C); wm_test_autorun_revert_action_exec(C);
} }
static void wm_block_autorun_warning_enable_scripts(bContext *C, void *arg_block, void * /*arg*/) static void wm_block_autorun_warning_enable_scripts(bContext *C, uiBlock *block)
{ {
wmWindow *win = CTX_wm_window(C); wmWindow *win = CTX_wm_window(C);
Main *bmain = CTX_data_main(C); Main *bmain = CTX_data_main(C);
UI_popup_block_close(C, win, static_cast<uiBlock *>(arg_block)); UI_popup_block_close(C, win, block);
/* Save user preferences for permanent execution. */ /* Save user preferences for permanent execution. */
if ((U.flag & USER_SCRIPT_AUTOEXEC_DISABLE) == 0) { if ((U.flag & USER_SCRIPT_AUTOEXEC_DISABLE) == 0) {
@ -3586,7 +3585,8 @@ static uiBlock *block_create_autorun_warning(bContext *C, ARegion *region, void
0, 0,
0, 0,
TIP_("Reload file with execution of Python scripts enabled")); TIP_("Reload file with execution of Python scripts enabled"));
UI_but_func_set(but, wm_block_autorun_warning_reload_with_scripts, block, nullptr); UI_but_func_set(
but, [block](bContext &C) { wm_block_autorun_warning_reload_with_scripts(&C, block); });
} }
else { else {
but = uiDefIconTextBut(block, but = uiDefIconTextBut(block,
@ -3604,7 +3604,8 @@ static uiBlock *block_create_autorun_warning(bContext *C, ARegion *region, void
0, 0,
0, 0,
TIP_("Enable scripts")); TIP_("Enable scripts"));
UI_but_func_set(but, wm_block_autorun_warning_enable_scripts, block, nullptr); UI_but_func_set(but,
[block](bContext &C) { wm_block_autorun_warning_enable_scripts(&C, block); });
} }
UI_but_drawflag_disable(but, UI_BUT_TEXT_LEFT); UI_but_drawflag_disable(but, UI_BUT_TEXT_LEFT);