Codeblock and TGUI

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

Garwin

I have tried to install TGUI libraries on Codeblock and so far without success. Firstly I tried development version 1.0, than final stable 0.9, both without success. I am doing probably something wrong. I will try to repeat what I did for version 0.9.

Release 20.03 rev 11983 (2020-03-12 18:24:30) gcc 8.1.0 Windows/unicode - 64 bit
SFML 2.5.1 (it works standalone)

1. downloaded precompiled TGUI 0.9.3 for MinGW 7.3.0 (SEH) - 64-bit
2. setting codeblock as described in tutorial - using static link of libraries (both TGUI and SFML)
3. paths to TGUI is set not relative

Enclosed is error report trying to build simple test program:
Issues is that it seems they are some strange paths

#include <TGUI/TGUI.hpp>


int main()
{
    sf::RenderWindow window{ {800, 600}, "TGUI example - SFML_GRAPHICS backend" };

    tgui::Gui gui{window};
    gui.mainLoop();
}


Any help appretiated.

texus

#1
Those errors look related to SFML. When you link SFML statically, you also have to link to its dependencies. The linking errors suggest that you aren't linking to the following SFML dependencies:
Quotefreetype
opengl32
winmm
gdi32

If you are linking to them, then maybe the order of linking is wrong. When you specify the libraries to link, do you have tgui at the end? Perhaps try putting tgui-s-d at the top of the list instead. When statically linking, libraries need to be ordered based on what they depend on (and for GCC the order is first TGUI, then SFML, then SFML's dependencies).


The MinGW compiler version usually has to match exactly between your project and what was used to build SFML and TGUI.
While the errors you showed don't look related to this, I don't think you can mix GCC 8.1 from CodeBlocks with the 7.3 that was used to compile TGUI without getting other issues (linker errors or crashes). If you use GCC 8.1 then you will most likely have to compile TGUI yourself. There is no precompiled TGUI library for GCC 8.1 because there is no stable SFML library for that compiler. So unless you are using an SFML snapshot instead of SFML 2.5.1, I would expect that you would have to compile SFML yourself as well (or switch your compiler to MinGW-w64 7.3.0 x86_64‑posix‑seh for which both SFML and TGUI provide libraries).
You can try keeping your current setup, maybe it will just work, but I won't be fully surprised if the program crashes on rendering once you resolved the linking errors.

Garwin

Thanks for the help.

As I am amateur, hobbiest , I have just tried to make it work. I use dynamic linking and it works.
Probably better solution than static linking.

Garwin

I just have tried https://tgui.eu/examples/0.10/popup-menu/ relaiting pop-up menu to start study of examples of library but trying to build this easy example does not work.

Looking at errors I am quite confused as trying to find "GuiBase" in any hpp file of TGUI is uncessfull.
I rename header to be in line with header file in the TGUI directory:
#include <TGUI/Backend/SFML-Graphics.hpp>
but GuiBase cannot be found anywhere.

C:\Users\tnadrchal\Documents\_Ostatni\C++\TEST\SFML_TGUI\main.cpp|14|error: variable or field 'rightClickCallback' declared void|
C:\Users\tnadrchal\Documents\_Ostatni\C++\TEST\SFML_TGUI\main.cpp|14|error: 'GuiBase' is not a member of 'tgui'|
C:\Users\tnadrchal\Documents\_Ostatni\C++\TEST\SFML_TGUI\main.cpp|14|error: 'gui' was not declared in this scope|
C:\Users\tnadrchal\Documents\_Ostatni\C++\TEST\SFML_TGUI\main.cpp|14|error: expected primary-expression before 'position'|
C:\Users\tnadrchal\Documents\_Ostatni\C++\TEST\SFML_TGUI\main.cpp||In function 'int main()':|
C:\Users\tnadrchal\Documents\_Ostatni\C++\TEST\SFML_TGUI\main.cpp|31|error: 'GuiSFML' is not a member of 'tgui'|
C:\Users\tnadrchal\Documents\_Ostatni\C++\TEST\SFML_TGUI\main.cpp|47|error: 'gui' was not declared in this scope|
C:\Users\tnadrchal\Documents\_Ostatni\C++\TEST\SFML_TGUI\main.cpp|56|error: 'gui' was not declared in this scope|
C:\Users\tnadrchal\Documents\_Ostatni\C++\TEST\SFML_TGUI\main.cpp|65|error: 'gui' was not declared in this scope|
C:\Users\tnadrchal\Documents\_Ostatni\C++\TEST\SFML_TGUI\main.cpp|65|error: 'rightClickCallback' was not declared in this scope|
C:\Users\tnadrchal\Documents\_Ostatni\C++\TEST\SFML_TGUI\main.cpp|68|error: 'gui' was not declared in this scope|
C:\Users\tnadrchal\Documents\_Ostatni\C++\TEST\SFML_TGUI\main.cpp|72|error: 'gui' was not declared in this scope|

texus

#4
It looks like the 0.10 examples are a bit outdated, the class was renamed to BackendGui.
I'll fix it ASAP in all the examples.

Garwin

Thanks, it helps.

I rename other changes but there is still one error I have not found the reason.

    tgui::GuiSFML gui(window);

I renamed it to:

    tgui::BackendGuiSFML gui(window);


as found in BackendGuiSFML.hpp but it does not help.

||=== Build: Debug in SFML_TGUI (compiler: GNU GCC Compiler) ===|
C:\Users\tnadrchal\Documents\_Ostatni\C++\TEST\SFML_TGUI\main.cpp||In function 'int main()':|
C:\Users\tnadrchal\Documents\_Ostatni\C++\TEST\SFML_TGUI\main.cpp|31|error: no matching function for call to 'tgui::BackendGuiSFML::BackendGuiSFML(sf::RenderWindow&)'|
C:\Users\tnadrchal\Documents\_Ostatni\C++\TEST\_LIB\TGUI-0.10\include\TGUI\Backend\Window\SFML\BackendGuiSFML.hpp|48|note: candidate: tgui::BackendGuiSFML::BackendGuiSFML()|
C:\Users\tnadrchal\Documents\_Ostatni\C++\TEST\_LIB\TGUI-0.10\include\TGUI\Backend\Window\SFML\BackendGuiSFML.hpp|48|note:   candidate expects 0 arguments, 1 provided|
||=== Build failed: 1 error(s), 0 warning(s) (0 minute(s), 1 second(s)) ===|

texus

#6
tgui::GuiSFML was from TGUI 0.9, in TGUI 0.10 you can just use tgui::Gui.

Edit: Popup example seems to be the only one still using GuiSFML, I'll fix that line too. (The "GuiBase" has been updated on the website in the meantime, but the old version is still in some caches).

Garwin

It seems I will need to learn how to compile libraries. Finaly run, but except background there is nothing and right click shows some problem with OpenGL.

Text from console running program.

An internal OpenGL call failed in RenderTarget.cpp(302).
Expression:
   glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(Vertex), data + 8)
Error description:
   GL_INVALID_OPERATION
   The specified operation is not allowed in the current state.

An internal OpenGL call failed in RenderTarget.cpp(711).
Expression:
   glDrawArrays(mode, static_cast<GLint>(firstVertex), static_cast<GLsizei>(vertexCount))
Error description:
   GL_INVALID_OPERATION
   The specified operation is not allowed in the current state.

texus

Since the SFML code is unlikely to be broken, and neither TGUI or your project is making OpenGL calls that could interfere with SFML, this does sound like some library incompatibility.
So you will indeed either need to learn how to compile SFML and TGUI, or alternatively learn how to change the compiler in CodeBlocks and downgrade the GCC version.

Garwin

Interesting thing is that I found out that I have:
g++ (x86_64-posix-seh-rev0, Built by MinGW-W64 project) 7.3.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


Strange that opening Codeblock shows gcc 8.1.0. but it seems more likely that it is MinGW 8.1.0

texus

Depending on which CodeBlocks binary you install, it will use a bundled 8.1 from C:\Program Files\CodeBlocks\MinGW
You can change that in Settings > Compiler... from the menu bar and then writing a different path under the "Toolchain executables" tab.

If you set it to a directory containing MinGW 7.1 then everything should be compatible when you are using the SFML 2.5.1 downloaded from the SFML website.

Garwin

Finally it works. Thanks a lot for your time.

Somehow changing of linking of SFML libraries from static to dynamic was not saved.
Saved now and it works like a charm.

I will start to look what library is offering.


Tooltips seems very nice.  Just an idea moving position of tooltip up/left by difference between bounding box of last entry in relation to videomode.

texus

QuoteJust an idea moving position of tooltip up/left by difference between bounding box of last entry in relation to videomode.
I'm not sure what you mean. It should already be moving the tool tip if it would be outside the window. Isn't it behaving like that for you?

Garwin

Quote from: texus on 12 April 2022, 16:39:26
QuoteJust an idea moving position of tooltip up/left by difference between bounding box of last entry in relation to videomode.
I'm not sure what you mean. It should already be moving the tool tip if it would be outside the window. Isn't it behaving like that for you?

No, it is not. See screenshot.


texus

Can you show how you create the tool tip? Because that behavior would be a bug.

For testing I just tried the following on a button near the right side of the window and it did work as intended:
button->setToolTip(tgui::Label::create("Testing with some long string"));

Garwin

#15
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.


texus

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);

Garwin

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 https://tgui.eu/tutorials/0.10/signals/ but I struggle.

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

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)
{
}


texus

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));

Garwin

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

texus

#20
You can find the other widgets by scrolling through https://tgui.eu/documentation/0.10/annotated.html (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: https://github.com/texus/TGUI/blob/0.10/src/Loading/Theme.cpp#L40-L303

Garwin

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