UI: Confirmations Using Std::String #117519

Merged
Harley Acheson merged 1 commits from Harley/blender:ConfirmStdString into main 2024-01-25 19:55:26 +01:00
3 changed files with 31 additions and 27 deletions

View File

@ -930,10 +930,10 @@ enum wmConfirmPosition {
}; };
struct wmConfirmDetails { struct wmConfirmDetails {
char title[1024]; std::string title;
char message[1024]; std::string message;
char message2[1024]; std::string message2;
char confirm_text[256]; std::string confirm_text;
int icon; int icon;
wmConfirmSize size; wmConfirmSize size;
wmConfirmPosition position; wmConfirmPosition position;

View File

@ -3584,8 +3584,8 @@ static void wm_clear_recent_files_confirm(bContext * /*C*/,
wmOperator * /*op*/, wmOperator * /*op*/,
wmConfirmDetails *confirm) wmConfirmDetails *confirm)
{ {
STRNCPY(confirm->message, IFACE_("Remove all items from the recent files list")); confirm->message = IFACE_("Remove all items from the recent files list");
STRNCPY(confirm->confirm_text, IFACE_("Remove All")); confirm->confirm_text = IFACE_("Remove All");
confirm->position = WM_WARNING_POSITION_CENTER; confirm->position = WM_WARNING_POSITION_CENTER;
confirm->size = WM_WARNING_SIZE_LARGE; confirm->size = WM_WARNING_SIZE_LARGE;
confirm->cancel_default = true; confirm->cancel_default = true;

View File

@ -1217,8 +1217,8 @@ static uiBlock *wm_block_confirm_create(bContext *C, ARegion *region, void *arg_
wmConfirmDetails confirm = {{0}}; wmConfirmDetails confirm = {{0}};
STRNCPY(confirm.title, WM_operatortype_description(C, op->type, op->ptr).c_str()); confirm.title = WM_operatortype_description(C, op->type, op->ptr);
STRNCPY(confirm.confirm_text, WM_operatortype_name(op->type, op->ptr).c_str()); confirm.confirm_text = WM_operatortype_name(op->type, op->ptr);
confirm.icon = ALERT_ICON_WARNING; confirm.icon = ALERT_ICON_WARNING;
confirm.size = WM_WARNING_SIZE_SMALL; confirm.size = WM_WARNING_SIZE_SMALL;
confirm.position = WM_WARNING_POSITION_MOUSE; confirm.position = WM_WARNING_POSITION_MOUSE;
@ -1245,21 +1245,23 @@ static uiBlock *wm_block_confirm_create(bContext *C, ARegion *region, void *arg_
const uiStyle *style = UI_style_get_dpi(); const uiStyle *style = UI_style_get_dpi();
int text_width = std::max( int text_width = std::max(
120 * UI_SCALE_FAC, 120 * UI_SCALE_FAC,
BLF_width(style->widget.uifont_id, confirm.title, ARRAY_SIZE(confirm.title))); BLF_width(style->widget.uifont_id, confirm.title.c_str(), confirm.title.length()));
if (confirm.message[0]) { if (!confirm.message.empty()) {
text_width = std::max( text_width = std::max(text_width,
text_width, int(BLF_width(style->widget.uifont_id,
int(BLF_width(style->widget.uifont_id, confirm.message, ARRAY_SIZE(confirm.message)))); confirm.message.c_str(),
confirm.message.length())));
} }
if (confirm.message2[0]) { if (!confirm.message2.empty()) {
text_width = std::max( text_width = std::max(text_width,
text_width, int(BLF_width(style->widget.uifont_id,
int(BLF_width(style->widget.uifont_id, confirm.message2, ARRAY_SIZE(confirm.message2)))); confirm.message2.c_str(),
confirm.message2.length())));
} }
const bool small = confirm.size == WM_WARNING_SIZE_SMALL; const bool small = confirm.size == WM_WARNING_SIZE_SMALL;
const int padding = (small ? 7 : 14) * UI_SCALE_FAC; const int padding = (small ? 7 : 14) * UI_SCALE_FAC;
const short icon_size = (small ? (confirm.message[0] ? 48 : 32) : 64) * UI_SCALE_FAC; const short icon_size = (small ? (confirm.message.empty() ? 32 : 48) : 64) * UI_SCALE_FAC;
const int dialog_width = icon_size + text_width + (style->columnspace * 2.5); const int dialog_width = icon_size + text_width + (style->columnspace * 2.5);
const float split_factor = (float)icon_size / (float)(dialog_width - style->columnspace); const float split_factor = (float)icon_size / (float)(dialog_width - style->columnspace);
@ -1278,17 +1280,19 @@ static uiBlock *wm_block_confirm_create(bContext *C, ARegion *region, void *arg_
/* The rest of the content on the right. */ /* The rest of the content on the right. */
layout = uiLayoutColumn(split_block, true); layout = uiLayoutColumn(split_block, true);
if (confirm.title[0]) { if (!confirm.title.empty()) {
if (!confirm.message[0]) { if (confirm.message.empty()) {
uiItemS(layout); uiItemS(layout);
} }
uiItemL_ex(layout, confirm.title, ICON_NONE, true, false); uiItemL_ex(layout, confirm.title.c_str(), ICON_NONE, true, false);
} }
if (confirm.message[0]) {
uiItemL(layout, confirm.message, ICON_NONE); if (!confirm.message.empty()) {
uiItemL(layout, confirm.message.c_str(), ICON_NONE);
} }
if (confirm.message2[0]) {
uiItemL(layout, confirm.message2, ICON_NONE); if (!confirm.message2.empty()) {
uiItemL(layout, confirm.message2.c_str(), ICON_NONE);
} }
uiItemS_ex(layout, small ? 0.5f : 4.0f); uiItemS_ex(layout, small ? 0.5f : 4.0f);
@ -1312,7 +1316,7 @@ static uiBlock *wm_block_confirm_create(bContext *C, ARegion *region, void *arg_
UI_BTYPE_BUT, UI_BTYPE_BUT,
0, 0,
0, 0,
confirm.confirm_text, confirm.confirm_text.c_str(),
0, 0,
0, 0,
0, 0,
@ -1348,7 +1352,7 @@ static uiBlock *wm_block_confirm_create(bContext *C, ARegion *region, void *arg_
UI_BTYPE_BUT, UI_BTYPE_BUT,
0, 0,
0, 0,
confirm.confirm_text, confirm.confirm_text.c_str(),
0, 0,
0, 0,
0, 0,