Clickable pictures.

Started by desocupado, 22 November 2015, 20:48:12

desocupado

Hey. I'm trying to set up clickable pictures. I searched the forums a bit, and tried to figure out how to do it, but it's not working.

This doesn't work:

   tgui::Picture::Ptr robot_face = std::make_shared<tgui::Picture>();
   robot_pic->connect("clicked", &Equip_Screen::select_robot, this);

If I make it a button, tho, it works

   tgui::Button::Ptr robot_face = theme->load("Button");
   robot_face->connect("pressed", &Equip_Screen::select_robot, this);

Assume that the positions and textures were set, I cut them out so the code is minimal.

What is wrong?

texus

The code should work fine. In the code in your post you did use robot_face as widget while you called connect on robot_pic, but if they are called on the same object then it works here. If that was just a mistake in your post and not in your code then you might want to create a minimal code that shows the issue so that I can reproduce it here.

desocupado

#2
Sigh.

It was just that. Really sorry about that, it's the second time I make a silly mistake like this today.

Could you tell me if I'm right about something tho, in this line:

robot_face->connect("clicked", &Equip_Screen::select_robot, this, i);

The value of "i" is set at the time the line executes. So if I do something like this:

int i = 1;
robot_face->connect("clicked", &Equip_Screen::select_robot, this, i);
i = 2;

wait for button press

When the button is pressed, the select_robot function is going to be called with the value of 1 as argument, correct?

And if I do

robot_face->connect("clicked", &Equip_Screen::select_robot, this, std::ref(i));

Then it'll store a reference to i, and use it's value?

texus

Yeah, that is correct.
I had to test myself what std::ref would do when the function itself doesn't take a reference as parameter but it does indeed passes the new value to the function.
But I guess you might have figured that out yourself by now.

Since I read your reply before the edit I only saw the edited version by chance. If you want to ask a new question it is better to add a new reply than to edit the post, that way I will get a new mail so I can't miss it.