This is an ownership problem which is why I'm posting here instead of on the fltk.rs github forum. Here is the code I need help with:
use fltk::{prelude::*, *, window};
use fltk::enums::CallbackTrigger;
fn main() {
let mainapp = app::App::default();
let mut mainwin = window::Window::default()
.with_size(800, 500)
.with_label("Main Window");
mainwin.make_resizable(true);
mainwin.end();
mainwin.show();
let value = input_prompt(&mainapp, "This is a prompt");
mainapp.run().unwrap();
println!("\n In main() the inputted value is: {:?}", value);
}
fn input_prompt(app: &app::App, prompt: &str) -> String {
let mut win = window::Window::default()
.with_size(400, 300)
.with_label("Input Window");
win.make_resizable(true);
let flex = group::Flex::default()
.with_size(100, 100)
.column()
.center_of_parent();
let _prompttext = frame::Frame::default().with_label(prompt);
let mut input = input::Input::default();
input.set_trigger(CallbackTrigger::EnterKey);
let input = input.clone();
let mut win = win.clone();
input.set_callback(move|input| {
println!("\n In the input callback, the value is: {}", input.value());
win.hide();
});
flex.end();
win.end();
win.show();
while win.shown() {
app.wait();
}
input.value()
}
The problem occurs in lines 36-39 where an attempt is made to set a callback on an input window. The idea is that the app will first open a main window for doing other stuff, but when an input window is needed, this routine will call up an input_prompt() window, to allow data entry. On pressing enter
the window is closed and the data returned to the calling function. The compiler is objecting to this code (rightfully so) because ownership of the input window is being passed into the callback closure container located in the lines 36-39. I really don't know how to address this problem, any ideas/suggestions?