Recent Posts

Pages: [1] 2 3 ... 10
1
Help requests / Re: Incorporating a form file into a release .exe
« Last post by texus on 13 February 2020, 08:42:04 »
If the form is stored as a resource in the exe (which is Windows-specific) then you need to load it, get its contents in a string, put this string into an std::stringstream and pass this stringstream to gui.loadWidgetsFromFile.
You can't store your themes in resources without writing your own theme loader though, so you won't be able to easily put everything inside your exe.
2
Help requests / Incorporating a form file into a release .exe
« Last post by lurquer on 13 February 2020, 00:49:17 »
Great library, Tex. Can't say enough about it.

Question: I have a big ol' project with a gui created using the form builder. I want to package it all up into an .exe I can share. Will I always need the form file to go along with it? Or, is there some way (short of doing it manually in my code) to get the form into my .exe.
I'm using C++ with Visual Studio 2019.
Thanks.
3
Help requests / Re: Highlighting Keywords
« Last post by Kvaz1r on 31 January 2020, 21:33:33 »
As for Q2.
You could easily extend standard widget that it will fits your needs. 
For example so(here I just added custom callback for onEnterPressed):

Code: [Select]
#include <TGUI/TGUI.hpp>
#include <iostream>
#include <functional>

template<typename Func>
class MyEditBox : public tgui::EditBox
{
public:
    using Ptr = std::shared_ptr<MyEditBox<Func>> ; ///< Shared widget pointer

    MyEditBox(Func f) : tgui::EditBox() , m_callback(f) {}

    static Ptr create(Func f)
    {
        return std::make_shared<MyEditBox>(f);
    }

    void keyPressed(const sf::Event::KeyEvent& event) override
    {
        if (event.code == sf::Keyboard::Enter)
        {
            m_callback();
        }
        EditBox::keyPressed(event);
    }

private:
    Func m_callback;
};

class MyFrame
{
public:
    MyFrame()
    {
        window.create(sf::VideoMode(800, 600), "TGUI window");
        gui.setTarget(window);
        //you could activate here callback for button with usual connect
        //in runtime
        //and disconnect it after
        //or use bool variable as flag
        auto onEnter = []()
        {
            std::cout << "Entered was pressed";
        };
        auto edit = MyEditBox<decltype(onEnter)>::create(onEnter);

        gui.add(edit);
    }
    void main()
    {
        while (window.isOpen())
        {
            sf::Event event;
            while (window.pollEvent(event))
            {
                if (event.type == sf::Event::Closed)
                    window.close();
                gui.handleEvent(event);
            }
            window.clear();
            gui.draw();
            window.display();
        }
    }

private:
    sf::RenderWindow window;
    tgui::Gui gui;
};

int main()
{
    MyFrame().main();
}

Another option for anti-spam would be usual Timer that runs and made "Send" button enabled only after timeout. And handler for "pressed" signal made button disabled after sending a message.

Or, for example, all messages writes to internal buffer first and it flushed by timer.

Well there are really many ways to do it ;-)
4
Help requests / Re: Highlighting Keywords
« Last post by texus on 31 January 2020, 18:36:08 »
It's currently not possible to have multiple text colors on the same line. It also won't be added anywhere soon (unless someone were to contribute it).

Next time the signal system gets a rewrite I will try to implement a way to trigger signals from another widget, but it currently isn't possible. But can't you simply bind the same function for both the edit box and button?
void func()
{
  [If edit box contains something, add a line to chatbox]

  editBox-> setText("");
  editBox->setFocused(true); // In case the user clicked on the button
}

button->connect("pressed", &func);
editBox->connect("ReturnKeyPressed", &func);
5
Help requests / Re: Combobox signal
« Last post by roccio on 30 January 2020, 09:33:22 »
Will try asap. I have just downloaded the last binary from the Download section (0.8.6).

Thank you
6
Help requests / Re: Combobox signal
« Last post by Kvaz1r on 30 January 2020, 09:31:45 »
Code works well for me.
Could you rebuild TGUI with current master and check it again? This commit seems related to your issue.
7
Help requests / Re: Combobox signal
« Last post by roccio on 30 January 2020, 09:22:36 »
With this I get no exception, but the value printed are not the one expected.

Code: [Select]
void ChangeColor(int val)
{
std::cout << val << std::endl;
}

int main()
{
sf::RenderWindow window(sf::VideoMode(SCREEN_W, SCREEN_H), "Aircraft configurator", sf::Style::Close);
window.setIcon(icon_image.width, icon_image.height, icon_image.pixel_data);

// init gui
tgui::Gui gui;
gui.setTarget(window);

tgui::ComboBox::Ptr combo = tgui::ComboBox::create();
combo->setPosition(100, 100);
combo->addItem("One");
combo->addItem("Two");
combo->connect("ItemSelected", ChangeColor);
gui.add(combo);

while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
switch (event.type)
{
case sf::Event::Closed: window.close(); break;
}

gui.handleEvent(event);
}

window.clear(sf::Color::White);

gui.draw();

window.display();
}

return 0;
}
8
Help requests / Re: Combobox signal
« Last post by Kvaz1r on 30 January 2020, 09:16:10 »
Could you provide minimal reproducible example?
9
Help requests / Combobox signal
« Last post by roccio on 30 January 2020, 08:56:08 »
Hi,
I have a combox and I want to connect a function on itemselected that pass the index of the selected item and not the text.

void ChangeColor(int index) { std::cout << index; std::endl;}

...

g_comboColor->connect("ItemSelected", ChangeColor);


This compiles well, but when I run the code I get an exception in SignalImpl.hll

const std::size_t offset = (sizeof...(UnboundArgs) > 0) ? signal.validateTypes({typeid(UnboundArgs)...}) : 0; (line 157)

What am I missing?
10
Help requests / Highlighting Keywords
« Last post by RamblingBaba on 29 January 2020, 03:25:39 »
I'm just messing around with TGUI and getting familiar with it. I'm just making a mock chat room and I was wondering if there is a way to have multiple colors on one line?
For example:

RamblingBaba: Hello, World.

And have the username color (say Red) and the message a different color (say Green).

I'm assuming there may be a way that isn't very apparent. I was messing with the index function, but I always came back to realizing there is only addline() and I couldn't figure out a way to emulate it.

Question 2
I was having a problem with the timing of pressing enter (so it doesn't spam the message). Frame management seemed to be ignored. I managed to get it working nicely, but I came across a question? I have a button that can be used to send the message from the edit box to the chatbox. Is there a way to activate the buttons connect callback without actually doing the command "pressed". I was basically looking for like an activate(true) method or something similar. I did "Focused" which was a guessing game to find what is required (tried 'up, keyup, released, etc..'). So I would type a message, press enter (didn't understand onReturnKeyPressed since it's not a bool), focus to the send button, which automatically activates the callback lambda on the button to send the edit box text to the chatbox, clear the edit box, and focus back to the edit box.

And question 2.5 is there a way to do that process quicker or perhaps more efficient?

Thanks!
Pages: [1] 2 3 ... 10