UI: Remove panel name size limit for complex character languages
The previous limit of 63 bytes for the panel name was an issue for languages where characters use multiple bytes. The UI would show panel names truncated that had reasonably long/short names. It's easy to support dynamically sized strings here, so do that instead of using fixed size buffers. Fixes #111927. Pull Request: https://projects.blender.org/blender/blender/pulls/111979
This commit is contained in:
committed by
Julian Eisel
parent
f1a0de8415
commit
0519e8d711
@@ -321,6 +321,7 @@ static void panel_list_copy(ListBase *newlb, const ListBase *lb)
|
||||
Panel *panel = static_cast<Panel *>(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);
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include <string>
|
||||
|
||||
#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
|
||||
|
||||
@@ -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. */
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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. */
|
||||
|
||||
Reference in New Issue
Block a user