diff --git a/src/main.rs b/src/main.rs index 354220f..49fb810 100644 --- a/src/main.rs +++ b/src/main.rs @@ -17,6 +17,10 @@ use std::rc::Rc; use std::io::{ Write, Read, Cursor }; use std::fs::File; + + +//////////////////// Data Layout //////////////////// + #[derive(Serialize, Deserialize, Debug)] struct Node { pub x: f32, @@ -45,8 +49,10 @@ impl Board { } pub fn remove_node(&mut self, id: usize) { + // We remove this node from the graph, then drop it from each + // other nodes edge. self.nodes.remove(&id); - for (_, node) in &mut self.nodes { + for node in self.nodes.values_mut() { node.edges.remove(&id); } } @@ -80,25 +86,7 @@ impl Board { } } -struct AppState { - pub board: Board, - pub image_raw: Option, - pub image: Option, -} - -impl AppState { - fn new() -> Self { - AppState { - board: Board::new(), - image_raw: None, - image: None - } - } -} - -fn menu_cb(_m: &mut impl MenuExt) { - todo!(); -} +//////////////////// Utility Functions //////////////////// fn encode_png(image: &DynamicImage) -> Vec { let mut cursor = Cursor::new(Vec::new()); @@ -146,6 +134,28 @@ impl CoordTransformer for frame::Frame { } } +fn menu_cb(_m: &mut impl MenuExt) { + todo!(); +} + +//////////////////// App State //////////////////// + +struct AppState { + pub board: Board, + pub image_raw: Option, + pub image: Option, +} + +impl AppState { + fn new() -> Self { + AppState { + board: Board::new(), + image_raw: None, + image: None + } + } +} + fn main() { let app = app::App::default() .with_scheme(app::Scheme::Gtk); @@ -241,7 +251,7 @@ fn main() { image.draw(f.x(), f.y(), f.w(), f.h()); } let board = &state.board; - for (_, node) in &board.nodes { + for node in board.nodes.values() { let (x, y) = f.from_coords(node.x, node.y); draw_text(&node.name, x, y); }