UI: Alert Dialog Helper Function
Shared helper function to create a split layout with an alert icon for popup dialogs. Differential Revision: https://developer.blender.org/D9486 Reviewed by Julian Eisel
This commit is contained in:
@@ -5951,3 +5951,45 @@ const char *UI_layout_introspect(uiLayout *layout)
|
||||
}
|
||||
|
||||
/** \} */
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
/** \name Alert Box with Big Icon
|
||||
* \{ */
|
||||
|
||||
/**
|
||||
* Helper to add a big icon and create a split layout for alert popups.
|
||||
* Returns the layout to place further items into the alert box.
|
||||
*/
|
||||
uiLayout *uiItemsAlertBox(uiBlock *block, const int size, const eAlertIcon icon)
|
||||
{
|
||||
const uiStyle *style = UI_style_get_dpi();
|
||||
const short icon_size = 64 * U.dpi_fac;
|
||||
const int text_points_max = MAX2(style->widget.points, style->widgetlabel.points);
|
||||
const int dialog_width = icon_size + (text_points_max * size * U.dpi_fac);
|
||||
/* By default, the space between icon and text/buttons will be equal to the 'columnspace',
|
||||
this extra padding will add some space by increasing the left column width,
|
||||
making the icon placement more symmetrical, between the block edge and the text. */
|
||||
const float icon_padding = 5.0f * U.dpi_fac;
|
||||
/* Calculate the factor of the fixed icon column depending on the block width. */
|
||||
const float split_factor = ((float)icon_size + icon_padding) /
|
||||
(float)(dialog_width - style->columnspace);
|
||||
|
||||
uiLayout *block_layout = UI_block_layout(
|
||||
block, UI_LAYOUT_VERTICAL, UI_LAYOUT_PANEL, 0, 0, dialog_width, 0, 0, style);
|
||||
|
||||
/* Split layout to put alert icon on left side. */
|
||||
uiLayout *split_block = uiLayoutSplit(block_layout, split_factor, false);
|
||||
|
||||
/* Alert icon on the left. */
|
||||
uiLayout *layout = uiLayoutRow(split_block, false);
|
||||
/* Using 'align_left' with 'row' avoids stretching the icon along the width of column. */
|
||||
uiLayoutSetAlignment(layout, UI_LAYOUT_ALIGN_LEFT);
|
||||
uiDefButAlert(block, icon, 0, 0, icon_size, icon_size);
|
||||
|
||||
/* The rest of the content on the right. */
|
||||
layout = uiLayoutColumn(split_block, false);
|
||||
|
||||
return layout;
|
||||
}
|
||||
|
||||
/** \} */
|
||||
|
||||
Reference in New Issue
Block a user