I want to refresh a DrawingArea
each time I call the draw()
function. I have read Update drawing function of a DrawingArea, so I know that I need to disconnect the old drawing signal before connecting a new one. DrawingArea
has the method disconnect(id: SignalHandlerId)
, so this code compiles, but no drawing is displayed:
let id = drawing_area.connect_draw(move |_, cr| {
// drawing
});
drawing_area.disconnect(id);
When I try to save the id to disconnect the old signal before connecting the new one, I need to explicitly declare id
as SignalHandlerId
:
extern crate cairo;
extern crate gio;
extern crate gtk;
use gtk::prelude::*;
pub struct DrawingMechanism {
id: gtk::glib::signal::SignalHandlerId,
used: bool,
}
impl DrawingMechanism {
pub fn draw(&self, drawing_area: >k::DrawingArea) {
if self.used {
drawing_area.disconnect(self.id);
} else {
self.used = true; // first call doesn`t have old id
}
self.id = drawing_area.connect_draw(move |_, cr| {
// drawing
});
}
}
Here is the problem: the compiler tells me that gtk::glib
is private, so I cannot use it. If I try to add the glib crate and use it instead of gtk::glib
, the compiler tells me that I am using glib::SignalHandlerId
, and what DrawingArea::connect_draw()
returns is glib::signal::SignalHandlerId
.
How do I declare the id
variable so I can store the old signal id?
EDIT: It was just a version mismatch, I was trying to use glib
version 0.9.0
, but gtk
was using 0.8.2
.