Whitespace fixup
This commit is contained in:
parent
8c6f54054c
commit
92b0d5cb01
@ -100,36 +100,36 @@ impl eframe::App for BoardBuilderApp {
|
|||||||
image.paint_at(ui, response.rect);
|
image.paint_at(ui, response.rect);
|
||||||
let view = View(response.rect);
|
let view = View(response.rect);
|
||||||
self.draw_board(&painter, view);
|
self.draw_board(&painter, view);
|
||||||
if let Some(pos) = response.interact_pointer_pos() {
|
if let Some(pos) = response.interact_pointer_pos() {
|
||||||
let btn = if response.clicked() {
|
let btn = if response.clicked() {
|
||||||
PointerButton::Primary
|
PointerButton::Primary
|
||||||
} else if response.secondary_clicked() {
|
} else if response.secondary_clicked() {
|
||||||
PointerButton::Secondary
|
PointerButton::Secondary
|
||||||
} else {
|
} else {
|
||||||
PointerButton::Middle
|
PointerButton::Middle
|
||||||
};
|
};
|
||||||
let (x, y) = view.xform(pos);
|
let (x, y) = view.xform(pos);
|
||||||
self.dispatch_click(btn, x, y);
|
self.dispatch_click(btn, x, y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if self.create_node_dialog.open {
|
if self.create_node_dialog.open {
|
||||||
Window::new("Create Node")
|
Window::new("Create Node")
|
||||||
.collapsible(false)
|
.collapsible(false)
|
||||||
.show(ctx, |ui| {
|
.show(ctx, |ui| {
|
||||||
let mut board = self.board.borrow_mut();
|
let mut board = self.board.borrow_mut();
|
||||||
ui.label("Name:");
|
ui.label("Name:");
|
||||||
ui.text_edit_singleline(&mut self.create_node_dialog.name);
|
ui.text_edit_singleline(&mut self.create_node_dialog.name);
|
||||||
if ui.button("Add").clicked() {
|
if ui.button("Add").clicked() {
|
||||||
self.create_node_dialog.close();
|
self.create_node_dialog.close();
|
||||||
board.add_node(
|
board.add_node(
|
||||||
self.create_node_dialog.x,
|
self.create_node_dialog.x,
|
||||||
self.create_node_dialog.y,
|
self.create_node_dialog.y,
|
||||||
self.create_node_dialog.name.clone(),
|
self.create_node_dialog.name.clone(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
self.edit_labels_dialog.ui(ctx);
|
self.edit_labels_dialog.ui(ctx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -164,17 +164,17 @@ impl BoardBuilderApp {
|
|||||||
fn draw_board(&self, painter: &Painter, view: View) {
|
fn draw_board(&self, painter: &Painter, view: View) {
|
||||||
let board = self.board.borrow();
|
let board = self.board.borrow();
|
||||||
for (&id, node) in &board.nodes {
|
for (&id, node) in &board.nodes {
|
||||||
let color = if Some(id) == self.selected_node {
|
let color = if Some(id) == self.selected_node {
|
||||||
Color32::RED
|
Color32::RED
|
||||||
} else {
|
} else {
|
||||||
Color32::BLACK
|
Color32::BLACK
|
||||||
};
|
};
|
||||||
painter.text(
|
painter.text(
|
||||||
view.inv_xform(node.x, node.y),
|
view.inv_xform(node.x, node.y),
|
||||||
Align2::CENTER_CENTER,
|
Align2::CENTER_CENTER,
|
||||||
&node.name,
|
&node.name,
|
||||||
FontId::proportional(16.0),
|
FontId::proportional(16.0),
|
||||||
color,
|
color,
|
||||||
);
|
);
|
||||||
let stroke = Stroke { width: 1.0, color: Color32::BLACK };
|
let stroke = Stroke { width: 1.0, color: Color32::BLACK };
|
||||||
for edge in &node.edges {
|
for edge in &node.edges {
|
||||||
@ -188,32 +188,32 @@ impl BoardBuilderApp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn dispatch_click(&mut self, btn: PointerButton, x: f32, y: f32) {
|
fn dispatch_click(&mut self, btn: PointerButton, x: f32, y: f32) {
|
||||||
use EditMode::*;
|
use EditMode::*;
|
||||||
use PointerButton::*;
|
use PointerButton::*;
|
||||||
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) => self.delete_node(x, y),
|
||||||
_ => {},
|
_ => {},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn select_edge(&mut self, x: f32, y: f32) {
|
fn select_edge(&mut self, x: f32, y: f32) {
|
||||||
let mut board = self.board.borrow_mut();
|
let mut board = self.board.borrow_mut();
|
||||||
if let Some(nearest_id) = board.nearest_node(x, y) {
|
if let Some(nearest_id) = board.nearest_node(x, y) {
|
||||||
match self.selected_node {
|
match self.selected_node {
|
||||||
None => self.selected_node = Some(nearest_id),
|
None => self.selected_node = Some(nearest_id),
|
||||||
Some(id) if id == nearest_id => self.selected_node = None,
|
Some(id) if id == nearest_id => self.selected_node = None,
|
||||||
Some(id) => board.add_edge(id, nearest_id),
|
Some(id) => board.add_edge(id, nearest_id),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn delete_node(&mut self, x: f32, y: f32) {
|
fn delete_node(&mut self, x: f32, y: f32) {
|
||||||
let mut board = self.board.borrow_mut();
|
let mut board = self.board.borrow_mut();
|
||||||
if let Some(nearest_id) = board.nearest_node(x, y) {
|
if let Some(nearest_id) = board.nearest_node(x, y) {
|
||||||
board.remove_node(nearest_id);
|
board.remove_node(nearest_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -235,14 +235,14 @@ struct CreateNodeDialog {
|
|||||||
|
|
||||||
impl CreateNodeDialog {
|
impl CreateNodeDialog {
|
||||||
fn show(&mut self, x: f32, y: f32) {
|
fn show(&mut self, x: f32, y: f32) {
|
||||||
self.open = true;
|
self.open = true;
|
||||||
self.x = x;
|
self.x = x;
|
||||||
self.y = y;
|
self.y = y;
|
||||||
self.name = String::new();
|
self.name = String::new();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn close(&mut self) {
|
fn close(&mut self) {
|
||||||
self.open = false;
|
self.open = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -323,7 +323,6 @@ enum StringDialogResponse {
|
|||||||
Accepted(String)
|
Accepted(String)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
impl StringDialog {
|
impl StringDialog {
|
||||||
fn show(&mut self) {
|
fn show(&mut self) {
|
||||||
self.open = true;
|
self.open = true;
|
||||||
@ -364,11 +363,11 @@ impl StringDialog {
|
|||||||
|
|
||||||
// impl EditNodeDialog {
|
// impl EditNodeDialog {
|
||||||
// fn show(&mut self, id: usize, board: &Board) {
|
// fn show(&mut self, id: usize, board: &Board) {
|
||||||
// self.open = true;
|
// self.open = true;
|
||||||
// let node = board.nodes.get(&id).unwrap();
|
// let node = board.nodes.get(&id).unwrap();
|
||||||
|
|
||||||
// self.id = id;
|
// self.id = id;
|
||||||
// self.name = node.name.clone();
|
// self.name = node.name.clone();
|
||||||
// self.labels = node.labels.clone();
|
// self.labels = node.labels.clone();
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
Loading…
Reference in New Issue
Block a user