Main Menu
Menu

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.

Show posts Menu

Messages - Kvaz1r

#76
It would be great to have opportunity handle click on header cells. For example for sorting some data. 
#77
Help requests / Re: Function signatures
03 September 2019, 12:53:50
There is std::function<> in modern C++. Of course there are also could be some templates tricks for works with variadic arguments but in base it's std::function.
#78
Feature requests / OpenFile{Folder}Dialog
31 August 2019, 19:36:27
A control{s} to select a file{directory} path. Sometimes it's called as File{Dir}Picker but more popular name is OpenFile{Folder}Dialog.
#79
right, it's indeed works, thank you.
#80
Is it possible to set position for widgets inside grid to keep it straight(i.e. on one row/column)?
When there is only one column better don't use grid at all, but it should be possible for multiple columns.

MCVE:

#include <TGUI/TGUI.hpp>
#include <random>
#include <string>

std::string random_str()
{
std::string str("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz");

std::random_device rd;
std::mt19937 gen(rd());
std::uniform_int_distribution<> dis(0, 32);
std::shuffle(str.begin(), str.end(), gen);
return str.substr(0, dis(gen));
}

int main()
{
sf::RenderWindow window(sf::VideoMode(800, 600), "TGUI window");
tgui::Gui gui(window);
auto panel = tgui::ScrollablePanel::create();
auto grid = tgui::Grid::create();

for (std::size_t i = 0; i < 20; i++)
{
auto cbox = tgui::Label::create(random_str());
//panel->add(cbox, std::to_string(i));
grid->addWidget(cbox, i, 0);
if (i != 0)
{
auto prev = grid->getWidget(i - 1, 0);
//auto prev = panel->get(std::to_string(i - 1));//works without grid
if (prev != nullptr)
{
cbox->setPosition({ tgui::bindLeft(prev), tgui::bindBottom(prev) });
}
}
}

panel->add(grid);
gui.add(panel);
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();

gui.handleEvent(event); // Pass the event to the widgets
}

window.clear();
gui.draw(); // Draw all widgets
window.display();
}
}


P.S. I read this topic but it's didn't help  :)
#81
O, now I see. Silly mistake, thank you.
#82
I want to create a MessageBox on menu click and close it via Cancel button. But calling close in ButtonPressed handler cause a crash. How it to do correctly?

MCVE:

#include <TGUI/TGUI.hpp>
#include <iostream>

static auto Edit = L"Edit";

int main()
{
sf::RenderWindow window(sf::VideoMode(800, 600), "TGUI window");
tgui::Gui gui(window);
tgui::MenuBar::Ptr menuBar = tgui::MenuBar::create();

menuBar->addMenu(Edit);
menuBar->addMenuItem(Edit, L"Apply");
menuBar->connectMenuItem({ Edit, L"Apply" }, [&gui]
{
auto ptr = tgui::MessageBox::create("Title", "Some warning", { "OK", "Cancel" });
gui.add(ptr);
ptr->connect("ButtonPressed", [&](const std::string& button)
{
if (button == "OK")
{
std::cout << "OK\n";
}
else if (button == "Cancel")
{
ptr->close();
}
});
});

gui.add(menuBar);

menuBar->moveToFront();
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();

gui.handleEvent(event); // Pass the event to the widgets
}

window.clear();
gui.draw(); // Draw all widgets
window.display();
}
}
#83
Help requests / Re: how to use builder tool
23 August 2019, 13:31:08
You can load widgets from file:
gui.loadWidgetsFromFile("form.txt");
#84
Thanks it works, I didn't know about group. I looking through tutorials and examples but didn't found anything related to it. When one should use group and not just layouts?

I tried set position only for layout without using group and this works too.   
#85
Help requests / Menubar overlap with layout.
21 August 2019, 12:58:33
I can't found a way to insert space between menu bar and panel with other widgets because without it they overlapped. How to do it correctly?

MCVE:

#include <TGUI/TGUI.hpp>

static auto File = "File";

int main()
{
sf::RenderWindow window(sf::VideoMode(400, 300), "TGUI window");
tgui::Gui gui(window);
auto topLayout = tgui::VerticalLayout::create();
auto panel = tgui::ScrollablePanel::create();
auto grid = tgui::Grid::create();

tgui::MenuBar::Ptr menuBar = tgui::MenuBar::create();
menuBar->addMenu(File);
menuBar->addMenuItem(File, L"New");
menuBar->addMenuItem(File, L"Open");
gui.add(menuBar);
auto box = tgui::CheckBox::create("0");
grid->addWidget(box, 0, 0);
auto box2 = tgui::CheckBox::create("1");
grid->addWidget(box2, 1, 0);
panel->add(grid);
gui.add(grid);
topLayout->add(panel);
gui.add(topLayout);
menuBar->moveToFront();
// Main loop
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();

gui.handleEvent(event); // Pass the event to the widgets
}
window.clear();
gui.draw(); // Draw all widgets
window.display();
}
}
#86
Yes, I'm used to menu bars that separate from frame so idea put it to layout was attempted make it works. At begin I didn't use layout at all and there was my mistake.

Yeah moveToFront works well, thanks for answer.
#87
Menu items don't show when I press on a menu. Menubar is added into layout. Is this expected behaviour or bug? If it's first case - how to fix?

MCVE:

#include <TGUI/TGUI.hpp>

int main()
{
sf::RenderWindow window(sf::VideoMode(800, 600), "TGUI window");
tgui::Gui gui(window);
auto topLayout = tgui::VerticalLayout::create();
topLayout->setSize("100%", "10%");

tgui::MenuBar::Ptr menuBar = tgui::MenuBar::create();
menuBar->addMenu("File");
menuBar->addMenuItem("File", "New");

topLayout->add(menuBar);
topLayout->add(tgui::Button::create("Button"));
gui.add(topLayout);

while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();

gui.handleEvent(event); // Pass the event to the widgets
}

window.clear();
gui.draw(); // Draw all widgets
window.display();
}
}
#88
It's a very common controls so it would be great have opportunity use them from builder.
#89
Can you provide MCVE (Minimal Complete Verifiable Example) for reproducing the behaviour?