Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYevgeny Makarov <jenkm>2020-12-06 22:17:51 +0300
committerHarley Acheson <harley.acheson@gmail.com>2020-12-06 22:17:51 +0300
commitee70eb96cf321e8aca2248b96c64680a33c7766f (patch)
tree0cf4a4c0b541a559862c2ba1ad8baa54a6bd176c
parent79eeabafb39f8771c0f41c46dc8b819097e403cb (diff)
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
-rw-r--r--source/blender/editors/include/UI_interface.h4
-rw-r--r--source/blender/editors/interface/interface_layout.c42
-rw-r--r--source/blender/windowmanager/intern/wm_files.c30
3 files changed, 47 insertions, 29 deletions
diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h
index a190194d89d..005dbf0e381 100644
--- a/source/blender/editors/include/UI_interface.h
+++ b/source/blender/editors/include/UI_interface.h
@@ -26,6 +26,7 @@
#include "BLI_compiler_attrs.h"
#include "BLI_sys_types.h" /* size_t */
#include "RNA_types.h"
+#include "UI_interface_icons.h"
#ifdef __cplusplus
extern "C" {
@@ -2431,6 +2432,9 @@ void uiItemTabsEnumR_prop(uiLayout *layout,
/* Only for testing, inspecting layouts. */
const char *UI_layout_introspect(uiLayout *layout);
+/* Helper to add a big icon and create a split layout for alert boxes. */
+uiLayout *uiItemsAlertBox(uiBlock *block, const int size, const eAlertIcon icon);
+
/* UI Operators */
typedef struct uiDragColorHandle {
float color[3];
diff --git a/source/blender/editors/interface/interface_layout.c b/source/blender/editors/interface/interface_layout.c
index d61e80e6505..0403287125c 100644
--- a/source/blender/editors/interface/interface_layout.c
+++ b/source/blender/editors/interface/interface_layout.c
@@ -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;
+}
+
+/** \} */
diff --git a/source/blender/windowmanager/intern/wm_files.c b/source/blender/windowmanager/intern/wm_files.c
index 6ec6f3d9a6f..5b21b2397e7 100644
--- a/source/blender/windowmanager/intern/wm_files.c
+++ b/source/blender/windowmanager/intern/wm_files.c
@@ -115,7 +115,6 @@
#include "GHOST_Path-api.h"
#include "UI_interface.h"
-#include "UI_interface_icons.h"
#include "UI_resources.h"
#include "UI_view2d.h"
@@ -3197,40 +3196,13 @@ static uiBlock *block_create__close_file_dialog(struct bContext *C,
{
wmGenericCallback *post_action = (wmGenericCallback *)arg1;
Main *bmain = CTX_data_main(C);
- 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 * 34 * 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 = 6.0f * U.dpi_fac;
- /* Calculate icon column factor. */
- const float split_factor = ((float)icon_size + icon_padding) /
- (float)(dialog_width - style->columnspace);
uiBlock *block = UI_block_begin(C, region, close_file_dialog_name, UI_EMBOSS);
-
UI_block_flag_enable(
block, UI_BLOCK_KEEP_OPEN | UI_BLOCK_LOOP | UI_BLOCK_NO_WIN_CLIP | UI_BLOCK_NUMSELECT);
UI_block_theme_style_set(block, UI_BLOCK_THEME_STYLE_POPUP);
- UI_block_emboss_set(block, UI_EMBOSS);
-
- 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. */
- 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, ALERT_ICON_QUESTION, 0, 0, icon_size, icon_size);
- /* The rest of the content on the right. */
- layout = uiLayoutColumn(split_block, false);
+ uiLayout *layout = uiItemsAlertBox(block, 34, ALERT_ICON_QUESTION);
/* Title. */
uiItemL_ex(layout, TIP_("Save changes before closing?"), ICON_NONE, true, false);