-
-
Notifications
You must be signed in to change notification settings - Fork 82
Struggling with accessing the same widget from multiple connect calls #111
Comments
You have to use let libraryview : Rc<RefCell<Viewport>> = Rc::new(RefCell::new(builder.get_object("libraryview").unwrap()));
let scroll : Rc<RefCell<ScrolledWindow>> = Rc::new(RefCell::new(builder.get_object("mainscroll").unwrap()));
let b_libraryview = libraryview.clone();
let b_libraryview2 = libraryview.clone();
let b_scroll = scroll.clone();
let b_scroll2 = scroll.clone();
librarylbl.connect_button_press_event(move |_,_,| {
(*b_scroll.borrow_mut()).remove(b_libraryview.borrow());
Inhibit(true)
});
newrecipelbl.connect_button_press_event(move|_,_| {
(*b_scroll2.borrow_mut()).remove(b_libraryview2.borrow());
Inhibit(true)
}); (Or nearby). |
@GuillaumeGomez You don't have to do that for refcounted types (particularly, any widgets) because they already are a kind of I'd also look into cloning the closure as well. This might work: let libraryview : Viewport = builder.get_object("libraryview").unwrap();
let scroll : ScrolledWindow = builder.get_object("mainscroll").unwrap();
let env = (scroll.clone(), library_view.clone());
let handler = move |_,_| {
let (ref scroll, ref library_view) = env;
scroll.remove(libraryview);
Inhibit(true)
};
librarylbl.connect_button_press_event(handler.clone());
newrecipelbl.connect_button_press_event(handler); |
I didn't pay attention. Thanks for correcting me @gkoz. |
When trying to clone the closure I got
I'm wondering, is cloning each widget the only way to do this? As i'm going to use a number of |
I was mistaken then, you can't clone a closure :(
Currently closures have unbounded ( One can always try to design some clever macros ;) |
Here's a macro that will clone the variables for you: http://is.gd/xQlEHR |
Cheers! Really appreciate your help |
I'm just having a little problem with this macro, I can do https://play.rust-lang.org/?gist=7ad1859c73cd05a19e2c&version=stable which works fine. But the following
Results in:
|
Interesting! Does Rust nightly produce the same error? |
Just about to try that :) Edit: Yup, it's fixed in nightly, and compiles fine |
This is slightly off-topic but I'm just wondering I'm doing the following:
So when I click the 'newrecipelbl' I get the newrecipeview shown in the GtkScrolledWindow, and when I click 'librarylbl' I get the libraryview shown in the GtkScrolledWindow. This works, if i click each of these buttons once, but as soon as I press one more than once. I get
Which seems odd, as I've removed the elements from the scrolled window, as far as I can tell. |
I'll probably need a full working sample to play with. |
I managed to solve it through re-parenting the view port to an offscreen window :)
|
I'm struggling with the following code I've written
Which results in a borrow error for scroll and libraryview, whereas it looks like you could do something similar in rgtk, using &mut || { } closures as far as I can tell?
The text was updated successfully, but these errors were encountered: