From 8b354af8febf16c3a9696a21351a260f35582007 Mon Sep 17 00:00:00 2001 From: biglizards <22501070+biglizards@users.noreply.github.com> Date: Thu, 30 May 2019 16:46:51 +0100 Subject: [PATCH 1/4] use absolute anchor instead of relative also prevents issues if performLayout is called twice in a row --- src/popup.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/popup.cpp b/src/popup.cpp index 4cf416c457..9f20077d99 100644 --- a/src/popup.cpp +++ b/src/popup.cpp @@ -31,7 +31,7 @@ void Popup::performLayout(NVGcontext *ctx) { mChildren[0]->performLayout(ctx); } if (mSide == Side::Left) - mAnchorPos[0] -= size()[0]; + mAnchorPos[0] = -15 - size()[0]; } void Popup::refreshRelativePlacement() { From d670681062f3cef2d8f947d225cce1a4492206a8 Mon Sep 17 00:00:00 2001 From: biglizards <22501070+biglizards@users.noreply.github.com> Date: Thu, 30 May 2019 16:47:32 +0100 Subject: [PATCH 2/4] Update popupbutton.cpp --- src/popupbutton.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/popupbutton.cpp b/src/popupbutton.cpp index f8ff92474f..3bac4ea32d 100644 --- a/src/popupbutton.cpp +++ b/src/popupbutton.cpp @@ -77,7 +77,7 @@ void PopupButton::performLayout(NVGcontext *ctx) { if (mPopup->side() == Popup::Right) mPopup->setAnchorPos(Vector2i(parentWindow->width() + 15, posY)); else - mPopup->setAnchorPos(Vector2i(0 - 15, posY)); + mPopup->setAnchorPos(Vector2i(0 - 15 - mPopup->size()[0], posY)); } void PopupButton::setSide(Popup::Side side) { From c7e4d2bf83f76739aab9f7c5b7285b2c0d5ae187 Mon Sep 17 00:00:00 2001 From: biglizards <22501070+biglizards@users.noreply.github.com> Date: Thu, 5 Dec 2019 16:28:52 +0000 Subject: [PATCH 3/4] Reposition a popup widget when it extends beyond the screen size --- include/nanogui/popup.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/nanogui/popup.h b/include/nanogui/popup.h index 9f4b1fb393..016efc6938 100644 --- a/include/nanogui/popup.h +++ b/include/nanogui/popup.h @@ -67,6 +67,7 @@ class NANOGUI_EXPORT Popup : public Window { protected: Window *mParentWindow; Vector2i mAnchorPos; + Vector2i pPos; int mAnchorHeight; Side mSide; public: From 26ab679947e75b5eafc7d12bfaf14f150306ae5d Mon Sep 17 00:00:00 2001 From: biglizards <22501070+biglizards@users.noreply.github.com> Date: Thu, 5 Dec 2019 16:30:26 +0000 Subject: [PATCH 4/4] Reposition a popup widget when it extends beyond the screen size --- src/popup.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/popup.cpp b/src/popup.cpp index 9f20077d99..cb2e2371a6 100644 --- a/src/popup.cpp +++ b/src/popup.cpp @@ -10,6 +10,7 @@ BSD-style license that can be found in the LICENSE.txt file. */ +#include #include #include #include @@ -37,7 +38,12 @@ void Popup::performLayout(NVGcontext *ctx) { void Popup::refreshRelativePlacement() { mParentWindow->refreshRelativePlacement(); mVisible &= mParentWindow->visibleRecursive(); - mPos = mParentWindow->position() + mAnchorPos - Vector2i(0, mAnchorHeight); + pPos = mParentWindow->position() + mAnchorPos - Vector2i(0, mAnchorHeight); + + const Screen* screen = this->screen(); + assert(screen); + mPos = pPos.cwiseMax(Vector2i::Zero()); + mPos = mPos.cwiseMin(screen->size() - mSize); } void Popup::draw(NVGcontext* ctx) { @@ -67,7 +73,7 @@ void Popup::draw(NVGcontext* ctx) { nvgBeginPath(ctx); nvgRoundedRect(ctx, mPos.x(), mPos.y(), mSize.x(), mSize.y(), cr); - Vector2i base = mPos + Vector2i(0, mAnchorHeight); + Vector2i base = pPos + Vector2i(0, mAnchorHeight); int sign = -1; if (mSide == Side::Left) { base.x() += mSize.x();