diff options
author | Campbell Barton <ideasman42@gmail.com> | 2018-04-22 23:08:48 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2018-04-22 23:13:26 +0300 |
commit | 62cd5e0b7bf151c757c5607b5081ba677b5240a4 (patch) | |
tree | 48a0b844fbdf5b19320a4af1de0ac35ca7c372a9 /source/blender/editors/interface/interface_region_popup.c | |
parent | 46375b8e03b7ac841af4d3cb16eb1561f959bdb7 (diff) |
UI: support for center popovers over buttons
Diffstat (limited to 'source/blender/editors/interface/interface_region_popup.c')
-rw-r--r-- | source/blender/editors/interface/interface_region_popup.c | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/source/blender/editors/interface/interface_region_popup.c b/source/blender/editors/interface/interface_region_popup.c index 540ef79f08e..b13d9b0448c 100644 --- a/source/blender/editors/interface/interface_region_popup.c +++ b/source/blender/editors/interface/interface_region_popup.c @@ -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) { |