Skip to content

Commit 8c72746

Browse files
committed
Finished egui integration
1 parent f88f97b commit 8c72746

File tree

8 files changed

+101
-180
lines changed

8 files changed

+101
-180
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
**rls/
22
*.o
3-
**.vscode/
3+
# **.vscode/
44

55
# Generated by Cargo
66
# will have compiled files and executables

.vscode/launch.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@
9595
"name": "Vite",
9696
"type": "f5anything",
9797
"request": "launch",
98-
"command": "vite ${workspaceFolder}/dist",
98+
"command": "vite ${workspaceFolder}/docs",
9999
"terminalName": "Vite",
100100
"showTerminal": true
101101
},

docs/gl.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

docs/index.html

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<!DOCTYPE html>
22
<html lang="en">
3+
34
<head>
45
<meta charset="UTF-8">
56
<meta http-equiv="X-UA-Compatible" content="IE=edge">
@@ -25,20 +26,22 @@
2526
width: 1290px;
2627
height: 720px;
2728
}
28-
</style>
29+
</style>
2930
</head>
31+
3032
<body>
3133
<canvas id="glcanvas" tabindex='1'></canvas>
3234

3335
<!-- Minified and statically hosted version of https://github.com/not-fl3/miniquad/blob/master/native/sapp-wasm/js/gl.js -->
34-
<script src="gl.js"></script>
36+
<script src="mq_js_bundle.js"></script>
3537

3638
<script>
3739
// Disables the right click menu in browsers
38-
document.querySelector('html').addEventListener('contextmenu', function(event) {
40+
document.querySelector('html').addEventListener('contextmenu', function (event) {
3941
event.preventDefault()
4042
}, false);
4143
</script>
4244
<script>load("rust_graph_visualiser.wasm");</script>
4345
</body>
46+
4447
</html>

docs/mq_js_bundle.js

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/rust_graph_visualiser.wasm

-14.8 MB
Binary file not shown.

src/graph.rs

Lines changed: 35 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::{draw_pill, utils};
22
use macroquad::{
3-
prelude::{mouse_position, Color, IVec2, BLACK, GREEN, MAGENTA, ORANGE, WHITE, YELLOW},
3+
prelude::{mouse_position, Color, IVec2, Vec4, BLACK, GREEN, MAGENTA, YELLOW},
44
shapes::{draw_circle, draw_circle_lines, draw_line, draw_triangle},
55
text::{draw_text, get_text_center, measure_text},
66
};
@@ -19,14 +19,13 @@ pub(crate) struct Graph {
1919
pub(crate) end: Option<u8>,
2020

2121
/// This is the id of the point that the mouse is currently hovering over
22-
pub hovered_point_id: Option<u8>,
22+
pub(crate) hovered_point_id: Option<u8>,
2323

2424
/// This is the id of the point the mouse is currently hovering over and mouse 1 is pressed
2525
pub(crate) selected_point_id: Option<u8>,
2626

2727
has_hovered_point_been_checked: bool,
2828
max_amount_of_points: u16,
29-
pub radius: u8,
3029
padding: u8,
3130

3231
/// Contains all data for the points
@@ -48,8 +47,16 @@ pub(crate) struct Graph {
4847
/// The 0th element is the start, the last element is the end
4948
path: Option<Vec<u8>>,
5049

51-
pub angle: f32,
52-
pub arrow_head_length: f32,
50+
/// User adjustable visuals
51+
pub(crate) angle: f32,
52+
pub(crate) arrow_head_length: f32,
53+
pub(crate) radius: u8,
54+
pub(crate) line_length: u16,
55+
pub(crate) path_thickness: f32,
56+
pub(crate) base_point: f32,
57+
pub(crate) path_color: [f32; 3],
58+
pub(crate) line_color: [f32; 3],
59+
pub(crate) point_color: [f32; 3],
5360
}
5461

5562
impl Default for Graph {
@@ -67,7 +74,13 @@ impl Default for Graph {
6774
lines: HashMap::<Line, u16>::new(),
6875
path: None,
6976
angle: 0.436,
70-
arrow_head_length: 20.0,
77+
arrow_head_length: 20.,
78+
line_length: 1,
79+
path_thickness: 2.,
80+
base_point: 15.,
81+
path_color: [0., 1., 0.],
82+
point_color: [1., 0.5, 0.],
83+
line_color: [0., 1., 1.],
7184
};
7285
}
7386
}
@@ -135,7 +148,7 @@ impl Graph {
135148
}
136149

137150
/// Adds a line; if it already exists, the length gets updated
138-
pub fn add_line(&mut self, from_id: u8, to_id: u8, line_length: u16) {
151+
pub fn add_line(&mut self, from_id: u8, to_id: u8) {
139152
let new_line = Line {
140153
from: from_id,
141154
to: to_id,
@@ -145,11 +158,11 @@ impl Graph {
145158
.lines
146159
.get_mut(&new_line)
147160
{
148-
Some(length) => *length = line_length,
161+
Some(length) => *length = self.line_length,
149162
None => {
150163
_ = self
151164
.lines
152-
.insert(new_line, line_length)
165+
.insert(new_line, self.line_length)
153166
},
154167
}
155168

@@ -395,8 +408,8 @@ impl Graph {
395408
to_point
396409
.position
397410
.y as f32,
398-
2.0,
399-
WHITE,
411+
self.path_thickness,
412+
Color::from_vec(Vec4::new(self.path_color[0], self.path_color[1], self.path_color[2], 1.)),
400413
);
401414
}
402415
}
@@ -416,7 +429,11 @@ impl Graph {
416429
.position
417430
.y as f32,
418431
self.radius as f32,
419-
if self.selected_point_id == Some(*id) { YELLOW } else { ORANGE },
432+
if self.selected_point_id == Some(*id) {
433+
YELLOW
434+
} else {
435+
Color::from_vec(Vec4::new(self.point_color[0], self.point_color[1], self.point_color[2], 1.))
436+
},
420437
);
421438

422439
let text_center = get_text_center(
@@ -529,26 +546,20 @@ impl Graph {
529546
.position
530547
.x
531548
+ (direction.x as f32
532-
* ((self.radius + 15) as f32
549+
* ((self.radius as f32 + self.base_point)
533550
/ direction
534551
.as_vec2()
535552
.length())) as i32,
536553
y: to_point
537554
.position
538555
.y
539556
+ (direction.y as f32
540-
* ((self.radius + 15) as f32
557+
* ((self.radius as f32 + self.base_point)
541558
/ direction
542559
.as_vec2()
543560
.length())) as i32,
544561
};
545562

546-
/*
547-
// The angle is in radians
548-
let angle: f32 = 0.436;
549-
let arrow_head_length = 20.0;
550-
*/
551-
552563
// Calculating the tip of the triangle that touches the node (position + (direction * (radius / length)))
553564
draw_line(
554565
from_point
@@ -570,7 +581,7 @@ impl Graph {
570581
arrow_head_location.x as f32,
571582
arrow_head_location.y as f32,
572583
1.0,
573-
Color::from_rgba(0, 255, 255, 255),
584+
Color::from_vec(Vec4::new(self.line_color[0], self.line_color[1], self.line_color[2], 1.)),
574585
);
575586

576587
/*
@@ -640,7 +651,7 @@ impl Graph {
640651
.sin()))) as i32,
641652
}
642653
.as_vec2(),
643-
Color::from_rgba(0, 255, 255, 255),
654+
Color::from_vec(Vec4::new(self.line_color[0], self.line_color[1], self.line_color[2], 1.)),
644655
);
645656

646657
// Right arrow head wing
@@ -696,7 +707,7 @@ impl Graph {
696707
.sin()))) as i32,
697708
}
698709
.as_vec2(),
699-
Color::from_rgba(0, 255, 255, 255),
710+
Color::from_vec(Vec4::new(self.line_color[0], self.line_color[1], self.line_color[2], 1.)),
700711
);
701712
},
702713

@@ -772,7 +783,7 @@ impl Graph {
772783
+ self
773784
.padding
774785
.mul(2) as f32,
775-
Color::from_rgba(0, 255, 255, 255),
786+
Color::from_vec(Vec4::new(self.line_color[0], self.line_color[1], self.line_color[2], 1.)),
776787
);
777788

778789
draw_text(

0 commit comments

Comments
 (0)