Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix left facing popup buttons in scroll panels #409

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/nanogui/popup.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class NANOGUI_EXPORT Popup : public Window {
protected:
Window *mParentWindow;
Vector2i mAnchorPos;
Vector2i pPos;
int mAnchorHeight;
Side mSide;
public:
Expand Down
12 changes: 9 additions & 3 deletions src/popup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
BSD-style license that can be found in the LICENSE.txt file.
*/

#include <nanogui/screen.h>
#include <nanogui/popup.h>
#include <nanogui/theme.h>
#include <nanogui/opengl.h>
Expand All @@ -31,13 +32,18 @@ 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() {
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) {
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/popupbutton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down