Closed MGlolenstine closed 4 years ago
I believe you'll need a gtk eventbox for that.
I figured as much, that's why I mentioned it...
I did try to use it, but as it has no connect_xxx
functions, I don't know how to use it.
I did ask on the gtk-rs
github, and they answered that there must exist a function like this, but I don't see it or I'm missing something.
hehe, I totally missed that you already mentioned eventbox.
I used that code in the past, worked fine:
event_box
.connect("button-press-event", false, |_| {
println!("clicked");
Some(true.to_value())
})
.unwrap();
there may be a nicer way though...
I'm sorry I believe that code was raw gtk-rs.
This is relm:
event_box
.connect_local(
// i don't understand the diff between connect and connect_local!!
// but connect wants some multithread things that connect_local doesn't require
"button-press-event",
false,
glib::clone!(@strong event => move |_| {
clicked(&event);
Some(true.to_value())
}),
)
.unwrap();
Oh, so if the connect
doesn't exist, we have to connect them manually.
Thanks!
From the connect
method, I found that we can call 'static
methods, but what if I wanted to call a method inside self
-> The custom widget?
I'd probably have to implement a custom Clone
trait, but I'm wondering if there's another way without having to use the glib::clone!
?
sorry that's over my head at this point. I don't use event_box in my code anymore, too, i just copy-pasted some of my old code.
No matter, thanks for your help! If nothing else, you've pointed me in the right direction ;)
Darn! I'm really getting lousy skimming through examples...
Thanks for your help!
@MGlolenstine: If you have an idea for making them more discoverable, I'd be happy to make that change.
One idea I had for the tutorial was to have one page describing the whole syntax of the view! {}
macro with links to the respective tutorials. Maybe I could have a version of that now that points to the examples. But still, that would not have helped to find that specific example.
I'll think about it, but I'm not sure what the best way to do it would be.
One thing, that could be done (but it would take a lot of effort), is to have all RELM
/gtk-rs
widgets/elements and point them to their usage in the examples
, like link them to their line with some explanation of the code surrounding it.
How would one detect clicks on Label? There's no
connect_clicked
and there isn't one in theEventBox
either.Is there another widget I could use to detect the button press on a
Label
?