I'm still missing something here, what is the width (the 36 in your earlier example) that you pass to the layoutWidth function?
Could you put this in a small but more complete example?
Could you put this in a small but more complete example?
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 Menubutton->connect("pressed", std::bind(f, std::ref(i)));QuoteAnother thing that I wondered about, is what is the scope of the function that is called by the button, once it's connected. I assumed it's the same scope as where the button was created, am I right?The question didn't make much sense earlier but I realize now that you might have used the wrong term, I guess the question is rather what the lifetime would be, not the scope.
Quotewhat is the scope of the function that is calledThe function can be anywhere, just like you can call any function yourself as long as it has been declared before.
QuoteAlso, what if the function has a return type? Let's say return type int. How could I catch that int when the function returns?This is not possible. You wouldn't be able to access the return value even if the function would return something since the function is called internally and there is nowhere in your code where you would get the return. If a function need to "return" something then give it a reference parameter and pass it with std::ref.
void f(int& x) { x = 5; }
int i = 0;
button->connect("pressed", f, std::ref(i));
// i is 0 here but will become 5 once the callback is triggered
QuoteIf you don't mind me saying, the tutorials could be a little clearer and explain stuff a little more in detail.It's hard for me to know which things have to be explained better, if you have suggestions on what to add to the tutorial to make it easier to understand then feel free to suggest them.
Quotetgui::Button::Ptr new_game_button;new_game_button will be a nullptr here. It should betgui::Button::Ptr new_game_button = std::make_shared<tgui::Button>();Quotegui there is not a pointer, it's asking me for the actual object.The solution is actually very simple:
tgui::Button::Ptr new_game_button(*guiPtr);QuoteI checked the documentation, and it's a typedef for a sharedptr for a ButtonYou either checked the wrong documentation or you misinterpreted it. In v0.7-dev it is indeed a normal std::shared_ptr, but in v0.6 it is a typedef to my own custom smart pointer class.
Quotewhy does it need that gui parameter?Constructing a widget goes in 3 steps (although you only need 2 lines):
tgui::Button::Ptr button(gui);
button->load("TGUI/widgets/Black.conf");tgui::Button::Ptr button = theme->load("button");
gui.add(button);Quotethe compiler is not letting me store the reference in a variable inside Game_State_Manager, for some reason, it complains that I have to initialize references in the constructor initialization list (I have to confess I don't know what it's talking aboutThe constructor of a class consists of two parts: the initializer list and the constructor body. Before the body of the constructor is executed, all members of the class have already been initialized (although plain types like int are just random values). The reference has to already refer to a variable during this initialization step, it is already too late when the body of the constructor is executed. So it has to happen in the initializer list of which you find an example below (notice the ':' after the constructor).)
class Test
{
public:
Test(int& i);
private:
int x;
int y;
int& z;
}
Test::Test(int& i) :
x(i), // Give x the value of the variable i
z(i) // Make z a reference to the variable i
{
}label->setPosition(tgui::bindPosition(button));label->setPosition(tgui::bindPosition(button) + sf::Vector(4, 2));
winEditConfigTabs = theme->load("tab");
winEditConfig->add(winEditConfigTabs);
winEditConfigTabs->setTextSize(text_size);
...