UI: Adjust template_ID Buttons Width For Content Length #119229

Merged
Harley Acheson merged 2 commits from Harley/blender:TemplateIDButtonWidth into main 2024-03-08 23:30:20 +01:00
1 changed files with 15 additions and 21 deletions

View File

@ -1206,13 +1206,11 @@ static uiBut *template_id_def_new_but(uiBlock *block,
StructRNA *type,
const char *const newop,
const bool editable,
const bool id_open,
const bool use_tab_but,
int but_height)
{
ID *idfrom = template_ui->ptr.owner_id;
uiBut *but;
const int w = id ? UI_UNIT_X : id_open ? UI_UNIT_X * 3 : UI_UNIT_X * 6;
const int but_type = use_tab_but ? UI_BTYPE_TAB : UI_BTYPE_BUT;
/* i18n markup, does nothing! */
@ -1252,13 +1250,19 @@ static uiBut *template_id_def_new_but(uiBlock *block,
* check the definition to see if a new call must be added when the limit
* is exceeded. */
const char *button_text = (id) ? "" : CTX_IFACE_(template_id_context(type), "New");
const int icon = (id && !use_tab_but) ? ICON_DUPLICATE : ICON_ADD;
const uiFontStyle *fstyle = UI_FSTYLE_WIDGET;
const int w = id ? UI_UNIT_X :
UI_fontstyle_string_width(fstyle, button_text) + (UI_UNIT_X * 1.5);
if (newop) {
but = uiDefIconTextButO(block,
but_type,
newop,
WM_OP_INVOKE_DEFAULT,
(id && !use_tab_but) ? ICON_DUPLICATE : ICON_ADD,
(id) ? "" : CTX_IFACE_(template_id_context(type), "New"),
icon,
button_text,
0,
0,
w,
@ -1268,19 +1272,8 @@ static uiBut *template_id_def_new_but(uiBlock *block,
but, template_id_cb, MEM_dupallocN(template_ui), POINTER_FROM_INT(UI_ID_ADD_NEW));
}
else {
but = uiDefIconTextBut(block,
but_type,
0,
(id && !use_tab_but) ? ICON_DUPLICATE : ICON_ADD,
(id) ? "" : CTX_IFACE_(template_id_context(type), "New"),
0,
0,
w,
but_height,
nullptr,
0,
0,
nullptr);
but = uiDefIconTextBut(
block, but_type, 0, icon, button_text, 0, 0, w, but_height, nullptr, 0, 0, nullptr);
UI_but_funcN_set(
but, template_id_cb, MEM_dupallocN(template_ui), POINTER_FROM_INT(UI_ID_ADD_NEW));
}
@ -1517,8 +1510,7 @@ static void template_ID(const bContext *C,
}
if ((flag & UI_ID_ADD_NEW) && (hide_buttons == false)) {
template_id_def_new_but(
block, id, template_ui, type, newop, editable, flag & UI_ID_OPEN, false, UI_UNIT_X);
template_id_def_new_but(block, id, template_ui, type, newop, editable, false, UI_UNIT_X);
}
/* Due to space limit in UI - skip the "open" icon for packed data, and allow to unpack.
@ -1540,7 +1532,10 @@ static void template_ID(const bContext *C,
RNA_int_set(but->opptr, "id_type", GS(id->name));
}
else if (flag & UI_ID_OPEN) {
const int w = id ? UI_UNIT_X : (flag & UI_ID_ADD_NEW) ? UI_UNIT_X * 3 : UI_UNIT_X * 6;
const char *button_text = (id) ? "" : IFACE_("Open");
const uiFontStyle *fstyle = UI_FSTYLE_WIDGET;
const int w = id ? UI_UNIT_X :
UI_fontstyle_string_width(fstyle, button_text) + (UI_UNIT_X * 1.5);
if (openop) {
but = uiDefIconTextButO(block,
@ -1707,7 +1702,6 @@ static void template_ID_tabs(const bContext *C,
type,
newop,
editable,
flag & UI_ID_OPEN,
true,
but_height);
UI_but_drawflag_enable(but, but_align);