v0.7 scrollbar within child window
« on: 26 April 2016, 05:46:59 »
I'm having trouble getting a scrollbar to appear when adding it to a child window container.
In drawStartTurnSummarySubMenu, I create the child window with the setupChildWindow method.
I then try to add a scrollbar to the child window using setupScrollBarHorz and passing the child window as a container.
I can see that the number of widgets in the child window increases when I add the scrollbar but it never appears. (Note I put autohide to false).
However if I change the line in setupScrollBarHorz

container->add(scrollbar, scrollBarName);
 

To the below, the scollbar appears.
//gui.add(scrollbar, scrollBarName);
 

However if I move the childwindow the position of the scrollbar doesn't move. Basically I want the scrollbar to control widgets inside a panel which inside a child window. Here are the methods in question.


void Test::drawStartTurnSummarySubMenu()
{
        sf::Vector2i pos(gameWindow.getSize().x * 0.1, gameWindow.getSize().y * 0);
        sf::Vector2i size((gameWindow.getSize().x - (gameWindow.getSize().x * 0.25)), gameWindow.getSize().y * 0.750);

        setupChildWindow(pos, size, "Start Turn Summary", sf::Color::Red, "startTurn");
        tgui::Container::Ptr container = gui.get<tgui::Container>("startTurn");
       
        pos = sf::Vector2i(0, 0);
        void (Test::*ptrToMember)(const tgui::Callback&) = NULL; // creating function ptr
        ptrToMember = &Test::scrollBarHorzSignalFunction; // assigning function ptr to appropraite function

        setupScrollBarHorz("regionPanelScrollHorz", ptrToMember, container);

        //clear game window
        gameWindow.clear();

        gui.draw();
        gameWindow.display();
}

void Test::setupChildWindow(sf::Vector2i pos, sf::Vector2i size, string title_text, sf::Color titleText_Color, string passed_childName)
{
        if (gui.get(passed_childName) == NULL)
        {
                tgui::ChildWindow::Ptr childWin = theme->load("ChildWindow");
                childWin->setPosition(pos.x, pos.y);
                childWin->setSize(size.x, size.y);
                childWin->getRenderer()->setTitleColor(titleText_Color);
                childWin->setTitle(title_text);
                gui.add(childWin, passed_childName);
        }
}

bool Test::setupScrollBarHorz(string scrollBarName, void (Test::*ptrToMember)(const tgui::Callback&),tgui::Container::Ptr container)
{
        if ((container != NULL && container->get(scrollBarName) == NULL) || (container == NULL && gui.get(scrollBarName) == NULL))
        {
                tgui::Scrollbar::Ptr scrollbar = theme->load("Scrollbar");
                scrollbar->setPosition(container->getPosition() + sf::Vector2f(container->getSize().x, 0));
                scrollbar->setSize(20, container->getSize().y);
                scrollbar->connectEx("ValueChanged", ptrToMember, this);
                scrollbar->setAutoHide(false);
                container->add(scrollbar, scrollBarName);
                //gui.add(scrollbar, scrollBarName);
                return true;
        }
        else
        {
                return false;
        }
}

void Test::scrollBarHorzSignalFunction(const tgui::Callback& callback)
{
        int scrollbarMove = callback.value;
}
 

*

texus

  • *****
  • 1143
    • View Profile
    • Texus's Blog
Re: v0.7 scrollbar within child window
« Reply #1 on: 26 April 2016, 08:42:30 »
If you add the scrollbar to the container with container->add then its position is relative to the container, so "scrollbar->setPosition(container->getPosition() + sf::Vector2f(container->getSize().x, 0));" should be "scrollbar->setPosition(sf::Vector2f(container->getSize().x - scrollbar->getSize().x, 0));" to avoid it from being outside the visible part of the container.

Re: v0.7 scrollbar within child window
« Reply #2 on: 26 April 2016, 23:51:01 »
argghhh - thank you.