Quote from: texus on 13 March 2019, 19:51:41
You should show the code you are using because it isn't the same as the example you quoted.
the issue with eHandler has been resolved.
sorry for bother you.
ps: nice lib. thnx.
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
Show posts MenuQuote from: texus on 13 March 2019, 19:51:41
You should show the code you are using because it isn't the same as the example you quoted.
Quote from: texus on 09 December 2015, 23:58:33
While writing the example I actually figured out that you can do it without any change in TGUI with exactly the same amount of lines of code:#include <TGUI/TGUI.hpp>
tgui::ListBox::Ptr popumMenu;
void popupMenuCallback(std::string item)
{
std::cout << item << std::endl;
}
void rightClickCallback(tgui::Gui& gui, sf::Vector2f position)
{
popumMenu = std::make_shared<tgui::ListBox>();
popumMenu->addItem("Option 1");
popumMenu->addItem("Option 2");
popumMenu->addItem("Option 3");
popumMenu->addItem("Option 4");
popumMenu->setItemHeight(20);
popumMenu->setPosition(position);
popumMenu->setSize(120, popumMenu->getItemHeight() * popumMenu->getItemCount());
popumMenu->connect("ItemSelected", popupMenuCallback);
gui.add(popumMenu);
}
int main()
{
sf::RenderWindow window(sf::VideoMode(800, 600), "TGUI window");
tgui::Gui gui(window);
gui.setFont("TGUI/fonts/DejaVuSans.ttf");
while(window.isOpen())
{
sf::Event event;
while(window.pollEvent(event))
{
if(event.type == sf::Event::Closed)
window.close();
// Check if there is a pop-up menu
if (popumMenu)
{
// When mouse is released, remove the pop-up menu
if (event.type == sf::Event::MouseButtonReleased && event.mouseButton.button == sf::Mouse::Left)
{
gui.remove(popumMenu);
popumMenu = nullptr;
}
// When mouse is pressed, remove the pop-up menu only when the mouse is not on top of the menu
if (event.type == sf::Event::MouseButtonPressed)
{
if (!popumMenu->mouseOnWidget(event.mouseButton.x, event.mouseButton.y))
{
gui.remove(popumMenu);
popumMenu = nullptr;
}
}
}
// Perhaps we have to open a menu
else if (event.type == sf::Event::MouseButtonPressed && event.mouseButton.button == sf::Mouse::Right)
{
rightClickCallback(gui, sf::Vector2f(event.mouseButton.x, event.mouseButton.y));
}
gui.handleEvent(event);
}
window.clear();
gui.draw();
window.display();
}
}
int pop_item=popumMenu->getSelectedItemIndex();
cout << " popUP item is " << pop_item << endl;