UI: support for center popovers over buttons

This commit is contained in:
Campbell Barton 2018-04-22 22:08:48 +02:00
parent 46375b8e03
commit 62cd5e0b7b
6 changed files with 34 additions and 8 deletions

View File

@ -108,7 +108,8 @@ enum {
UI_DIR_DOWN = (1 << 1),
UI_DIR_LEFT = (1 << 2),
UI_DIR_RIGHT = (1 << 3),
UI_DIR_CENTER_Y = (1 << 4),
UI_DIR_CENTER_X = (1 << 4),
UI_DIR_CENTER_Y = (1 << 5),
UI_DIR_ALL = (UI_DIR_UP | UI_DIR_DOWN | UI_DIR_LEFT | UI_DIR_RIGHT),
};
@ -140,6 +141,7 @@ enum {
#define UI_BLOCK_POPUP_HOLD (1 << 18)
#define UI_BLOCK_LIST_ITEM (1 << 19)
#define UI_BLOCK_RADIAL (1 << 20)
#define UI_BLOCK_POPOVER (1 << 21)
/* uiPopupBlockHandle->menuretval */
#define UI_RETURN_CANCEL (1 << 0) /* cancel all menus cascading */

View File

@ -1308,6 +1308,8 @@ void UI_block_draw(const bContext *C, uiBlock *block)
/* back */
if (block->flag & UI_BLOCK_RADIAL)
ui_draw_pie_center(block);
else if (block->flag & UI_BLOCK_POPOVER)
ui_draw_popover_back(&style, block, &rect);
else if (block->flag & UI_BLOCK_LOOP)
ui_draw_menu_back(&style, block, &rect);
else if (block->panel)

View File

@ -728,6 +728,7 @@ struct Gwn_Batch *ui_batch_roundbox_shadow_get(void);
void ui_draw_anti_roundbox(int mode, float minx, float miny, float maxx, float maxy,
float rad, bool use_alpha, const float color[4]);
void ui_draw_menu_back(struct uiStyle *style, uiBlock *block, rcti *rect);
void ui_draw_popover_back(struct uiStyle *style, uiBlock *block, rcti *rect);
void ui_draw_pie_center(uiBlock *block);
uiWidgetColors *ui_tooltip_get_theme(void);
void ui_draw_tooltip_background(uiStyle *UNUSED(style), uiBlock *block, rcti *rect);

View File

@ -129,7 +129,9 @@ static uiBlock *ui_block_func_POPOVER(bContext *C, uiPopupBlockHandle *handle, v
UI_block_layout_resolve(block, &width, &height);
UI_block_flag_enable(block, UI_BLOCK_MOVEMOUSE_QUIT | UI_BLOCK_KEEP_OPEN);
UI_block_flag_enable(block, UI_BLOCK_MOVEMOUSE_QUIT | UI_BLOCK_KEEP_OPEN | UI_BLOCK_POPOVER);
UI_block_direction_set(block, UI_DIR_DOWN | UI_DIR_CENTER_X);
if (pup->popover) {
UI_block_flag_enable(block, UI_BLOCK_LOOP);

View File

@ -138,11 +138,12 @@ static void ui_block_position(wmWindow *window, ARegion *butregion, uiBut *but,
const int win_y = WM_window_pixels_y(window);
// wm_window_get_size(window, &win_x, &win_y);
const int center_x = (block->direction & UI_DIR_CENTER_X) ? size_x / 2 : 0;
const int center_y = (block->direction & UI_DIR_CENTER_Y) ? size_y / 2 : 0;
/* check if there's space at all */
if (butrct.xmin - size_x > 0.0f) left = 1;
if (butrct.xmax + size_x < win_x) right = 1;
if (butrct.xmin - size_x + center_x > 0.0f) left = 1;
if (butrct.xmax + size_x - center_x < win_x) right = 1;
if (butrct.ymin - size_y + center_y > 0.0f) down = 1;
if (butrct.ymax + size_y - center_y < win_y) top = 1;
@ -193,8 +194,8 @@ static void ui_block_position(wmWindow *window, ARegion *butregion, uiBut *but,
}
else if (dir1 == UI_DIR_UP) {
offset_y = butrct.ymax - block->rect.ymin;
if (dir2 == UI_DIR_RIGHT) offset_x = butrct.xmax - block->rect.xmax;
else offset_x = butrct.xmin - block->rect.xmin;
if (dir2 == UI_DIR_RIGHT) offset_x = butrct.xmax - block->rect.xmax + center_x;
else offset_x = butrct.xmin - block->rect.xmin - center_x;
/* changed direction? */
if ((dir1 & block->direction) == 0) {
UI_block_order_flip(block);
@ -202,14 +203,19 @@ static void ui_block_position(wmWindow *window, ARegion *butregion, uiBut *but,
}
else if (dir1 == UI_DIR_DOWN) {
offset_y = butrct.ymin - block->rect.ymax;
if (dir2 == UI_DIR_RIGHT) offset_x = butrct.xmax - block->rect.xmax;
else offset_x = butrct.xmin - block->rect.xmin;
if (dir2 == UI_DIR_RIGHT) offset_x = butrct.xmax - block->rect.xmax + center_x;
else offset_x = butrct.xmin - block->rect.xmin - center_x;
/* changed direction? */
if ((dir1 & block->direction) == 0) {
UI_block_order_flip(block);
}
}
/* Center over popovers for eg. */
if (block->direction & UI_DIR_CENTER_X) {
offset_x += BLI_rctf_size_x(&butrct) / ((dir2 == UI_DIR_LEFT) ? 2 : - 2);
}
/* and now we handle the exception; no space below or to top */
if (top == 0 && down == 0) {
if (dir1 == UI_DIR_LEFT || dir1 == UI_DIR_RIGHT) {

View File

@ -4597,6 +4597,19 @@ void ui_draw_menu_back(uiStyle *UNUSED(style), uiBlock *block, rcti *rect)
}
}
void ui_draw_popover_back(uiStyle *UNUSED(style), uiBlock *block, rcti *rect)
{
uiWidgetType *wt = widget_type(UI_WTYPE_MENU_BACK);
wt->state(wt, 0);
if (block) {
wt->draw(&wt->wcol, rect, block->flag, block->direction);
}
else {
wt->draw(&wt->wcol, rect, 0, 0);
}
}
static void draw_disk_shaded(
float start, float angle,
float radius_int, float radius_ext, int subd,