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

Conversation

biglizards
Copy link

If a left facing popup button is in a scroll panel, the popup will be too far to the right (and in some cases cover up the button entirely) if that panel has been scrolled at all. This is (I think) because the scroll panel calls Popup::performLayout but not PopupButton::performLayout. In the PR, both functions set the anchor to the same (x) position, so that is no longer an issue.

Example (based on example_icons.cpp):

#include <nanogui/nanogui.h>

using namespace nanogui;

int main(int /* argc */, char ** /* argv */) {
    nanogui::init();

    {
        // create a fixed size screen with one window
        Screen *screen = new Screen({500, 400}, "Scroll Popup", false);
        Window *window = new Window(screen, "Scroll Popup");
        window->setPosition(Vector2i(200, 15));
        window->setLayout(new BoxLayout(Orientation::Horizontal,
Alignment::Middle, 0, 6));

        // attach a vertical scroll panel
        auto vscroll = new VScrollPanel(window);
        vscroll->setFixedSize({200, 100});

        // vscroll should only have *ONE* child. this is what `wrapper` is for
        auto wrapper = new Widget(vscroll);
        wrapper->setFixedSize({200, 100});
	    wrapper->setLayout(new GroupLayout());

        new Label(wrapper, "Padding", "sans-bold");

        // right side popups are in the right place
        PopupButton *popupBtn = new PopupButton(wrapper, "good popup");
        Popup *popup = popupBtn->popup();
        popup->setLayout(new GroupLayout());
        popupBtn->setSide(Popup::Side::Right);
        new Label(popup, "this works");

        // left side popups are also anchored to the right?
        popupBtn = new PopupButton(wrapper, "bad popup");
        popup = popupBtn->popup();
        popup->setLayout(new GroupLayout());
        popupBtn->setSide(Popup::Side::Left);
        new Label(popup, "this, I assume, doesnt work");

        screen->performLayout();
        screen->setVisible(true);

        nanogui::mainloop();
    }

    nanogui::shutdown();
    return 0;
}

also prevents issues if performLayout is called twice in a row
@biglizards biglizards changed the title [bug] fix left facing popup buttons in scroll panels fix left facing popup buttons in scroll panels May 30, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant