[SOLVED][0.7] tgui::bindWidth doesn't work with menu

Started by cpl.bator, 03 December 2014, 16:08:18

cpl.bator

with this code :
auto menu = tgui::MenuBar::create(THEME);
menu->setSize(tgui::bindWidth(mGui.getContainer())*0.5, 22); // Half size ?? 
    menu->addMenu("Fichier");
    menu->addMenuItem("Fichier", "Importer image");
    menu->addMenuItem("Fichier", "Enregistrer");
    menu->addMenuItem("Fichier", "Enregistrer sous...");
    menu->addMenuItem("Fichier", "Quitter");
menu->addMenu("Affichage");
    menu->addMenuItem("Affichage", "Basculer en plein écran");
menu->connectEx("MenuItemClicked", &Application::OnMenuClick,this );
    mGui.add(menu);


and inside my run method :

sf::Event event;
while (mWindow.pollEvent(event))
{

// window closed
if (event.type == sf::Event::Closed)
{
mWindow.close();
mRun = false;
}

// window resized
if (event.type == sf::Event::Resized)
{
mWindowSize.x = event.size.width;
mWindowSize.y = event.size.height;
mGui.setView(sf::View{{0, 0, (float)event.size.width, (float)event.size.height}});
}

mGui.handleEvent(event);
}


the menu is not streched  , but is not resized at the desired value.

texus

This seems to be a bug.
I'll see if I can find what is causing this exactly.

Btw, tgui::bindWidth(mGui.getContainer()) can also be written as tgui::bindWidth(mGui).

texus

I found the problem.

When you add the menu to the gui, it is given the width of the gui. This was done so that you didn't have to specify a width for the menu bar as it would just fill the whole width.

I'll fix it so that it will only give the menu bar a width when the width has not yet manually been set (ie different from 0).

But in the meantime just call the setSize function after the mGui.add(menu) line, that will make the code work.

cpl.bator