Skip to content

Commit 465a56c

Browse files
committed
Styled UI colors; Compiles release candidate 2 to WASM
1 parent 096efa3 commit 465a56c

File tree

9 files changed

+47
-65
lines changed

9 files changed

+47
-65
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
[package]
22
name = "rust_graph_visualiser"
3-
version = "1.9.0"
3+
version = "1.9.2"
44
edition = "2021"
5+
authors = ["Sandra"]
6+
repository = "https://github.com/an-Iceberg/rust_graph_visualiser"
57

68
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
79

docs/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
event.preventDefault()
4242
}, false);
4343
</script>
44-
<script>load("rust_graph_visualiser@v1.0.0.wasm");</script>
44+
<script>load("rust_graph_visualiser@v1.9.2.wasm");</script>
4545
</body>
4646

4747
</html>
4.66 MB
Binary file not shown.

src/graph.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,6 @@ impl DijkstraGraph
239239
if !neighbour.visited
240240
{ unvisited_points.push(edge.destination); }
241241

242-
// TODO: if both are same then toss coin
243242
if neighbour.distance.is_none() || neighbour.distance.unwrap() > possibly_lower_goal || (neighbour.distance.unwrap() == possibly_lower_goal && rand::random())
244243
{
245244
neighbour.distance = Some(possibly_lower_goal);
@@ -440,7 +439,7 @@ impl DijkstraGraph
440439
self.add_line(13, 2, 1);
441440
self.add_line(15, 8, 10);
442441
self.add_line(14, 8, 14);
443-
self.add_line(1, 18, 10);
442+
self.add_line(1, 18, 10); // TODO: reduce length to 9
444443
self.add_line(17, 18, 3);
445444
self.add_line(16, 17, 2);
446445
self.add_line(7, 3, 1);

src/main.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,16 @@ pub(crate) enum Mode {
2727
Path,
2828
}
2929

30-
// TODO: extract some variables as const
3130
pub(crate) const VERSION: Option<&str> = option_env!("CARGO_PKG_VERSION");
31+
pub(crate) const AUTHORS: Option<&str> = option_env!("CARGO_PKG_AUTHORS");
3232
pub(crate) const UI_WIDTH: f32 = 200.;
3333
pub(crate) const PADDING: u8 = 3;
3434
pub(crate) const BG_COLOR: u32 = 0x400080;
3535
pub(crate) const PATH_COLOR: u32 = 0x00ff00;
36-
pub(crate) const LINE_COLOR: u32 = 0xff8000;
37-
pub(crate) const POINT_COLOR: u32 = 0x00ffff;
38-
pub(crate) const LINE_LENGTH_COLOR: u32 = 0xc0c0c0;
36+
pub(crate) const LINE_COLOR: u32 = 0x00c0c0;
37+
pub(crate) const POINT_COLOR: u32 = 0xff8000;
38+
pub(crate) const LINE_LENGTH_COLOR: u32 = 0xc09a9a;
39+
pub(crate) const UI_SPACE: f32 = 225.;
3940

4041
#[macroquad::main(window_configuration)]
4142
async fn main()

src/tests/graph_tests.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@ fn shortest_path_large_b()
310310
let mut graph = DijkstraGraph::new();
311311
graph.insert_large_graph();
312312

313+
// TODO: add second valid path
313314
let should_path = vec![6, 4, 1, 2, 16, 17, 18];
314315

315316
graph.set_start(6);

src/ui.rs

Lines changed: 34 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
use crate::{graph::DijkstraGraph, Mode, VERSION};
1+
use crate::{graph::DijkstraGraph, Mode, VERSION, AUTHORS, UI_SPACE};
2+
23
use egui_macroquad::{
3-
egui::{epaint::Shadow, Align2, Rounding, Slider, Vec2, Visuals, Window, Response, Ui, Sense, WidgetInfo, WidgetType, lerp, pos2, vec2, Widget},
4+
egui::{epaint::Shadow, Align2, Rounding, Slider, Vec2, Visuals, Window, Color32, Stroke},
45
ui,
56
};
6-
use macroquad::time::get_fps;
7+
78

89
// TODO: edit colour with hex values
910
// TODO: make colours editable
@@ -22,7 +23,6 @@ pub(crate) fn paint_ui(
2223
)
2324
{
2425
ui(|egui_context| {
25-
// Disabling all shadows
2626
egui_context.set_visuals(Visuals
2727
{
2828
window_shadow: Shadow::NONE,
@@ -33,19 +33,30 @@ pub(crate) fn paint_ui(
3333
sw: 10.,
3434
se: 0.,
3535
},
36+
window_fill: Color32::from_rgb(32, 0, 64),
37+
window_stroke: Stroke::new(2., Color32::from_rgb(0, 192, 192)),
38+
override_text_color: Some(Color32::from_rgb(216, 167, 215)),
39+
// widgets: Widgets::style(&self, response),
3640
..Default::default()
3741
});
3842

3943
// egui ❤ macroquad
4044
Window::new("Rust Graph Visualiser")
41-
.anchor(Align2::RIGHT_TOP, Vec2::new(0., 10.))
45+
.anchor(Align2::RIGHT_TOP, Vec2::new(-1.5, 10.))
4246
.constrain(true)
4347
.collapsible(false)
4448
.movable(false)
4549
.resizable(false)
4650
.fixed_size(Vec2::new(200., 0.))
4751
.show(egui_context, |ui|
4852
{
53+
ui.style_mut().visuals.widgets.inactive.weak_bg_fill = Color32::from_rgb(0, 64, 64);
54+
ui.style_mut().visuals.widgets.inactive.bg_fill = Color32::from_rgb(0, 64, 64);
55+
ui.style_mut().visuals.widgets.hovered.weak_bg_fill = Color32::from_rgb(0, 128, 128);
56+
ui.style_mut().visuals.widgets.hovered.bg_fill = Color32::from_rgb(0, 128, 128);
57+
ui.style_mut().visuals.widgets.active.weak_bg_fill = Color32::from_rgb(0, 192, 192);
58+
ui.style_mut().visuals.widgets.active.bg_fill = Color32::from_rgb(0, 192, 192);
59+
4960
ui.label("Select a mode:");
5061
ui.horizontal(|ui|
5162
{
@@ -78,10 +89,15 @@ pub(crate) fn paint_ui(
7889
Mode::Path =>
7990
{
8091
ui.separator();
81-
ui.add_enabled_ui(graph.start().is_some() && graph.end().is_some(), |ui|
92+
ui.horizontal(|ui|
8293
{
83-
if ui.button("Find shortest path").clicked()
84-
{ graph.find_shortest_path(); }
94+
ui.add_enabled_ui(graph.start().is_some() && graph.end().is_some(), |ui|
95+
{
96+
if ui.button("Find shortest path").clicked()
97+
{ graph.find_shortest_path(); }
98+
});
99+
if ui.button("Clear path").clicked()
100+
{ graph.clear_path(); }
85101
});
86102
/*
87103
ui.horizontal(|ui|
@@ -98,11 +114,11 @@ pub(crate) fn paint_ui(
98114

99115
ui.add_space(match (&mode, selected_point_id)
100116
{
101-
(Mode::Move, _) => 215.,
102-
(Mode::Line, None) => 182.,
103-
(Mode::Line, Some(_)) => 140.,
104-
(Mode::Point, _) => 201.,
105-
(Mode::Path, _) => 136.
117+
(Mode::Move, _) => UI_SPACE,
118+
(Mode::Line, None) => UI_SPACE-33.,
119+
(Mode::Line, Some(_)) => UI_SPACE-75.,
120+
(Mode::Point, _) => UI_SPACE-14.,
121+
(Mode::Path, _) => UI_SPACE-58.
106122
});
107123

108124
ui.separator();
@@ -126,6 +142,7 @@ pub(crate) fn paint_ui(
126142

127143
ui.horizontal(|ui|
128144
{
145+
// TODO: print angle as plain text
129146
ui.label("Angle:");
130147
ui.add_enabled_ui(false, |ui|
131148
{ ui.drag_angle(angle); });
@@ -169,11 +186,7 @@ pub(crate) fn paint_ui(
169186

170187
ui.separator();
171188

172-
ui.horizontal(|ui|
173-
{
174-
ui.label("Hexagons:");
175-
ui.add(toggle(hexagons));
176-
});
189+
ui.checkbox(hexagons, "Hexagons");
177190

178191
/*
179192
ui.separator();
@@ -199,48 +212,14 @@ pub(crate) fn paint_ui(
199212

200213
ui.separator();
201214

215+
// --- CREDITS (!important) ---
202216
ui.horizontal(|ui|
203217
{
204218
ui.label(format!("v{}", VERSION.unwrap_or("unknown")));
205219
ui.separator();
206-
ui.label(format!("FPS:{}", get_fps()));
220+
ui.label("Made by");
221+
ui.hyperlink_to(format!("{}", AUTHORS.unwrap_or("unknown")), "https://github.com/an-Iceberg");
207222
});
208223
});
209224
});
210225
}
211-
212-
fn toggle_ui(ui: &mut Ui, on: &mut bool) -> Response
213-
{
214-
let desired_size = ui.spacing().interact_size.y * vec2(2.0, 1.0);
215-
let (rect, mut response) = ui.allocate_exact_size(desired_size, Sense::click());
216-
if response.clicked()
217-
{
218-
*on = !*on;
219-
response.mark_changed();
220-
}
221-
response.widget_info(|| WidgetInfo::selected(WidgetType::Checkbox, *on, ""));
222-
223-
if ui.is_rect_visible(rect)
224-
{
225-
let how_on = ui.ctx().animate_bool(response.id, *on);
226-
let visuals = ui.style().interact_selectable(&response, *on);
227-
let rect = rect.expand(visuals.expansion);
228-
let radius = 0.5 * rect.height();
229-
ui.painter().rect(rect, radius, visuals.bg_fill, visuals.bg_stroke);
230-
let circle_x = lerp((rect.left() + radius)..=(rect.right() - radius), how_on);
231-
let center = pos2(circle_x, rect.center().y);
232-
ui.painter().circle(center, 0.75 * radius, visuals.bg_fill, visuals.fg_stroke);
233-
}
234-
235-
return response;
236-
}
237-
238-
// A wrapper that allows the more idiomatic usage pattern: `ui.add(toggle(&mut my_bool))`
239-
/// iOS-style toggle switch.
240-
///
241-
/// ## Example:
242-
/// ``` ignore
243-
/// ui.add(toggle(&mut my_bool));
244-
/// ```
245-
pub(crate) fn toggle(on: &mut bool) -> impl Widget + '_
246-
{ move |ui: &mut Ui| toggle_ui(ui, on) }

src/utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use macroquad::{
33
prelude::{
44
mouse_position, Color,
55
},
6-
shapes::{draw_circle, draw_rectangle, draw_circle_lines, draw_line, draw_triangle, draw_hexagon}, text::{get_text_center, draw_text, measure_text}, math::{Vec4, Vec2}, color::{YELLOW, BLACK, MAGENTA, GREEN, RED},
6+
shapes::{draw_circle, draw_rectangle, draw_circle_lines, draw_line, draw_triangle, draw_hexagon}, text::{get_text_center, draw_text, measure_text}, math::Vec2, color::{YELLOW, MAGENTA, GREEN},
77
};
88
use std::ops::{Div, Mul};
99
use crate::Mode;

0 commit comments

Comments
 (0)