Codeblock and TGUI

Started by Garwin, 12 April 2022, 09:30:19


Code included. And sorry, it is not tooltip, it is context menu from example mentioned above.
Just do not look at quality of code, it is just a mess trying everything and some part of code is from my first testing c++.

Just thinking how can I get choosen context menu back to main (generally back to caller to work with it).
Another thoughts how to implement tooltip over SFML objects, not only TGUI widgets using advantage of one theme in future.


This behavior for the context menu is a completely different story. If TGUI would support context menus then it would be good if it automatically moved the menu, but TGUI currently doesn't even support context menus at all.

From TGUI's perspective, you are just creating a regular ListBox, and it won't automatically change positions for ordinary widgets like that.

So you would have to do this yourself by adding the following code at the end of rightClickCallback (after calling gui.add).
Code (cpp) Select
if (popupMenu->getPosition().x + popupMenu->getSize().x > popupMenu->getParent()->getSize().x)
    popupMenu->setPosition(popupMenu->getParent()->getSize().x - popupMenu->getSize().x, popupMenu->getPosition().y);
if (popupMenu->getPosition().y + popupMenu->getSize().y > popupMenu->getParent()->getSize().y)
    popupMenu->setPosition(popupMenu->getPosition().x, popupMenu->getParent()->getSize().y - popupMenu->getSize().y);


Thanks, it is even better limiting to parent, not the whole window.

I am now experimenting with callback event in the code trying to use example of but I struggle.

This is callback:

and function:

double popupMenuCallback1(tgui::String item)

But I need to pass reference of variable "speed" as this variable will be change in accordance to choosen item. I use example and try to pass value (even trying pointer) with errors.
I was thinking about lambdas (still trying to undertand them) but I need not to pass only variable but use of choosen item from listbox too.

This is callback:
popupMenu->onItemSelect(&popupMenuCallback1, speed);

and function:

double popupMenuCallback1(tgui::String item, double& speed)


The order of the parameters is wrong.
double popupMenuCallback1(tgui::String item, double& speed)
should be
double popupMenuCallback1(double& speed, tgui::String item)
(because TGUI always passes your bound parameters first before the optional parameters such as the item)

If you want to change the speed variable inside your callback then you also have to use std::ref, to prevent the speed from being copied by TGUI:
popupMenu->onItemSelect(&popupMenuCallback1, std::ref(speed));


Thanks, I did try std::ref but did not realize the bad order.

Nice library, a little more difficult to understand for a beginner like me compared to SFML which has really easy syntax, but has a lot of functionality and it seems some functionality can be used over SFML objects (needs to dig in how).

Just a question. Is there anywhere just simple overview of all widgets?
Something like list of widget with simple screenshot or at least just list of widgets?

I look at tutorial and examples, there a listed many of them but it seems there is no place where there is list of all of them.
So far, I can see:
- tabs / tabs container
- menu bar (clickable and rollable options)
- label  (just text)
- radio button (for the first look it seems  that primary it is single button, clickable, need to look if it can be unclicked)
- button (seems similar to radio button except visualization)
- edit box (need to check, how it treats longer strings than
- list box (with options and scrollable, need to find if this scroll on right can be removed)
- progress bar
- slider
- combo box (to choose from options)
- child window
- chat box
- canvas (it seems interesing as it seems to me that it can draw SFML sprites and use TGUI functionality. I will dig into it)
- scrollable panel


You can find the other widgets by scrolling through (which is a list of all classes, not just widgets)

QuoteSomething like list of widget with simple screenshot or at least just list of widgets?
Creating such a list (with a screenshot, minimal explanation and a list of its signals) has been on my TODO list for a long time. I'll probably start working on it once 0.10 is released.

Edit: The default theme code could also be used as a list for all widgets for now:


It would help a lot as the API is quite large and it seems to use it effectively means understanding it under the hood.