2

I am having a bit of a problem with constantly updating an fltk frame. I have tried to google a few things but anything that should have worked from other answers (e.g: using & / &mut but it doesnt seem to work)

fn main() {
    println!("{}", &time_tick());
    
    let app = app::App::default();
    let mut wind = Window::default()
        .with_size(500, 600)
        .center_screen()
        .with_label("Counter");
    let mut frame = Frame::default()
        .with_size(100, 40)
        .center_of(&wind)
        .with_label(&time_tick());
    wind.make_resizable(true);
    wind.end();
    wind.show();
    /* Event handling */
    thread::spawn(move || {
        app.run().unwrap();
    });
    loop {
        wind.set_callback( move |_| frame.set_label(&time_tick()));
    }
}

Here is the rust playground version

Maximilian Burszley
  • 18,243
  • 4
  • 34
  • 63

1 Answers1

1

Updates can be performed in the wait loop.

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let app = app::App::default();
    let mut wind = Window::default().with_size(400, 400).with_label("Counter");
    let mut frame = Frame::default()
        .with_size(200, 300)
        .center_of(&wind)
        .with_label(&time_tick());

    wind.end();
    wind.show();

    while app.wait() {
        frame.set_label(&time_tick());
        wind.redraw();
    }

    Ok(())
}

I recommend reading the documentation, I had zero experience with the framework and figured it out from docs.

Jakub Dóka
  • 2,477
  • 1
  • 7
  • 12