Show Posts

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.


Messages - serhio

Pages: [1]
1
Feature requests / Re: Resizable Child Windows/Right-Click Menu
« on: 13 March 2019, 20:15:54 »
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.

2
Feature requests / Re: Resizable Child Windows/Right-Click Menu
« on: 13 March 2019, 09:38:58 »
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();
    }
}

hello all

i'm unable to get

Code: [Select]
int pop_item=popumMenu->getSelectedItemIndex();                   
cout << " popUP item is " << pop_item << endl;

pop_item is always -1

Debian stable 32 bit
sfml 2.4.1
tgui 0.8.4

thnx


Pages: [1]