New to Rust and I'm trying to build a simple Rust GUI using gtk-rs following the docs here. What I'm wondering is whether it's possible to pass around the window
that gets built in the build_ui
function, so that I can update it from other operations in my code. The following code lives inside of a function that does other stuff too, further down in the function I would like to access the window so that I can add a new child widget (or something like that). Is this possible? If so how can I go about it? Unfortunately none of the examples in the project cover something like this.
fn main() {
let app = Application::builder()
.application_id("org.gtk-rs.example")
.build();
app.connect_activate(build_ui);
let mut win: ApplicationWindow; <---- I want to store the window here to use later
fn build_ui(app: &Application) {
// Create a window and set the title
let window = ApplicationWindow::builder()
.application(app)
.title("My GTK App")
.build();
win = window; <----
}
// do other UI bootstrapping stuff
// when ready to mount the window
window.present();
}
Would appreciate any help, thanks