Button's text not showing when the button is in a panel

Started by Dexario, 14 June 2015, 13:56:18

Dexario

Hi,

I am making a program using tgui. So far, everything was working fine. I am now trying to implement a scrollable panel, like in this example https://tgui.eu/example-code/v06/scrollable-panel/ (I use widgets instead of pics). It works fine except for the fact that the text in the buttons isn't being displayed. Screenshot here:



As you can see, the other buttons work fine but not those that are in the scrollable panel.

Here is the code that inits the panel and the two buttons that are in it:

Code (cpp) Select
//Create the panel
m_panel->setPosition(0, 0);
m_panel->setSize(300, 400);
m_panel->setBackgroundColor(sf::Color(200, 200, 200));

//Add some widgets to it
        //Button ok
m_b_ok->load(THEME_CONFIG_FILE);
m_b_ok->setSize(130, 30);
m_b_ok->setPosition(0, 0);
m_b_ok->setText("Ok");
m_panel->add(m_b_ok);

        //Button cancel
m_b_cancel->load(THEME_CONFIG_FILE);
m_b_cancel->setSize(130, 30);
m_b_cancel->setPosition(0, 40);
m_b_cancel->setText("Cancel");
m_panel->add(m_b_cancel);

//Add the scrollbar
m_scrollbar->load(THEME_CONFIG_FILE);
m_scrollbar->setSize(20, 400);
m_scrollbar->setPosition(m_panel->getPosition() + sf::Vector2f(m_panel->getSize().x, 0));
m_scrollbar->setArrowScrollAmount(30);
m_scrollbar->setLowValue(360); // Viewable area (height of the panel)
m_scrollbar->setMaximum(5 * 180); // Total area (height of the 5 images)

// Call the scrollPanel function that we defined above when scrolling
m_scrollbar->bindCallback(&NewObjectDialog::ScrollPanel, this, tgui::Scrollbar::ValueChanged);

m_win->add(m_panel);
m_win->add(m_scrollbar);


m_win is the child window in which these widgets are.

Also, if we look back at the screenshot, we can see that the widgets that are in the panel aren't hidden when they get out of it (I don't know if this is a normal behaviour since it's supposed to be a static panel).

Thanks.

texus

Quotewe can see that the widgets that are in the panel aren't hidden when they get out of it
This is not supposed to happen, so lets focus on fixing this and then see if the problem with the invisible text still persists.

If you look at my example codes, I never call the add functions. The most important line is actually not being shown in your code: the way the widget is created. If you initialize it with the m_win object then they will immediately be added to the gui. You have to initialize them with "*m_panel". Only when you don't pass any parent, then you have to call the add function to add it somewhere later.

I suspect that you created the buttons being inside the Gui, and then you added them to the Panel. That could explain why the buttons are still visible. Its possible that I am completely wrong about this, but you should show some more code then. If you would have a minimal code example inside a main function that I can just copy-paste then I can usually find the problem really fast.

Dexario

I changed the initialisations of the widgets because they used to use the default constructors:
Code (cpp) Select
tgui::Button::Ptr()

So I changed it to:

Code (cpp) Select
//Create the panel
m_panel = tgui::Panel::Ptr(*m_win);
m_panel->setPosition(0, 0);
m_panel->setSize(300, 400);
m_panel->setBackgroundColor(sf::Color(200, 200, 200));

//Add some widgets to it
m_b_ok = tgui::Button::Ptr(*m_panel);
m_b_ok->load(THEME_CONFIG_FILE);
m_b_ok->setSize(130, 30);
m_b_ok->setPosition(0, 0);
m_b_ok->setText("Ok");
//m_panel->add(m_b_ok);

m_b_cancel = tgui::Button::Ptr(*m_panel);
m_b_cancel->load(THEME_CONFIG_FILE);
m_b_cancel->setSize(130, 30);
m_b_cancel->setPosition(0, 40);
m_b_cancel->setText("Cancel");
//m_panel->add(m_b_cancel);

//Add the scrollbar
m_scrollbar = tgui::Scrollbar::Ptr(*m_win);
m_scrollbar->load(THEME_CONFIG_FILE);
m_scrollbar->setSize(20, 400);
m_scrollbar->setPosition(m_panel->getPosition() + sf::Vector2f(m_panel->getSize().x, 0));
m_scrollbar->setArrowScrollAmount(30);
m_scrollbar->setLowValue(360); // Viewable area (height of the panel)
m_scrollbar->setMaximum(400); // Total area (height of the 5 images)

// Call the scrollPanel function that we defined above when scrolling
m_scrollbar->bindCallback(&NewObjectDialog::ScrollPanel, this, tgui::Scrollbar::ValueChanged);


I also got rid of all the "->add".

The text problem is now fixed but not the problem where the buttons aren't hidden:



Thanks.

texus

Are you drawing anything directly with sfml?

If not, could you create some code that I can run here? Because this is a really strange bug and I don't think I will be able to solve it without debugging.

Dexario

Here is the code: https://puu.sh/iosxw/d67636b3bb.zip

You will find to projects:
    -Isolated files: contains only the most important files from the full project
    -full project

I am sorry I was not able to provide an executable because I was guessing you use Linux and I don't know how to compile for Linux using Windows.

I found an interesting fact: if you look at isolated files project -> NewObjectDialog, you will see that there is also a canvas. I noticed that if you delete that code:

Code (cpp) Select
void NewObjectDialog::Display(sf::RenderWindow *w)
{
m_canvas->clear(sf::Color(80, 80, 80));
m_canvas->draw(*m_image);
}


The widgets will be hidden. The weird thing is that if I do the same in the full project, the widgets will not be hidden, even though the NewObjectDialog files are the same.

texus

Since you are using a Canvas on which you draw with sfml I think I already know what the issue is going to be.
An issue was reported not so long ago but I didn't fix it because I thought the chance that someone else would run into an identical situation was like one in a billion.

Try with adding window.resetGLStates() right before gui.draw.

I'll be trying to set up the project in the meantime in case that doesn't help.

QuoteI was not able to provide an executable because I was guessing you use Linux
You guessed right :). Even if you added a .exe which I could run with wine, I wouldn't be able to do anything with it anyway since I need the code to make small changes and test stuff.

Dexario


texus

I'll fix this in the next patch release then. The problem only occurs when drawing to a sf::RenderTexture (which Canvas uses) right before calling gui.draw. If that "dialog.Display(&win);" would be anywhere else (e.g. before the win.clear) or if there would be another draw call in between it then it wouldn't have caused troubles.

Btw, your project uses backslashes in the includes which prevents it from working on non-windows systems. Using normal slashes makes it cross-platform.