Convert to a procedural style (more in keeping with fltk framework)
This commit is contained in:
parent
d544eb478f
commit
e844a5f005
46
src/main.rs
46
src/main.rs
@ -8,15 +8,7 @@ use std::cell::RefCell;
|
||||
use std::rc::Rc;
|
||||
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;
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
struct Node {
|
||||
pub x: f32,
|
||||
@ -25,13 +17,11 @@ struct Node {
|
||||
pub name: String,
|
||||
pub edges: Vec<Id>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
struct Board {
|
||||
nodes: HashMap<Id, Node>,
|
||||
image: Option<String>,
|
||||
}
|
||||
|
||||
impl Board {
|
||||
pub fn new() -> Self {
|
||||
let nodes = HashMap::new();
|
||||
@ -40,8 +30,11 @@ impl Board {
|
||||
}
|
||||
}
|
||||
|
||||
impl BoardApp {
|
||||
pub fn new() -> Self {
|
||||
fn menu_cb(m: &mut impl MenuExt) {
|
||||
todo!();
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let app = app::App::default();
|
||||
let mut win = window::Window::default()
|
||||
.with_size(400, 300);
|
||||
@ -76,33 +69,10 @@ impl BoardApp {
|
||||
});
|
||||
|
||||
flex.end();
|
||||
|
||||
win.end();
|
||||
win.make_resizable(true);
|
||||
win.show();
|
||||
|
||||
BoardApp { app, win, image, board }
|
||||
}
|
||||
|
||||
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();
|
||||
app.run().unwrap();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user