Use node edit dialog to change names of nodes
This commit is contained in:
parent
da1c4b7f3f
commit
540629100c
@ -5,7 +5,7 @@ use image::DynamicImage;
|
|||||||
|
|
||||||
use rfd::FileDialog;
|
use rfd::FileDialog;
|
||||||
|
|
||||||
use board_builder::{ Board, CoordTransformer, read_board_from_file, write_board_to_file };
|
use board_builder::{ Board, Node, CoordTransformer, read_board_from_file, write_board_to_file };
|
||||||
|
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
@ -25,6 +25,7 @@ struct BoardBuilderApp {
|
|||||||
edit_mode: EditMode,
|
edit_mode: EditMode,
|
||||||
selected_node: Option<usize>,
|
selected_node: Option<usize>,
|
||||||
create_node_dialog: CreateNodeDialog,
|
create_node_dialog: CreateNodeDialog,
|
||||||
|
edit_node_dialog: EditNodeDialog,
|
||||||
edit_labels_dialog: EditLabelsDialog,
|
edit_labels_dialog: EditLabelsDialog,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -131,6 +132,7 @@ impl eframe::App for BoardBuilderApp {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
self.edit_node_dialog.ui(ctx);
|
||||||
self.edit_labels_dialog.ui(ctx);
|
self.edit_labels_dialog.ui(ctx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -194,7 +196,12 @@ impl BoardBuilderApp {
|
|||||||
match (btn, self.edit_mode) {
|
match (btn, self.edit_mode) {
|
||||||
(Primary, Nodes) => self.create_node_dialog.show(x, y),
|
(Primary, Nodes) => self.create_node_dialog.show(x, y),
|
||||||
(Primary, Edges) => self.select_edge(x, y),
|
(Primary, Edges) => self.select_edge(x, y),
|
||||||
(Secondary, Nodes) => self.delete_node(x, y),
|
(Secondary, Nodes) => {
|
||||||
|
let board = Rc::clone(&self.board);
|
||||||
|
if let Some(id) = self.board.borrow().nearest_node(x, y) {
|
||||||
|
self.edit_node_dialog.show(id, board);
|
||||||
|
}
|
||||||
|
},
|
||||||
_ => {},
|
_ => {},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -247,6 +254,41 @@ impl CreateNodeDialog {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Default)]
|
||||||
|
struct EditNodeDialog {
|
||||||
|
open: bool,
|
||||||
|
id: usize,
|
||||||
|
node: Node,
|
||||||
|
board: Rc<RefCell<Board>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl EditNodeDialog {
|
||||||
|
fn show(&mut self, id: usize, board: Rc<RefCell<Board>>) {
|
||||||
|
self.open = true;
|
||||||
|
self.id = id;
|
||||||
|
self.board = board;
|
||||||
|
self.node = self.board.borrow().nodes.get(&self.id).unwrap().clone();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn ui(&mut self, ctx: &Context) {
|
||||||
|
if !self.open { return }
|
||||||
|
Window::new("Edit Node")
|
||||||
|
.collapsible(false)
|
||||||
|
.show(ctx, |ui| {
|
||||||
|
let mut board = self.board.borrow_mut();
|
||||||
|
ui.text_edit_singleline(&mut self.node.name);
|
||||||
|
if ui.button("Ok").clicked() {
|
||||||
|
board.nodes.insert(self.id, self.node.clone());
|
||||||
|
self.open = false;
|
||||||
|
}
|
||||||
|
if ui.button("Cancel").clicked() {
|
||||||
|
self.open = false
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
struct EditLabelsDialog {
|
struct EditLabelsDialog {
|
||||||
open: bool,
|
open: bool,
|
||||||
@ -359,22 +401,3 @@ impl StringDialog {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// #[derive(Default)]
|
|
||||||
// struct EditNodeDialog {
|
|
||||||
// open: bool,
|
|
||||||
// name: String,
|
|
||||||
// id: usize,
|
|
||||||
// labels: HashMap<String, String>,
|
|
||||||
// }
|
|
||||||
|
|
||||||
// impl EditNodeDialog {
|
|
||||||
// fn show(&mut self, id: usize, board: &Board) {
|
|
||||||
// self.open = true;
|
|
||||||
// let node = board.nodes.get(&id).unwrap();
|
|
||||||
|
|
||||||
// self.id = id;
|
|
||||||
// self.name = node.name.clone();
|
|
||||||
// self.labels = node.labels.clone();
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use serde::{ Serialize, Deserialize };
|
use serde::{ Serialize, Deserialize };
|
||||||
use std::collections::{ HashMap, HashSet };
|
use std::collections::{ HashMap, HashSet };
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug, Default)]
|
#[derive(Serialize, Deserialize, Debug, Default, Clone)]
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub struct Node {
|
pub struct Node {
|
||||||
pub x: f32,
|
pub x: f32,
|
||||||
|
Loading…
Reference in New Issue
Block a user