I'm very new to Rust and rarely do any kind of graphics or UI stuff, so expect dumb mistakes.
I am trying to create a program that runs a simulation and displays its changing state over time. For this I want to create a window and then draw stuff on it, and have the stuff that's drawn change. Ideally it would be great if it were optimized for placing individual pixels (with the expectation that most of the time only a few pixels will change per timestep), but for now I'll settle for anything where I can run some code, display the result, run some more code, and refresh the display.
What I have so far:
fn main() {
let app = Application::builder()
.application_id("org.example.HelloWorld")
.build();
app.connect_activate(|app| {
let win = ApplicationWindow::builder()
.application(app)
.default_width(320)
.default_height(200)
.title("Hello, World!")
.build();
let draw_area = DrawingArea::new();
win.add(&draw_area);
draw_area.connect_draw(|_unused, f| {
f.set_source_rgb(1.0, 0.0, 0.0);
f.paint();
thread::sleep(time::Duration::from_millis(1000));
f.set_source_rgb(0.0, 1.0, 0.0);
f.paint();
Inhibit(false)
});
win.show_all();
});
app.run();
}
I would like this to show an all-red window, wait for a second, and then show an all-green one. Instead it waits for a second and shows an all-green window. How can I restructure it so that I can update the display at intervals I control?