GithubHelp home page GithubHelp logo

Comments (8)

texus avatar texus commented on May 31, 2024

As explained on the forum, the default Black style doesn't has focused images.
But after adding the FocusedImage option in the config file, does this code work?
The code below works fine for me, so if it works for you as well then you should write small piece of code to reproduce the problem.

#include <TGUI/TGUI.hpp>

int main()
{
    sf::RenderWindow window(sf::VideoMode(930, 700), "TGUI window");
    tgui::Gui gui(window);

    if (gui.setGlobalFont("TGUI/fonts/DejaVuSans.ttf") == false)
        return 1;

    tgui::Button::Ptr button(gui);
    button->load("TGUI/widgets/Black.conf");
    button->setPosition(40, 25);
    button->setText("Quit");
    button->setCallbackId(1);
    button->bindCallback(tgui::Button::LeftMouseClicked | tgui::Button::SpaceKeyPressed | tgui::Button::ReturnKeyPressed);
    button->setSize(300, 40);

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

            gui.handleEvent(event);
        }

        tgui::Callback callback;
        while (gui.pollCallback(callback))
        {
            std::cout << "CALLBACK" << std::endl;
        }

        window.clear();
        gui.draw();
        window.display();
    }

    return 0;
}

from tgui.

heinrichheinsson avatar heinrichheinsson commented on May 31, 2024

No, your code doesn't work still. Minimum code required is the same code as yours minus the "leftMouseClicked". leftMouse trigger I get, but the SpaceBar and ReturnKey callbacks do not get propagated. When I do button->bindCallback(tgui::Button::AllButtonCallbacks in your example code I do not catch anything from the keys, only mouse movement, focussing/unfocussing and the like. I use development screenshot from the day before yesterday which I compiled with gcc.

from tgui.

heinrichheinsson avatar heinrichheinsson commented on May 31, 2024

Please try your code snippet again with
button->bindCallback(tgui::Button::LeftMouseClicked | tgui::Button::SpaceKeyPressed | tgui::Button::ReturnKeyPressed);

replaced by

button->bindCallback(tgui::Button::SpaceKeyPressed | tgui::Button::ReturnKeyPressed);

from tgui.

heinrichheinsson avatar heinrichheinsson commented on May 31, 2024

"No, your code doesn't work still. Minimum code required..."
I am sorry this may have been misleading, Your code of course works because it contains the leftMouseClicked callback. But the other callbacks don't. See my comment above. Also it has nothing to do with our focusedImage discussion on the forums.

from tgui.

texus avatar texus commented on May 31, 2024

I meant that space and return key callbacks worked for me, so after changing that line it still works.

The important question is: do you see the focused image when you click on the button (or press tab)?
Because this has everything to do with the FocusedImage on my side.

With an unchanged Black.conf, there is no focus image, the button can't be focused, and the space and return key callback will never work because the button is never focused.

When adding the three lines below in the Button section in Black.conf, the focus image shows up, the button gets focused when clicked (or when pressing tab), and the space and return key callbacks work when the button is focused.

FocusedImage_L = "Black.png" (  0, 175,  50, 50)
FocusedImage_M = "Black.png" ( 50, 175, 100, 50)
FocusedImage_R = "Black.png" (150, 175,  50, 50)

If you do see the focused image and the callbacks still don't work, then I simply cannot reproduce the issue and then I will have to do some other tests for which I have no time now (I have an exam in a few days).

from tgui.

heinrichheinsson avatar heinrichheinsson commented on May 31, 2024

Ok, I am very embarrassed. Actually, your minimum example does work.
The problem only arises when the button(s) are in a grid, for some reason they displayed their focused images and but reacted to mouse callbacks only. Turned out one has to focus() the grid before so KeyPressed actually gets propagated to the childWidgets. Somehow it is not enough to only focus() the button. LeftClick always worked because I speculate, that then the grid would be focussed() by it anyway.
I hope your exam turns out well.

from tgui.

Wizzard033 avatar Wizzard033 commented on May 31, 2024

http://forum.tgui.eu/index.php/topic,124.0.html

The grid needs to be focused.

Edit: I originally had the wrong link in there, sorry!

from tgui.

texus avatar texus commented on May 31, 2024

Ok, now at least I know what the problem is.
It shouldn't be too hard to fix, but I should first test the impact of the changes when having multiple child windows and when tabbing between widgets etc.

from tgui.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.