Can turn on a "horizontal wrap" setting
This commit is contained in:
@@ -3,10 +3,9 @@ name = "board-builder-gui"
|
||||
version = "1.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
board-builder = { path = "../" }
|
||||
eframe = "0.18.0"
|
||||
rfd = "0.8.2"
|
||||
image = "0.24.2"
|
||||
image = "0.24.2"
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ use image::DynamicImage;
|
||||
|
||||
use rfd::FileDialog;
|
||||
|
||||
use board_builder::{ Board, Node, CoordTransformer, read_board_from_file, write_board_to_file };
|
||||
use board_builder::{ Board, Node, CoordTransformer, read_board_from_file, write_board_to_file, should_wrap_horizontal };
|
||||
|
||||
use std::path::Path;
|
||||
use std::collections::HashSet;
|
||||
@@ -29,6 +29,7 @@ struct BoardBuilderApp {
|
||||
create_node_dialog: CreateNodeDialog,
|
||||
edit_node_dialog: EditNodeDialog,
|
||||
edit_labels_dialog: EditLabelsDialog,
|
||||
edit_settings_dialog: EditSettingsDialog,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
@@ -93,7 +94,10 @@ impl eframe::App for BoardBuilderApp {
|
||||
if ui.button("Edit Labels...").clicked() {
|
||||
self.edit_labels_dialog.show(Rc::clone(&self.board));
|
||||
}
|
||||
})
|
||||
});
|
||||
if ui.button("Settings...").clicked() {
|
||||
self.edit_settings_dialog.show(Rc::clone(&self.board));
|
||||
};
|
||||
});
|
||||
});
|
||||
CentralPanel::default().show(ctx, |ui| {
|
||||
@@ -121,6 +125,7 @@ impl eframe::App for BoardBuilderApp {
|
||||
self.create_node_dialog.ui(ctx);
|
||||
self.edit_node_dialog.ui(ctx);
|
||||
self.edit_labels_dialog.ui(ctx);
|
||||
self.edit_settings_dialog.ui(ctx);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -169,10 +174,25 @@ impl BoardBuilderApp {
|
||||
let stroke = Stroke { width: 1.0, color: Color32::BLACK };
|
||||
for edge in &node.edges {
|
||||
let other_node = &board.nodes[edge];
|
||||
painter.line_segment(
|
||||
[view.inv_xform(node.x, node.y), view.inv_xform(other_node.x, other_node.y)],
|
||||
stroke,
|
||||
);
|
||||
if board.config.horizontal_wrapping && should_wrap_horizontal(node, other_node) {
|
||||
let mut nodes = [node, other_node];
|
||||
nodes.sort_by(|a, b| a.x.partial_cmp(&b.x).unwrap());
|
||||
let [left_node, right_node] = nodes;
|
||||
let y_mid = (left_node.y + right_node.y) / 2.0;
|
||||
painter.line_segment(
|
||||
[view.inv_xform(0.0, y_mid), view.inv_xform(left_node.x, left_node.y)],
|
||||
stroke
|
||||
);
|
||||
painter.line_segment(
|
||||
[view.inv_xform(right_node.x, right_node.y), view.inv_xform(1.0, y_mid)],
|
||||
stroke
|
||||
);
|
||||
} else {
|
||||
painter.line_segment(
|
||||
[view.inv_xform(node.x, node.y), view.inv_xform(other_node.x, other_node.y)],
|
||||
stroke,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -364,7 +384,6 @@ impl EditLabelsDialog {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#[derive(Default)]
|
||||
struct StringDialog {
|
||||
string: String,
|
||||
@@ -422,3 +441,26 @@ fn node_common_ui(ui: &mut Ui, node: &mut Node, board: &Board) {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
struct EditSettingsDialog {
|
||||
open: bool,
|
||||
board: Rc<RefCell<Board>>
|
||||
}
|
||||
|
||||
impl EditSettingsDialog {
|
||||
fn show(&mut self, board: Rc<RefCell<Board>>) {
|
||||
self.board = board;
|
||||
self.open = true;
|
||||
}
|
||||
|
||||
fn ui(&mut self, ctx: &Context) {
|
||||
Window::new("Settings")
|
||||
.collapsible(false)
|
||||
.open(&mut self.open)
|
||||
.show(ctx, |ui| {
|
||||
let mut board = self.board.borrow_mut();
|
||||
ui.checkbox(&mut board.config.horizontal_wrapping, "Horizontal Wrapping");
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user