I've been experimenting with passing an FLTK generated widow around between functions. I suspect that what I'm trying to do is one of those things that just won't work. Still, if I can get it working, it will solve some problems for me. I have two code snippets. The first one works, the second one doesn't. Here's the first:
use fltk::app::set_font_size;
use fltk::enums::Color;
use fltk::prelude::{GroupExt, WidgetExt};
use fltk::window::Window;
fn main() {
let app = fltk::app::App::default();
let mut win = makeawin();
win.end();
win.show();
app.run().unwrap();
}
fn makeawin() -> Window {
let mut dwin = Window::default().with_size(825, 900).with_pos(1100, 200);
set_font_size(20);
dwin.set_color(Color::Cyan);
dwin.set_label("Question Bank Display");
dwin.make_resizable(true);
dwin
}
Like I said, this works just fine, drawing a pretty, cyan-colored window on my screen. I had the (maybe not so smart) idea that it would be handy to create a struct to hold that window (along with whatever other widgets I want to add to my window) and then pass that struct back and forth between functions as needed. So, here's what I came up with (that doesn't work):
use fltk::app::set_font_size;
use fltk::enums::Color;
use fltk::prelude::{GroupExt, WidgetExt};
use fltk::window::Window;
struct Wndw {
win: Window,
}
impl Wndw {
fn new() -> Self {
Self {
win: Window::default().with_size(300, 400).with_pos(500, 200),
}
}
}
fn main() {
let app = fltk::app::App::default();
let mut winstruct = Wndw::new();
makeawin(&mut winstruct);
winstruct.win.end();
winstruct.win.show();
app.run().unwrap();
}
fn makeawin(winstruct: &mut Wndw) {
let mut dwin = Window::default().with_size(825, 900).with_pos(1100, 200);
set_font_size(20);
dwin.set_color(Color::Cyan);
dwin.set_label("Question Bank Display");
dwin.make_resizable(true);
winstruct.win = dwin.clone();
}
This compiles and runs without errors, but the window does not display. It wouldn't surprise me if the problem is one of those simple things that I should be smart enough to catch, so please be patient with me.
Any thoughts?