diff --git a/source/blender/blenkernel/intern/screen.cc b/source/blender/blenkernel/intern/screen.cc index ea784b98361..0511b573207 100644 --- a/source/blender/blenkernel/intern/screen.cc +++ b/source/blender/blenkernel/intern/screen.cc @@ -321,6 +321,7 @@ static void panel_list_copy(ListBase *newlb, const ListBase *lb) Panel *panel = static_cast(lb->first); for (; new_panel; new_panel = new_panel->next, panel = panel->next) { new_panel->activedata = nullptr; + new_panel->drawname = nullptr; memset(&new_panel->runtime, 0x0, sizeof(new_panel->runtime)); panel_list_copy(&new_panel->children, &panel->children); } @@ -488,6 +489,7 @@ void BKE_region_callback_free_gizmomap_set(void (*callback)(wmGizmoMap *)) static void area_region_panels_free_recursive(Panel *panel) { MEM_SAFE_FREE(panel->activedata); + MEM_SAFE_FREE(panel->drawname); LISTBASE_FOREACH_MUTABLE (Panel *, child_panel, &panel->children) { area_region_panels_free_recursive(child_panel); @@ -1096,6 +1098,7 @@ static void direct_link_panel_list(BlendDataReader *reader, ListBase *lb) panel->runtime_flag = 0; panel->activedata = nullptr; panel->type = nullptr; + panel->drawname = nullptr; panel->runtime.custom_data_ptr = nullptr; direct_link_panel_list(reader, &panel->children); } diff --git a/source/blender/editors/include/UI_interface_c.hh b/source/blender/editors/include/UI_interface_c.hh index f61d1734fe2..515f8bea627 100644 --- a/source/blender/editors/include/UI_interface_c.hh +++ b/source/blender/editors/include/UI_interface_c.hh @@ -12,6 +12,7 @@ #include #include "BLI_compiler_attrs.h" +#include "BLI_string_ref.hh" #include "BLI_string_utf8_symbols.h" #include "BLI_sys_types.h" /* size_t */ #include "BLI_utildefines.h" @@ -1877,6 +1878,9 @@ void UI_panel_header_buttons_begin(Panel *panel); void UI_panel_header_buttons_end(Panel *panel); void UI_panel_end(Panel *panel, int width, int height); +/** Set the name that should be drawn in the UI. Should be a translated string. */ +void UI_panel_drawname_set(Panel *panel, blender::StringRef name); + /** * Set a context for this entire panel and its current layout. This should be used whenever panel * callbacks that are called outside of regular drawing might require context. Currently it affects diff --git a/source/blender/editors/interface/interface_panel.cc b/source/blender/editors/interface/interface_panel.cc index 4b41210b2d9..99b246675b8 100644 --- a/source/blender/editors/interface/interface_panel.cc +++ b/source/blender/editors/interface/interface_panel.cc @@ -304,6 +304,7 @@ static void panel_delete(const bContext *C, ARegion *region, ListBase *panels, P if (panel->activedata) { MEM_freeN(panel->activedata); } + MEM_SAFE_FREE(panel->drawname); MEM_freeN(panel); } @@ -695,7 +696,7 @@ Panel *UI_panel_begin( panel->runtime.block = block; - STRNCPY(panel->drawname, drawname); + UI_panel_drawname_set(panel, drawname); /* If a new panel is added, we insert it right after the panel that was last added. * This way new panels are inserted in the right place between versions. */ @@ -831,6 +832,12 @@ void UI_panel_end(Panel *panel, int width, int height) panel->blocksizey = height; } +void UI_panel_drawname_set(Panel *panel, blender::StringRef name) +{ + MEM_SAFE_FREE(panel->drawname); + panel->drawname = BLI_strdupn(name.data(), name.size()); +} + static void ui_offset_panel_block(uiBlock *block) { const uiStyle *style = UI_style_get_dpi(); @@ -1108,7 +1115,7 @@ static void panel_draw_aligned_widgets(const uiStyle *style, } /* Draw text label. */ - if (panel->drawname[0] != '\0') { + if (panel->drawname && panel->drawname[0] != '\0') { rcti title_rect; title_rect.xmin = widget_rect.xmin + (panel->labelofs / aspect) + scaled_unit * 1.1f; title_rect.xmax = widget_rect.xmax; @@ -1118,7 +1125,7 @@ static void panel_draw_aligned_widgets(const uiStyle *style, uiFontStyleDraw_Params params{}; params.align = UI_STYLE_TEXT_LEFT; UI_fontstyle_draw( - fontstyle, &title_rect, panel->drawname, sizeof(panel->drawname), title_color, ¶ms); + fontstyle, &title_rect, panel->drawname, strlen(panel->drawname), title_color, ¶ms); } /* Draw the pin icon. */ diff --git a/source/blender/editors/interface/interface_region_hud.cc b/source/blender/editors/interface/interface_region_hud.cc index d098a69b847..8bf55691b1e 100644 --- a/source/blender/editors/interface/interface_region_hud.cc +++ b/source/blender/editors/interface/interface_region_hud.cc @@ -104,7 +104,8 @@ static bool hud_panel_operator_redo_poll(const bContext *C, PanelType * /*pt*/) static void hud_panel_operator_redo_draw_header(const bContext *C, Panel *panel) { wmOperator *op = WM_operator_last_redo(C); - STRNCPY(panel->drawname, WM_operatortype_name(op->type, op->ptr).c_str()); + const std::string opname = WM_operatortype_name(op->type, op->ptr); + UI_panel_drawname_set(panel, opname); } static void hud_panel_operator_redo_draw(const bContext *C, Panel *panel) diff --git a/source/blender/editors/space_file/file_panels.cc b/source/blender/editors/space_file/file_panels.cc index bd377285838..c1390f49f85 100644 --- a/source/blender/editors/space_file/file_panels.cc +++ b/source/blender/editors/space_file/file_panels.cc @@ -56,7 +56,8 @@ static void file_panel_operator_header(const bContext *C, Panel *panel) SpaceFile *sfile = CTX_wm_space_file(C); wmOperator *op = sfile->op; - STRNCPY(panel->drawname, WM_operatortype_name(op->type, op->ptr).c_str()); + const std::string opname = WM_operatortype_name(op->type, op->ptr); + UI_panel_drawname_set(panel, opname); } static void file_panel_operator(const bContext *C, Panel *panel) diff --git a/source/blender/makesdna/DNA_screen_types.h b/source/blender/makesdna/DNA_screen_types.h index 33f5961f8c8..fbfbf7eb9c4 100644 --- a/source/blender/makesdna/DNA_screen_types.h +++ b/source/blender/makesdna/DNA_screen_types.h @@ -154,7 +154,7 @@ typedef struct Panel { /** Defined as UI_MAX_NAME_STR. */ char panelname[64]; /** Panel name is identifier for restoring location. */ - char drawname[64]; + char *drawname; /** Offset within the region. */ int ofsx, ofsy; /** Panel size including children. */