Skip to content

Commit 90cfdb8

Browse files
committed
Add color code to step and arrows so it can be followed easier.
1 parent b908a2b commit 90cfdb8

File tree

5 files changed

+60
-15
lines changed

5 files changed

+60
-15
lines changed

src/main.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ fn App() -> Element {
4949
rsx! {
5050
document::Link { rel: "stylesheet", href: STYLE }
5151
div {
52+
h2 { "Solo-Chess Solver" }
5253
div {
5354
class: "board-stack",
5455
Chessboard {
@@ -60,6 +61,15 @@ fn App() -> Element {
6061
}
6162
PieceSelectionBoard { selected: selected_piece }
6263
Solution { steps }
64+
div {
65+
h2 { "Rules" }
66+
p { "From chess.com: "}
67+
ul {
68+
li { "Capture a piece with every move until just one remains" }
69+
li { "No piece may capture more than 2 times per puzzle (shown in black if cannot move)" }
70+
li { "If there is a King on the board, it must be the final piece" }
71+
}
72+
}
6373
}
6474
}
6575
}

src/ui.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ pub mod chessboard;
22
pub mod piece_selection;
33
pub mod solution;
44
pub mod step_arrows;
5+
pub mod step_colors;

src/ui/solution.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,22 @@
11
use dioxus::prelude::*;
22

33
use crate::step::Step;
4+
use crate::ui::step_colors::STEP_COLORS;
45

56
#[component]
67
pub fn Solution(steps: Vec<Step>) -> Element {
7-
let sans = to_sans(&steps).join(" ");
8+
let sans = to_sans(&steps);
89
rsx! {
9-
p { {sans} }
10+
p {
11+
strong { "Steps: " }
12+
for (idx, step) in sans.iter().enumerate() {
13+
span {
14+
key: "{idx}",
15+
style: "color: {STEP_COLORS[idx % STEP_COLORS.len()]};",
16+
"{step} "
17+
}
18+
}
19+
}
1020
}
1121
}
1222

src/ui/step_arrows.rs

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use dioxus::prelude::*;
22

33
use crate::step::Step;
4+
use crate::ui::step_colors::STEP_COLORS;
45

56
#[component]
67
pub fn StepArrows(steps: Vec<Step>) -> Element {
@@ -10,18 +11,20 @@ pub fn StepArrows(steps: Vec<Step>) -> Element {
1011
view_box: "0 0 8 8",
1112
preserve_aspect_ratio: "none",
1213
defs {
13-
marker {
14-
id: "arrowhead",
15-
marker_units: "strokeWidth",
16-
marker_width: "4",
17-
marker_height: "4",
18-
ref_x: "9",
19-
ref_y: "5",
20-
orient: "auto",
21-
view_box: "0 0 10 10",
22-
path {
23-
d: "M 0 0 L 10 5 L 0 10 z",
24-
style: "fill: var(--step-arrow); fill-opacity: var(--step-arrow-opacity);",
14+
for (idx, color) in STEP_COLORS.iter().enumerate() {
15+
marker {
16+
id: "arrowhead-{idx}",
17+
marker_units: "strokeWidth",
18+
marker_width: "4",
19+
marker_height: "4",
20+
ref_x: "9",
21+
ref_y: "5",
22+
orient: "auto",
23+
view_box: "0 0 10 10",
24+
path {
25+
d: "M 0 0 L 10 5 L 0 10 z",
26+
style: "fill: {color}; fill-opacity: var(--step-arrow-opacity);",
27+
}
2528
}
2629
}
2730
}
@@ -32,14 +35,23 @@ pub fn StepArrows(steps: Vec<Step>) -> Element {
3235
line {
3336
key: "{idx}",
3437
class: "step-arrow",
38+
style: "stroke: {step_color(idx)};",
3539
x1: "{(fc as f32) + 0.5}",
3640
y1: "{(fr as f32) + 0.5}",
3741
x2: "{(tc as f32) + 0.5}",
3842
y2: "{(tr as f32) + 0.5}",
39-
marker_end: "url(#arrowhead)",
43+
marker_end: "url(#arrowhead-{color_index(idx)})",
4044
}
4145
}
4246
}
4347
}
4448
}
4549
}
50+
51+
fn color_index(idx: usize) -> usize {
52+
idx % STEP_COLORS.len()
53+
}
54+
55+
fn step_color(idx: usize) -> &'static str {
56+
STEP_COLORS[color_index(idx)]
57+
}

src/ui/step_colors.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
pub const STEP_COLORS: [&str; 10] = [
2+
"#e6194b",
3+
"#f58231",
4+
"#ffe119",
5+
"#3cb44b",
6+
"#42d4f4",
7+
"#4363d8",
8+
"#911eb4",
9+
"#f032e6",
10+
"#bfef45",
11+
"#fabebe",
12+
];

0 commit comments

Comments
 (0)