Comments, code cleanup, etc

This commit is contained in:
Dane Johnson 2022-04-29 09:03:48 -05:00
parent 3f76a78766
commit ad22b84cb1

View File

@ -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<DynamicImage>,
pub image: Option<PngImage>,
}
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<u8> {
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<DynamicImage>,
pub image: Option<PngImage>,
}
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);
}