Recent Posts

Pages: [1] 2 3 ... 10
1
Help requests / Re: Grid
« Last post by nolimitee on 14 March 2019, 20:59:46 »
Ok, yeah for the instance I showed with only the grid in it, but in my program I have more than one :)

So I tested with the fix and it works great, thanks for your support !
2
Help requests / Re: Grid
« Last post by texus on 14 March 2019, 20:02:53 »
VerticalLayout spreads the entire height among all widgets inside it, in this case just the Grid. So the height of the VerticalLayout (100% of parent by default) will be passed to the Grid. So you can just limit the height of the vertical layout:
verticalLayout_->setSize("100%", 150);

But if you are only putting 1 widget in VerticalLayout then you don't need it and you can just add the Grid directly to the container and call that setSize function on the grid widget.
3
Help requests / Re: Grid
« Last post by nolimitee on 14 March 2019, 19:54:59 »
Ok thanks for your answer, i will check it out very soon.

Is there a way to compact the widgets in the upper left corner with that layout ? With tgui::Grid::Alignement::UpperLeft when using addWidget() maybe ?
I would like to have something organized like this : (6.png).
4
Help requests / Re: Grid
« Last post by texus on 14 March 2019, 19:35:02 »
All your images are wrong for that given code actually, including 5elm-5pr.jpg.
The VerticalLayout will tell the grid what it's size should be. When a Grid is given a size, it will rearrange the widgets to fill this space. This rearrangement was broken, which caused the weird results, but even with only one line there should be space between the widgets to fill the entire width.

6elm-5pr-without-verticallayout.jpg doesn't have any extra space between the widgets because it is auto-sizing (the size of the grid is determined by the widgets inside it, as the grid wasn't given a size).

In my opinion the result of your code should be similar to my attached screenshots. I didn't write the code that adds spaces between the widgets to fill the size though, so feel free to propose alternatives if you believe it should look different.

You can download the code with the fix in Grid on github.
5
Help requests / Re: ComboBox and State pattern
« Last post by Maksat on 14 March 2019, 09:44:02 »
Thank you!
6
Help requests / Grid
« Last post by nolimitee on 14 March 2019, 09:39:20 »
Hello,

I'm currently trying to use Grid but I'm facing weird behavior.

The spacing between my widgets in the grid are way too important if I'm trying to create more than one row. So, my widgets are overflowing my parent container.
The grid is in vertical layout, and the vertical layout is in a Group::Ptr.

I've took multiple screenshots :

Screen with 5 widgets, 5 per row : "5elm-5pr.jpg"
Screen with 6 widgets, 5 per row : "6elm-5pr.jpg"
Screen with 12 widgets, 5 per row : "12elm-5pr.jpg"

And here is the code :

        container_ = tgui::Group::create({ "30%", "100% " });
        container_->setPosition({ "70%", "0%" });

        verticalLayout_ = tgui::VerticalLayout::create();

        tgui::Button::Ptr button = tgui::Button::create("");
        button->getRenderer()->setTexture(ResourceManager::GetInstance().getTextureByName("panel"));
        button->setSize(75, 75);

        grid_ = tgui::Grid::create();

        for (int i = 0; i < 12; ++i) {
                tgui::Button::Ptr butt = tgui::Button::copy(button);
                grid_->addWidget(butt, i / 5, i % 5);
        }

        verticalLayout_->add(grid_);

        container_->add(verticalLayout_);

        Gui.add(container_);
 

As you can see, the "5elm-5pr.jpg" is ok because the row number is always equals to "0". But when I'm trying to create more than row (e.g "6elm-5pr.jpg"), everything explodes.

Am i missing something ?

Thanks

EDIT :

I found out that this problem occurs only when the grid is in the vertical layout (c.f . 6elm-5pr-without-verticallayout.jpg").
But I would like to keep that layout. Is there a solution to compact the grid when it used in the layout ?
7
Feature requests / Re: Resizable Child Windows/Right-Click Menu
« Last post by serhio 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.
8
Feature requests / Re: Resizable Child Windows/Right-Click Menu
« Last post by 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.
9
Help requests / Re: ComboBox and State pattern
« Last post by texus on 13 March 2019, 19:44:50 »
Using multiple Gui objects is not recommended at all, but I didn't fully understand what you meant and I was thinking the issue had to do with how events were sent.

I don't think it was possible yet to select a different item by holding the mouse in ListBox (which ComboBox uses internally) when the code was originally written like this in ComboBox. So this issue only appeared after an "unrelated" change in ListBox.

I've looked at how combo boxes work on my linux and a windows pc and they indeed only changes the value when the mouse is released. So I have updated my code to do the same. You can find the new version on github.
10
Feature requests / Re: Resizable Child Windows/Right-Click Menu
« Last post by serhio 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] 2 3 ... 10