UI: Make uiBut safe for non-trivial construction
No user-visible changes expected. Essentially, this makes it possible to use C++ types like `std::function` inside `uiBut`. This has plenty of benefits, for example this should help significantly reducing unsafe `void *` use (since a `std::function` can hold arbitrary data while preserving types). ---- I wanted to use a non-trivially-constructible C++ type (`std::function`) inside `uiBut`. But this would mean we can't use `MEM_cnew()` like allocation anymore. Rather than writing worse code, allow non-trivial construction for `uiBut`. Member-initializing all members is annoying since there are so many, but rather safe than sorry. As we use more C++ types (e.g. convert callbacks to use `std::function`), this should become less since they initialize properly on default construction. Also use proper C++ inheritance for `uiBut` subtypes, the old way to allocate based on size isn't working anymore. Differential Revision: https://developer.blender.org/D17164 Reviewed by: Hans Goudey
This commit is contained in:
@@ -934,7 +934,7 @@ bool ui_popup_context_menu_for_button(bContext *C, uiBut *but, const wmEvent *ev
|
||||
uiButViewItem *view_item_but = (uiButViewItem *)ui_view_item_find_mouse_over(region,
|
||||
event->xy);
|
||||
if (view_item_but) {
|
||||
BLI_assert(view_item_but->but.type == UI_BTYPE_VIEW_ITEM);
|
||||
BLI_assert(view_item_but->type == UI_BTYPE_VIEW_ITEM);
|
||||
UI_view_item_context_menu_build(C, view_item_but->view_item, uiLayoutColumn(layout, false));
|
||||
uiItemS(layout);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user