Comments, code cleanup, etc
This commit is contained in:
parent
3f76a78766
commit
ad22b84cb1
52
src/main.rs
52
src/main.rs
@ -17,6 +17,10 @@ use std::rc::Rc;
|
|||||||
use std::io::{ Write, Read, Cursor };
|
use std::io::{ Write, Read, Cursor };
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//////////////////// Data Layout ////////////////////
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
struct Node {
|
struct Node {
|
||||||
pub x: f32,
|
pub x: f32,
|
||||||
@ -45,8 +49,10 @@ impl Board {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn remove_node(&mut self, id: usize) {
|
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);
|
self.nodes.remove(&id);
|
||||||
for (_, node) in &mut self.nodes {
|
for node in self.nodes.values_mut() {
|
||||||
node.edges.remove(&id);
|
node.edges.remove(&id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -80,25 +86,7 @@ impl Board {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct AppState {
|
//////////////////// Utility Functions ////////////////////
|
||||||
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!();
|
|
||||||
}
|
|
||||||
|
|
||||||
fn encode_png(image: &DynamicImage) -> Vec<u8> {
|
fn encode_png(image: &DynamicImage) -> Vec<u8> {
|
||||||
let mut cursor = Cursor::new(Vec::new());
|
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() {
|
fn main() {
|
||||||
let app = app::App::default()
|
let app = app::App::default()
|
||||||
.with_scheme(app::Scheme::Gtk);
|
.with_scheme(app::Scheme::Gtk);
|
||||||
@ -241,7 +251,7 @@ fn main() {
|
|||||||
image.draw(f.x(), f.y(), f.w(), f.h());
|
image.draw(f.x(), f.y(), f.w(), f.h());
|
||||||
}
|
}
|
||||||
let board = &state.board;
|
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);
|
let (x, y) = f.from_coords(node.x, node.y);
|
||||||
draw_text(&node.name, x, y);
|
draw_text(&node.name, x, y);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user