Use new window for node placement
This commit is contained in:
parent
74ad76f504
commit
008c539623
18
src/main.rs
18
src/main.rs
@ -108,7 +108,7 @@ impl Board {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//////////////////// Node Create/Edit Dialogs ////////////////////
|
//////////////////// Node Create/Edit Dialogs ////////////////////
|
||||||
fn node_create_dialog(state: &mut AppState, pos_x: f32, pos_y: f32) {
|
fn node_create_dialog(pos_x: f32, pos_y: f32) {
|
||||||
let mut win = window::Window::default()
|
let mut win = window::Window::default()
|
||||||
.with_size(100, 100)
|
.with_size(100, 100)
|
||||||
.with_pos(app::event_x_root(), app::event_y_root());
|
.with_pos(app::event_x_root(), app::event_y_root());
|
||||||
@ -125,6 +125,14 @@ fn node_create_dialog(state: &mut AppState, pos_x: f32, pos_y: f32) {
|
|||||||
win.make_resizable(true);
|
win.make_resizable(true);
|
||||||
win.make_modal(true);
|
win.make_modal(true);
|
||||||
win.show();
|
win.show();
|
||||||
|
btn.set_callback({
|
||||||
|
let mut win = win.clone();
|
||||||
|
move |_| {
|
||||||
|
let mut state = STATE.get().lock().unwrap();
|
||||||
|
state.board.add_node(pos_x, pos_y, name.value().to_string());
|
||||||
|
win.hide();
|
||||||
|
}
|
||||||
|
});
|
||||||
while win.shown() {
|
while win.shown() {
|
||||||
app::wait();
|
app::wait();
|
||||||
}
|
}
|
||||||
@ -138,11 +146,7 @@ mod dispatch {
|
|||||||
pub(super) fn node_press(coords: Coords) {
|
pub(super) fn node_press(coords: Coords) {
|
||||||
let (pos_x, pos_y) = coords;
|
let (pos_x, pos_y) = coords;
|
||||||
if app::event_button() == 1 {
|
if app::event_button() == 1 {
|
||||||
let name = dialog::input_default("Node", "");
|
node_create_dialog(pos_x, pos_y);
|
||||||
if let Some(name) = name {
|
|
||||||
let mut state = STATE.get().lock().unwrap();
|
|
||||||
state.board.add_node(pos_x, pos_y, name);
|
|
||||||
}
|
|
||||||
} else if app::event_button() == 3 {
|
} else if app::event_button() == 3 {
|
||||||
let mut state = STATE.get().lock().unwrap();
|
let mut state = STATE.get().lock().unwrap();
|
||||||
let id = state.board.nearest_node(pos_x, pos_y);
|
let id = state.board.nearest_node(pos_x, pos_y);
|
||||||
@ -314,7 +318,7 @@ fn main() {
|
|||||||
let file = File::create(fc.filename()).unwrap();
|
let file = File::create(fc.filename()).unwrap();
|
||||||
let mut ar = zip::ZipWriter::new(file);
|
let mut ar = zip::ZipWriter::new(file);
|
||||||
let options = zip::write::FileOptions::default();
|
let options = zip::write::FileOptions::default();
|
||||||
let mut state = STATE.get().lock().unwrap();
|
let state = STATE.get().lock().unwrap();
|
||||||
|
|
||||||
ar.start_file("graph.json", options).ok();
|
ar.start_file("graph.json", options).ok();
|
||||||
ar.write(&serde_json::to_vec(&state.board).unwrap()).ok();
|
ar.write(&serde_json::to_vec(&state.board).unwrap()).ok();
|
||||||
|
Loading…
Reference in New Issue
Block a user