Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#4764: Better popup sizing and placement
- Loading branch information
1 parent
7555819
commit 70e32ff
Showing
4 changed files
with
64 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#pragma once | ||
|
||
#include <wx/popupwin.h> | ||
#include <wx/sizer.h> | ||
#include "MultiMonitor.h" | ||
|
||
namespace wxutil | ||
{ | ||
|
||
class TransientPopupWindow : | ||
public wxPopupTransientWindow | ||
{ | ||
public: | ||
TransientPopupWindow(wxWindow* parent) : | ||
wxPopupTransientWindow(parent, wxBORDER_DEFAULT) | ||
{ | ||
SetSizer(new wxBoxSizer(wxVERTICAL)); | ||
} | ||
|
||
// Attempts to position the popup to the right or left of the given window | ||
// The vertical offset is added to the screen position of the given window | ||
void PositionNextTo(wxWindow* win, int verticalOffset, const wxSize& size) | ||
{ | ||
auto rectScreen = MultiMonitor::getMonitorForWindow(win); | ||
|
||
SetSize(size); | ||
|
||
// Try right first | ||
auto rightTop = win->GetScreenRect().GetRightTop(); | ||
rightTop.y += verticalOffset; | ||
|
||
if (rightTop.x + size.GetWidth() < rectScreen.GetX() + rectScreen.GetWidth()) | ||
{ | ||
SetPosition(rightTop); | ||
return; | ||
} | ||
|
||
// Failed, place to the left | ||
auto leftTop = win->GetScreenRect().GetLeftTop(); | ||
leftTop.y += verticalOffset; | ||
|
||
if (leftTop.x - size.GetWidth() > rectScreen.GetX()) | ||
{ | ||
SetPosition(wxPoint(leftTop.x - size.GetWidth(), leftTop.y)); | ||
return; | ||
} | ||
|
||
// Fall back to the wxwidgets default algorithm | ||
Position(win->GetScreenPosition(), size); | ||
} | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters