Convert to a procedural style (more in keeping with fltk framework)

This commit is contained in:
Dane Johnson 2022-04-28 08:53:53 -05:00
parent d544eb478f
commit e844a5f005

View File

@ -8,15 +8,7 @@ use std::cell::RefCell;
use std::rc::Rc; use std::rc::Rc;
use std::collections::HashMap; use std::collections::HashMap;
struct BoardApp {
app: app::App,
win: window::Window,
image: Rc<RefCell<Option<image::SharedImage>>>,
board: Rc<RefCell<Board>>,
}
type Id = usize; type Id = usize;
#[derive(Serialize, Deserialize, Debug)] #[derive(Serialize, Deserialize, Debug)]
struct Node { struct Node {
pub x: f32, pub x: f32,
@ -25,13 +17,11 @@ struct Node {
pub name: String, pub name: String,
pub edges: Vec<Id>, pub edges: Vec<Id>,
} }
#[derive(Serialize, Deserialize, Debug)] #[derive(Serialize, Deserialize, Debug)]
struct Board { struct Board {
nodes: HashMap<Id, Node>, nodes: HashMap<Id, Node>,
image: Option<String>, image: Option<String>,
} }
impl Board { impl Board {
pub fn new() -> Self { pub fn new() -> Self {
let nodes = HashMap::new(); let nodes = HashMap::new();
@ -40,8 +30,11 @@ impl Board {
} }
} }
impl BoardApp { fn menu_cb(m: &mut impl MenuExt) {
pub fn new() -> Self { todo!();
}
fn main() {
let app = app::App::default(); let app = app::App::default();
let mut win = window::Window::default() let mut win = window::Window::default()
.with_size(400, 300); .with_size(400, 300);
@ -76,33 +69,10 @@ impl BoardApp {
}); });
flex.end(); flex.end();
win.end(); win.end();
win.make_resizable(true); win.make_resizable(true);
win.show();
BoardApp { app, win, image, board } app.run().unwrap();
}
pub fn show(&mut self) {
self.win.show();
}
pub fn run(&mut self) {
self.app.run().unwrap();
}
pub fn load_image(&mut self, path: &str) {
self.board.borrow_mut().image = Some(path.to_string());
self.image.replace(image::SharedImage::load(path).ok());
}
}
fn menu_cb(m: &mut impl MenuExt) {
todo!();
}
fn main() {
let mut app = BoardApp::new();
app.show();
app.load_image("risk.png");
app.run();
} }