1const BASE: u32 = 0xF0000;
6
7#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
8pub enum Icon {
9 Files = 0,
10 Search = 1,
11 Git = 2,
12 Settings = 3,
13 Folder = 4,
14 FolderOpen = 5,
15 File = 6,
16 ChevronRight = 7,
17 ChevronDown = 8,
18 Close = 9,
19 ReplaceAll = 10,
20 Globe = 11,
21 Check = 12,
22 Agents = 13,
23 Outline = 14,
24 Layers = 15,
26 ListBullet = 30,
28 ListNumber = 53,
29 ListTask = 16,
30 Quote = 17,
31 Code = 18,
32 Link = 19,
33 Table = 20,
34 Picture = 21,
35 Sigma = 22,
36 Rule = 23,
37 Comment = 24,
38 Export = 25,
39 Play = 26,
40 Cite = 27,
41 More = 28,
42 Diagram = 29,
43 Track = 31,
44 PlayAll = 32,
45 Stop = 33,
46 Restart = 34,
47 AddCell = 35,
48 AddText = 36,
49 Terminal = 37,
50 Diff = 38,
51 Replace = 39,
52 ArrowUp = 40,
53 ArrowDown = 41,
54 Maximize = 42,
56 Minimize = 43,
57 Panel = 44,
59 SymbolFunction = 45,
62 SymbolType = 46,
63 SymbolField = 47,
64 SymbolValue = 48,
65 Bell = 49,
67 Question = 50,
69 CircleCheck = 51,
70 CircleX = 52,
71 HidePane = 54,
75 HidePanel = 55,
78 ShowPane = 56,
80 Smile = 57,
82 Power = 58,
84 FolderFilled = 59,
90 FileRust = 60,
91 FilePython = 61,
92 FileMarkdown = 62,
93 FileGit = 63,
94 FileJson = 64,
95 FileConfig = 65,
96 FileCode = 66,
97 HideSidebar = 90,
100 ShowSidebar = 91,
103 AgentClaude = 67,
110 AgentCodex = 68,
111 AgentGemini = 69,
112 Program = 70,
113 AgentOpenCode = 71,
114 AgentCopilot = 72,
115 AgentCursor = 73,
116 Log = 92,
118 ChevronLeft = 93,
120}
121
122#[derive(Clone, Copy, Debug, PartialEq, Eq)]
124pub struct Piece {
125 pub icon: Icon,
126 pub width: u8,
127 pub height: u8,
128 pub column: u8,
129 pub row: u8,
130}
131
132impl Piece {
133 pub fn symbol(self) -> char {
134 let code = (self.icon as u32) << 8
135 | u32::from(self.width) << 6
136 | u32::from(self.height) << 4
137 | u32::from(self.column) << 2
138 | u32::from(self.row);
139 char::from_u32(BASE + code).expect("the private plane holds every code")
140 }
141
142 pub fn decode(symbol: &str) -> Option<Self> {
143 let mut chars = symbol.chars();
144 let code = (chars.next()? as u32).checked_sub(BASE)?;
145 if chars.next().is_some() || code >= 1 << 12 {
146 return None;
147 }
148 let icon = match code >> 8 {
149 0 => Icon::Files,
150 1 => Icon::Search,
151 2 => Icon::Git,
152 13 => Icon::Agents,
153 14 => Icon::Outline,
154 15 => Icon::Layers,
155 _ => Icon::Settings,
156 };
157 Some(Self {
158 icon,
159 width: (code >> 6 & 3) as u8,
160 height: (code >> 4 & 3) as u8,
161 column: (code >> 2 & 3) as u8,
162 row: (code & 3) as u8,
163 })
164 }
165
166 pub fn fallback(self) -> &'static str {
168 const ART: [[[&str; 3]; 2]; 7] = [
169 [["▛", "▀", "▜"], ["▙", "▄", "▟"]],
170 [["▞", "▀", "▚"], ["▚", "▄", "▟"]],
171 [["●", "─", "●"], ["●", "─", "╯"]],
172 [["▚", "▀", "▞"], ["▞", "▄", "▚"]],
173 [["▗", "▄", "▖"], ["▐", "█", "▌"]],
174 [["▪", "─", "─"], [" ", "▪", "─"]],
175 [["▗", "▀", "▖"], ["▝", "▀", "▘"]],
176 ];
177 let art = match self.icon {
178 Icon::Agents => 4,
179 Icon::Outline => 5,
180 Icon::Layers => 6,
181 other => (other as usize).min(3),
182 };
183 if self.width == 1 || self.height == 1 {
184 if self.column > 0 {
185 return " ";
186 }
187 return match self.icon {
188 Icon::Files => "▤",
189 Icon::Search => "⌕",
190 Icon::Git => "⎇",
191 Icon::Agents => "◉",
192 Icon::Outline => "≡",
193 Icon::Layers => "≋",
194 _ => "⚙",
195 };
196 }
197 ART[art][self.row.min(1) as usize][self.column.min(2) as usize]
198 }
199}
200
201type Point = (f32, f32);
202
203fn segment(p: Point, a: Point, b: Point) -> f32 {
204 let (dx, dy) = (b.0 - a.0, b.1 - a.1);
205 let t = (((p.0 - a.0) * dx + (p.1 - a.1) * dy) / (dx * dx + dy * dy)).clamp(0.0, 1.0);
206 ((p.0 - a.0 - t * dx).powi(2) + (p.1 - a.1 - t * dy).powi(2)).sqrt()
207}
208
209fn path(p: Point, points: &[Point]) -> f32 {
211 points
212 .windows(2)
213 .map(|pair| segment(p, pair[0], pair[1]))
214 .fold(f32::MAX, f32::min)
215}
216
217fn circle(p: Point, c: Point) -> f32 {
218 ((p.0 - c.0).powi(2) + (p.1 - c.1).powi(2)).sqrt()
219}
220
221fn ring(p: Point, c: Point, radius: f32) -> f32 {
223 (circle(p, c) - radius).abs()
224}
225
226fn rounded(p: Point, min: Point, max: Point, radius: f32) -> f32 {
228 let (cx, cy) = ((min.0 + max.0) / 2.0, (min.1 + max.1) / 2.0);
229 let (qx, qy) = (
230 (p.0 - cx).abs() - (max.0 - min.0) / 2.0 + radius,
231 (p.1 - cy).abs() - (max.1 - min.1) / 2.0 + radius,
232 );
233 let outside = (qx.max(0.0).powi(2) + qy.max(0.0).powi(2)).sqrt();
234 (outside + qx.max(qy).min(0.0) - radius).abs()
235}
236
237fn solid(p: Point, min: Point, max: Point, radius: f32) -> f32 {
239 let (cx, cy) = ((min.0 + max.0) / 2.0, (min.1 + max.1) / 2.0);
240 let (qx, qy) = (
241 (p.0 - cx).abs() - (max.0 - min.0) / 2.0 + radius,
242 (p.1 - cy).abs() - (max.1 - min.1) / 2.0 + radius,
243 );
244 let outside = (qx.max(0.0).powi(2) + qy.max(0.0).powi(2)).sqrt();
245 (outside + qx.max(qy).min(0.0) - radius).max(0.0)
246}
247
248fn disc(p: Point, c: Point, radius: f32) -> f32 {
250 (circle(p, c) - radius).max(0.0)
251}
252
253fn cut(fill: f32, line: f32, half: f32) -> f32 {
256 if line < half { f32::MAX } else { fill }
257}
258
259fn replace(p: Point) -> f32 {
262 rounded(p, (2.0, 14.0), (10.0, 22.0), 2.0)
263 .min(path(
264 p,
265 &[(6.0, 10.0), (6.0, 5.0), (6.9, 2.9), (9.0, 2.0), (10.0, 2.0)],
266 ))
267 .min(path(p, &[(3.0, 7.0), (6.0, 10.0), (9.0, 7.0)]))
268 .min(path(p, &[(14.0, 4.0), (14.6, 2.6), (16.0, 2.0)]))
269 .min(path(p, &[(16.0, 10.0), (14.6, 9.4), (14.0, 8.0)]))
270 .min(path(p, &[(20.0, 2.0), (21.4, 2.6), (22.0, 4.0)]))
271 .min(path(p, &[(22.0, 8.0), (21.4, 9.4), (20.0, 10.0)]))
272}
273
274fn half_stroke(icon: Icon) -> f32 {
277 match icon {
278 Icon::Files
279 | Icon::Search
280 | Icon::Git
281 | Icon::Settings
282 | Icon::Outline
283 | Icon::Layers
284 | Icon::File
285 | Icon::Folder
286 | Icon::FolderOpen
287 | Icon::ChevronRight
288 | Icon::ChevronLeft
289 | Icon::ChevronDown
290 | Icon::Close
291 | Icon::ArrowUp
292 | Icon::ArrowDown
293 | Icon::Replace
294 | Icon::Maximize
295 | Icon::Minimize
296 | Icon::SymbolFunction
297 | Icon::SymbolType
298 | Icon::SymbolField
299 | Icon::SymbolValue
300 | Icon::HidePane
301 | Icon::HidePanel
302 | Icon::ShowPane
303 | Icon::HideSidebar
304 | Icon::ShowSidebar
305 | Icon::ReplaceAll => 0.9,
306 Icon::Agents => 0.8,
307 Icon::AgentClaude => 1.3,
308 Icon::AgentCodex
309 | Icon::Program
310 | Icon::AgentOpenCode
311 | Icon::AgentCopilot
312 | Icon::AgentCursor => 1.0,
313 Icon::AgentGemini => 0.5,
314 Icon::Check => 1.7,
315 _ => 1.15,
316 }
317}
318
319pub fn inked(icon: Icon, u: f32, v: f32) -> bool {
322 let p = (u * 24.0, v * 24.0);
323 let distance = match icon {
324 Icon::Files => path(
326 p,
327 &[
328 (9.0, 18.0),
329 (7.6, 17.4),
330 (7.0, 16.0),
331 (7.0, 4.0),
332 (7.6, 2.6),
333 (9.0, 2.0),
334 (16.0, 2.0),
335 (20.0, 6.0),
336 (20.0, 16.0),
337 (19.4, 17.4),
338 (18.0, 18.0),
339 (9.0, 18.0),
340 ],
341 )
342 .min(path(
343 p,
344 &[
345 (20.0, 7.0),
346 (17.0, 7.0),
347 (15.6, 6.4),
348 (15.0, 5.0),
349 (15.0, 2.0),
350 ],
351 ))
352 .min(path(
353 p,
354 &[
355 (3.0, 7.6),
356 (3.0, 20.4),
357 (3.5, 21.5),
358 (4.6, 22.0),
359 (14.4, 22.0),
360 ],
361 )),
362 Icon::Search => ring(p, (11.0, 11.0), 7.0).min(segment(p, (16.65, 16.65), (20.0, 20.0))),
363 Icon::Git => {
364 let joint = (9.0, 9.0);
365 let quarter = p.0 >= joint.0 && p.1 >= joint.1;
366 let curve = if quarter {
367 ring(p, joint, 9.0)
368 } else {
369 f32::MAX
370 };
371 ring(p, (6.0, 18.0), 3.0)
372 .min(ring(p, (18.0, 6.0), 3.0))
373 .min(segment(p, (6.0, 3.0), (6.0, 15.0)))
374 .min(curve)
375 }
376 Icon::Settings => segment(p, (20.0, 7.0), (11.0, 7.0))
378 .min(segment(p, (14.0, 17.0), (5.0, 17.0)))
379 .min(ring(p, (17.0, 17.0), 3.0))
380 .min(ring(p, (7.0, 7.0), 3.0)),
381 Icon::Agents => rounded(p, (4.0, 8.5), (20.0, 20.5), 3.0)
382 .min(path(p, &[(12.0, 8.5), (12.0, 3.5), (8.5, 3.5)]))
383 .min(segment(p, (9.0, 13.0), (9.0, 15.5)))
384 .min(segment(p, (15.0, 13.0), (15.0, 15.5)))
385 .min(segment(p, (1.5, 14.5), (4.0, 14.5)))
386 .min(segment(p, (20.0, 14.5), (22.5, 14.5))),
387 Icon::File => path(
389 p,
390 &[
391 (15.0, 2.0),
392 (6.0, 2.0),
393 (4.6, 2.6),
394 (4.0, 4.0),
395 (4.0, 20.0),
396 (4.6, 21.4),
397 (6.0, 22.0),
398 (18.0, 22.0),
399 (19.4, 21.4),
400 (20.0, 20.0),
401 (20.0, 7.0),
402 (15.0, 2.0),
403 ],
404 )
405 .min(path(
406 p,
407 &[
408 (14.0, 2.0),
409 (14.0, 6.0),
410 (14.6, 7.4),
411 (16.0, 8.0),
412 (20.0, 8.0),
413 ],
414 )),
415 Icon::Folder => path(
416 p,
417 &[
418 (20.0, 20.0),
419 (21.4, 19.4),
420 (22.0, 18.0),
421 (22.0, 8.0),
422 (21.4, 6.6),
423 (20.0, 6.0),
424 (12.1, 6.0),
425 (10.4, 5.1),
426 (9.6, 3.9),
427 (7.9, 3.0),
428 (4.0, 3.0),
429 (2.6, 3.6),
430 (2.0, 5.0),
431 (2.0, 18.0),
432 (2.6, 19.4),
433 (4.0, 20.0),
434 (20.0, 20.0),
435 ],
436 ),
437 Icon::FolderOpen => path(
438 p,
439 &[
440 (6.0, 14.0),
441 (7.5, 11.1),
442 (9.2, 10.0),
443 (20.0, 10.0),
444 (21.9, 12.5),
445 (20.4, 18.5),
446 (18.5, 20.0),
447 (4.0, 20.0),
448 (2.6, 19.4),
449 (2.0, 18.0),
450 (2.0, 5.0),
451 (2.6, 3.6),
452 (4.0, 3.0),
453 (7.9, 3.0),
454 (9.6, 3.9),
455 (10.4, 5.1),
456 (12.1, 6.0),
457 (18.0, 6.0),
458 (19.4, 6.6),
459 (20.0, 8.0),
460 (20.0, 10.0),
461 ],
462 ),
463 Icon::Layers => path(
465 p,
466 &[
467 (12.0, 2.5),
468 (21.5, 7.5),
469 (12.0, 12.5),
470 (2.5, 7.5),
471 (12.0, 2.5),
472 ],
473 )
474 .min(path(p, &[(2.5, 12.5), (12.0, 17.5), (21.5, 12.5)]))
475 .min(path(p, &[(2.5, 17.0), (12.0, 22.0), (21.5, 17.0)])),
476 Icon::Outline => segment(p, (21.0, 6.0), (8.0, 6.0))
478 .min(segment(p, (21.0, 12.0), (13.0, 12.0)))
479 .min(segment(p, (21.0, 18.0), (13.0, 18.0)))
480 .min(path(
481 p,
482 &[
483 (3.0, 6.0),
484 (3.0, 10.0),
485 (3.6, 11.4),
486 (5.0, 12.0),
487 (8.0, 12.0),
488 ],
489 ))
490 .min(path(
491 p,
492 &[
493 (3.0, 10.0),
494 (3.0, 16.0),
495 (3.6, 17.4),
496 (5.0, 18.0),
497 (8.0, 18.0),
498 ],
499 )),
500 Icon::ListBullet => (circle(p, (5.0, 6.5)) - 0.4)
501 .min(circle(p, (5.0, 12.0)) - 0.4)
502 .min(circle(p, (5.0, 17.5)) - 0.4)
503 .min(segment(p, (9.5, 6.5), (20.5, 6.5)))
504 .min(segment(p, (9.5, 12.0), (20.5, 12.0)))
505 .min(segment(p, (9.5, 17.5), (20.5, 17.5))),
506 Icon::ListNumber => path(p, &[(3.8, 5.2), (5.4, 4.0), (5.4, 9.5)])
507 .min(path(
508 p,
509 &[
510 (3.6, 15.0),
511 (5.0, 13.8),
512 (6.8, 14.8),
513 (3.6, 19.8),
514 (7.2, 19.8),
515 ],
516 ))
517 .min(segment(p, (10.5, 6.8), (20.5, 6.8)))
518 .min(segment(p, (10.5, 16.8), (20.5, 16.8))),
519 Icon::ListTask => rounded(p, (4.0, 4.0), (20.0, 20.0), 3.5)
520 .min(path(p, &[(8.0, 12.2), (11.0, 15.2), (16.2, 9.0)])),
521 Icon::Quote => segment(p, (4.5, 5.0), (4.5, 19.0))
522 .min(segment(p, (9.5, 7.0), (20.5, 7.0)))
523 .min(segment(p, (9.5, 12.0), (20.5, 12.0)))
524 .min(segment(p, (9.5, 17.0), (16.5, 17.0))),
525 Icon::Code => path(p, &[(8.5, 6.5), (3.0, 12.0), (8.5, 17.5)])
526 .min(path(p, &[(15.5, 6.5), (21.0, 12.0), (15.5, 17.5)])),
527 Icon::Link => rounded(p, (2.5, 8.0), (13.5, 16.0), 4.0).min(rounded(
528 p,
529 (10.5, 8.0),
530 (21.5, 16.0),
531 4.0,
532 )),
533 Icon::Table => rounded(p, (3.0, 4.5), (21.0, 19.5), 2.5)
534 .min(segment(p, (3.0, 9.5), (21.0, 9.5)))
535 .min(segment(p, (3.0, 14.5), (21.0, 14.5)))
536 .min(segment(p, (12.0, 4.5), (12.0, 19.5))),
537 Icon::Track => path(
539 p,
540 &[
541 (4.0, 16.5),
542 (15.5, 5.0),
543 (19.0, 8.5),
544 (7.5, 20.0),
545 (4.0, 20.0),
546 (4.0, 16.5),
547 ],
548 )
549 .min(path(p, &[(13.0, 20.5), (21.0, 20.5)])),
550 Icon::Diagram => rounded(p, (2.5, 3.5), (10.0, 9.5), 1.5)
551 .min(rounded(p, (14.0, 3.5), (21.5, 9.5), 1.5))
552 .min(rounded(p, (14.0, 14.5), (21.5, 20.5), 1.5))
553 .min(path(p, &[(10.0, 6.5), (14.0, 6.5)]))
554 .min(path(p, &[(6.2, 9.5), (6.2, 17.5), (14.0, 17.5)])),
555 Icon::Picture => rounded(p, (3.0, 4.5), (21.0, 19.5), 2.5)
556 .min(ring(p, (8.5, 9.8), 1.5))
557 .min(path(
558 p,
559 &[
560 (3.5, 18.0),
561 (9.5, 12.8),
562 (13.5, 16.2),
563 (16.2, 13.8),
564 (20.5, 17.5),
565 ],
566 )),
567 Icon::Sigma => path(
568 p,
569 &[
570 (18.0, 7.5),
571 (18.0, 4.5),
572 (5.5, 4.5),
573 (12.5, 12.0),
574 (5.5, 19.5),
575 (18.0, 19.5),
576 (18.0, 16.5),
577 ],
578 ),
579 Icon::Rule => segment(p, (3.0, 12.0), (21.0, 12.0))
580 .min(segment(p, (8.0, 6.5), (16.0, 6.5)))
581 .min(segment(p, (8.0, 17.5), (16.0, 17.5))),
582 Icon::Comment => rounded(p, (3.0, 4.0), (21.0, 16.5), 3.5)
583 .min(path(p, &[(8.0, 16.5), (8.0, 20.5), (12.5, 16.5)])),
584 Icon::Export => path(p, &[(12.0, 3.5), (12.0, 15.0)])
585 .min(path(p, &[(7.0, 10.5), (12.0, 15.5), (17.0, 10.5)]))
586 .min(segment(p, (4.0, 20.0), (20.0, 20.0))),
587 Icon::Play => path(p, &[(7.0, 4.5), (19.5, 12.0), (7.0, 19.5), (7.0, 4.5)]),
588 Icon::PlayAll => path(p, &[(3.0, 5.5), (12.0, 12.0), (3.0, 18.5), (3.0, 5.5)]).min(path(
589 p,
590 &[(12.0, 5.5), (21.0, 12.0), (12.0, 18.5), (12.0, 5.5)],
591 )),
592 Icon::Stop => rounded(p, (6.0, 6.0), (18.0, 18.0), 1.5),
593 Icon::Restart => {
594 let angle = (p.1 - 12.0).atan2(p.0 - 12.0);
596 let gap = angle > -1.1 && angle < 0.1;
597 let arc = if gap {
598 f32::MAX
599 } else {
600 ring(p, (12.0, 12.0), 7.5)
601 };
602 arc.min(path(p, &[(19.5, 4.0), (19.5, 10.0), (13.8, 10.0)]))
603 }
604 Icon::AddCell => rounded(p, (3.0, 6.0), (21.0, 18.0), 2.0)
605 .min(segment(p, (12.0, 9.0), (12.0, 15.0)))
606 .min(segment(p, (9.0, 12.0), (15.0, 12.0))),
607 Icon::AddText => segment(p, (3.0, 6.0), (21.0, 6.0))
608 .min(segment(p, (3.0, 11.0), (13.0, 11.0)))
609 .min(segment(p, (3.0, 16.0), (10.0, 16.0)))
610 .min(segment(p, (18.0, 13.0), (18.0, 21.0)))
611 .min(segment(p, (14.0, 17.0), (22.0, 17.0))),
612 Icon::Cite => path(p, &[(9.0, 4.5), (5.5, 4.5), (5.5, 19.5), (9.0, 19.5)])
613 .min(path(
614 p,
615 &[(15.0, 4.5), (18.5, 4.5), (18.5, 19.5), (15.0, 19.5)],
616 ))
617 .min(segment(p, (12.0, 9.0), (12.0, 15.0))),
618 Icon::More => (circle(p, (5.0, 12.0)) - 0.5)
619 .min(circle(p, (12.0, 12.0)) - 0.5)
620 .min(circle(p, (19.0, 12.0)) - 0.5),
621 Icon::ChevronRight => path(p, &[(9.5, 6.5), (15.0, 12.0), (9.5, 17.5)]),
622 Icon::ChevronLeft => path(p, &[(14.5, 6.5), (9.0, 12.0), (14.5, 17.5)]),
623 Icon::ChevronDown => path(p, &[(6.5, 9.5), (12.0, 15.0), (17.5, 9.5)]),
624 Icon::Close => {
625 segment(p, (6.5, 6.5), (17.5, 17.5)).min(segment(p, (17.5, 6.5), (6.5, 17.5)))
626 }
627 Icon::Replace => replace(p),
628 Icon::ArrowUp => path(p, &[(5.0, 12.0), (12.0, 5.0), (19.0, 12.0)]).min(segment(
629 p,
630 (12.0, 5.0),
631 (12.0, 19.0),
632 )),
633 Icon::ArrowDown => path(p, &[(19.0, 12.0), (12.0, 19.0), (5.0, 12.0)]).min(segment(
634 p,
635 (12.0, 5.0),
636 (12.0, 19.0),
637 )),
638 Icon::ReplaceAll => replace(p)
639 .min(path(
640 p,
641 &[
642 (14.0, 14.0),
643 (15.4, 14.6),
644 (16.0, 16.0),
645 (16.0, 20.0),
646 (15.4, 21.4),
647 (14.0, 22.0),
648 ],
649 ))
650 .min(path(
651 p,
652 &[
653 (20.0, 14.0),
654 (21.4, 14.6),
655 (22.0, 16.0),
656 (22.0, 20.0),
657 (21.4, 21.4),
658 (20.0, 22.0),
659 ],
660 )),
661 Icon::Check => path(p, &[(4.5, 12.5), (9.5, 17.5), (19.5, 6.5)]),
662 Icon::HidePane => rounded(p, (3.0, 3.0), (21.0, 21.0), 2.0)
664 .min(segment(p, (15.0, 3.0), (15.0, 21.0)))
665 .min(solid(p, (15.0, 3.0), (21.0, 21.0), 2.0)),
666 Icon::HidePanel => rounded(p, (3.0, 3.0), (21.0, 21.0), 2.0)
667 .min(segment(p, (3.0, 15.0), (21.0, 15.0)))
668 .min(solid(p, (3.0, 15.0), (21.0, 21.0), 2.0)),
669 Icon::ShowPane => {
670 rounded(p, (3.0, 3.0), (21.0, 21.0), 2.0).min(segment(p, (15.0, 3.0), (15.0, 21.0)))
671 }
672 Icon::HideSidebar => rounded(p, (3.0, 3.0), (21.0, 21.0), 2.0)
674 .min(segment(p, (9.0, 3.0), (9.0, 21.0)))
675 .min(solid(p, (3.0, 3.0), (9.0, 21.0), 2.0)),
676 Icon::ShowSidebar => {
677 rounded(p, (3.0, 3.0), (21.0, 21.0), 2.0).min(segment(p, (9.0, 3.0), (9.0, 21.0)))
678 }
679 Icon::Maximize => path(p, &[(15.0, 3.0), (21.0, 3.0), (21.0, 9.0)])
680 .min(path(p, &[(9.0, 21.0), (3.0, 21.0), (3.0, 15.0)]))
681 .min(segment(p, (21.0, 3.0), (14.0, 10.0)))
682 .min(segment(p, (3.0, 21.0), (10.0, 14.0))),
683 Icon::Minimize => path(p, &[(4.0, 14.0), (10.0, 14.0), (10.0, 20.0)])
684 .min(path(p, &[(20.0, 10.0), (14.0, 10.0), (14.0, 4.0)]))
685 .min(segment(p, (14.0, 10.0), (21.0, 3.0)))
686 .min(segment(p, (3.0, 21.0), (10.0, 14.0))),
687 Icon::SymbolFunction => path(
689 p,
690 &[
691 (12.0, 2.5),
692 (20.5, 7.2),
693 (20.5, 16.8),
694 (12.0, 21.5),
695 (3.5, 16.8),
696 (3.5, 7.2),
697 (12.0, 2.5),
698 ],
699 )
700 .min(path(p, &[(3.8, 7.3), (12.0, 12.0), (20.2, 7.3)]))
701 .min(segment(p, (12.0, 12.0), (12.0, 21.5))),
702 Icon::SymbolType => path(
703 p,
704 &[
705 (8.5, 3.0),
706 (7.0, 3.0),
707 (5.5, 4.5),
708 (5.5, 10.0),
709 (3.5, 12.0),
710 (5.5, 14.0),
711 (5.5, 19.5),
712 (7.0, 21.0),
713 (8.5, 21.0),
714 ],
715 )
716 .min(path(
717 p,
718 &[
719 (15.5, 3.0),
720 (17.0, 3.0),
721 (18.5, 4.5),
722 (18.5, 10.0),
723 (20.5, 12.0),
724 (18.5, 14.0),
725 (18.5, 19.5),
726 (17.0, 21.0),
727 (15.5, 21.0),
728 ],
729 )),
730 Icon::SymbolField => {
731 rounded(p, (3.0, 7.5), (21.0, 16.5), 2.5).min(segment(p, (7.0, 12.0), (12.0, 12.0)))
732 }
733 Icon::SymbolValue => {
734 segment(p, (4.5, 9.0), (19.5, 9.0)).min(segment(p, (4.5, 15.0), (19.5, 15.0)))
735 }
736 Icon::Terminal => path(p, &[(3.5, 6.0), (10.0, 12.0), (3.5, 18.0)]).min(segment(
737 p,
738 (12.5, 18.0),
739 (20.5, 18.0),
740 )),
741 Icon::Panel => {
742 rounded(p, (3.0, 3.0), (21.0, 21.0), 4.0).min(segment(p, (3.0, 15.0), (21.0, 15.0)))
743 }
744 Icon::Diff => rounded(p, (3.0, 3.0), (21.0, 21.0), 4.0)
745 .min(segment(p, (12.0, 6.5), (12.0, 12.5)))
746 .min(segment(p, (9.0, 9.5), (15.0, 9.5)))
747 .min(segment(p, (9.0, 16.5), (15.0, 16.5))),
748 Icon::Bell => {
750 let dome = if p.1 <= 9.0 {
751 ring(p, (12.0, 9.0), 6.0)
752 } else {
753 f32::MAX
754 };
755 dome.min(path(
756 p,
757 &[(6.0, 9.0), (6.0, 12.5), (5.2, 15.4), (3.2, 17.5)],
758 ))
759 .min(path(
760 p,
761 &[(18.0, 9.0), (18.0, 12.5), (18.8, 15.4), (20.8, 17.5)],
762 ))
763 .min(segment(p, (3.2, 17.5), (20.8, 17.5)))
764 .min(path(p, &[(10.2, 20.8), (12.0, 21.8), (13.8, 20.8)]))
765 }
766 Icon::Question => ring(p, (12.0, 12.0), 9.5)
767 .min(path(
768 p,
769 &[
770 (9.3, 9.2),
771 (10.1, 7.6),
772 (12.0, 7.0),
773 (14.0, 7.7),
774 (14.8, 9.4),
775 (14.0, 11.0),
776 (12.0, 12.2),
777 (12.0, 13.6),
778 ],
779 ))
780 .min(circle(p, (12.0, 17.0)) - 0.4),
781 Icon::CircleCheck => {
782 ring(p, (12.0, 12.0), 9.5).min(path(p, &[(8.0, 12.3), (10.8, 15.0), (16.0, 9.5)]))
783 }
784 Icon::FolderFilled => {
786 solid(p, (3.0, 4.2), (10.5, 9.0), 1.6).min(solid(p, (3.0, 7.2), (21.0, 19.4), 2.0))
787 }
788 Icon::FileRust => {
790 let letter = segment(p, (9.0, 7.3), (9.0, 16.7))
791 .min(path(
792 p,
793 &[
794 (9.0, 7.3),
795 (12.6, 7.3),
796 (14.3, 8.0),
797 (15.0, 9.6),
798 (14.3, 11.2),
799 (12.6, 11.9),
800 (9.0, 11.9),
801 ],
802 ))
803 .min(segment(p, (12.4, 11.9), (15.3, 16.7)));
804 cut(disc(p, (12.0, 12.0), 9.2), letter, 0.95)
805 }
806 Icon::FilePython => {
808 let letter = segment(p, (9.4, 7.3), (9.4, 16.7)).min(path(
809 p,
810 &[
811 (9.4, 7.3),
812 (12.9, 7.3),
813 (14.7, 8.1),
814 (15.4, 9.9),
815 (14.7, 11.7),
816 (12.9, 12.5),
817 (9.4, 12.5),
818 ],
819 ));
820 cut(disc(p, (12.0, 12.0), 9.2), letter, 0.95)
821 }
822 Icon::FileMarkdown => path(
824 p,
825 &[
826 (2.5, 17.0),
827 (2.5, 7.0),
828 (7.0, 12.5),
829 (11.5, 7.0),
830 (11.5, 17.0),
831 ],
832 )
833 .min(segment(p, (18.0, 7.5), (18.0, 16.5)))
834 .min(path(p, &[(14.5, 13.0), (18.0, 16.5), (21.5, 13.0)])),
835 Icon::FileGit => {
837 let across = (p.0 - 12.0).abs() + (p.1 - 12.0).abs();
838 let diamond = ((across - 9.6) * std::f32::consts::FRAC_1_SQRT_2).max(0.0);
839 cut(diamond, circle(p, (12.0, 12.0)), 2.7)
840 }
841 Icon::FileJson => {
843 let brace = |side: f32| {
844 let x = |from: f32| 12.0 + side * (from - 12.0);
845 path(
846 p,
847 &[
848 (x(9.0), 4.0),
849 (x(7.2), 4.5),
850 (x(6.4), 6.2),
851 (x(6.4), 9.6),
852 (x(5.6), 11.3),
853 (x(3.8), 12.0),
854 (x(5.6), 12.7),
855 (x(6.4), 14.4),
856 (x(6.4), 17.8),
857 (x(7.2), 19.5),
858 (x(9.0), 20.0),
859 ],
860 )
861 };
862 brace(1.0).min(brace(-1.0))
863 }
864 Icon::FileConfig => path(p, &[(8.0, 4.0), (5.0, 4.0), (5.0, 20.0), (8.0, 20.0)])
866 .min(path(
867 p,
868 &[(16.0, 4.0), (19.0, 4.0), (19.0, 20.0), (16.0, 20.0)],
869 ))
870 .min(segment(p, (9.6, 9.8), (14.4, 9.8)))
871 .min(segment(p, (9.6, 14.2), (14.4, 14.2))),
872 Icon::FileCode => path(p, &[(8.0, 7.5), (3.5, 12.0), (8.0, 16.5)])
874 .min(path(p, &[(16.0, 7.5), (20.5, 12.0), (16.0, 16.5)]))
875 .min(segment(p, (13.6, 5.5), (10.4, 18.5))),
876 Icon::Power => {
878 let open = if p.1 >= 6.4 {
879 ring(p, (12.0, 13.0), 9.0)
880 } else {
881 f32::MAX
882 };
883 open.min(segment(p, (12.0, 2.0), (12.0, 12.0)))
884 }
885 Icon::AgentClaude => segment(p, (12.0, 3.5), (12.0, 20.5))
887 .min(segment(p, (3.5, 12.0), (20.5, 12.0)))
888 .min(segment(p, (6.0, 6.0), (18.0, 18.0)))
889 .min(segment(p, (18.0, 6.0), (6.0, 18.0))),
890 Icon::AgentCodex => path(
892 p,
893 &[
894 (12.0, 2.5),
895 (20.3, 7.25),
896 (20.3, 16.75),
897 (12.0, 21.5),
898 (3.7, 16.75),
899 (3.7, 7.25),
900 (12.0, 2.5),
901 ],
902 )
903 .min(path(p, &[(9.2, 9.6), (11.8, 12.0), (9.2, 14.4)]))
904 .min(segment(p, (13.4, 14.4), (15.4, 14.4))),
905 Icon::AgentGemini => {
907 let (x, y) = (((p.0 - 12.0) / 10.0).abs(), ((p.1 - 12.0) / 10.0).abs());
908 if x.powf(0.75) + y.powf(0.75) <= 1.0 {
909 0.0
910 } else {
911 f32::MAX
912 }
913 }
914 Icon::Program => solid(p, (5.0, 5.0), (19.0, 19.0), 3.5),
916 Icon::AgentOpenCode => cut(
918 solid(p, (5.0, 5.0), (19.0, 19.0), 3.5),
919 ring(p, (12.0, 12.0), 3.6),
920 1.15,
921 ),
922 Icon::AgentCopilot => {
924 let (dx, dy) = (p.0 - 12.0, p.1 - 12.0);
925 let open = dx > 0.0 && dy.abs() < dx * 0.9;
926 let letter = if open {
927 f32::MAX
928 } else {
929 ring(p, (12.0, 12.0), 3.6)
930 };
931 cut(solid(p, (5.0, 5.0), (19.0, 19.0), 3.5), letter, 1.15)
932 }
933 Icon::AgentCursor => {
936 let arrow = [
937 (8.6, 7.0),
938 (8.6, 16.6),
939 (11.0, 14.4),
940 (12.8, 18.0),
941 (14.6, 17.2),
942 (12.8, 13.6),
943 (16.0, 13.4),
944 ];
945 let inside =
946 arrow
947 .iter()
948 .zip(arrow.iter().cycle().skip(1))
949 .fold(false, |inside, (a, b)| {
950 let crosses = (a.1 > p.1) != (b.1 > p.1)
951 && p.0 < (b.0 - a.0) * (p.1 - a.1) / (b.1 - a.1) + a.0;
952 inside != crosses
953 });
954 if inside {
955 f32::MAX
956 } else {
957 solid(p, (5.0, 5.0), (19.0, 19.0), 3.5)
958 }
959 }
960 Icon::Log => segment(p, (4.0, 5.5), (20.0, 5.5))
961 .min(segment(p, (4.0, 10.0), (15.0, 10.0)))
962 .min(segment(p, (4.0, 14.5), (18.0, 14.5)))
963 .min(segment(p, (4.0, 19.0), (11.0, 19.0))),
964 Icon::Smile => ring(p, (12.0, 12.0), 9.5)
965 .min(circle(p, (9.0, 9.6)) - 0.35)
966 .min(circle(p, (15.0, 9.6)) - 0.35)
967 .min(path(
968 p,
969 &[
970 (8.0, 14.0),
971 (9.6, 15.5),
972 (12.0, 16.1),
973 (14.4, 15.5),
974 (16.0, 14.0),
975 ],
976 )),
977 Icon::CircleX => ring(p, (12.0, 12.0), 9.5)
978 .min(segment(p, (8.8, 8.8), (15.2, 15.2)))
979 .min(segment(p, (15.2, 8.8), (8.8, 15.2))),
980 Icon::Globe => {
981 let (x, y) = ((p.0 - 12.0) / 4.5, (p.1 - 12.0) / 9.5);
982 let meridian = ((x * x + y * y).sqrt() - 1.0).abs() * 4.5;
983 ring(p, (12.0, 12.0), 9.5)
984 .min(meridian)
985 .min(segment(p, (2.5, 12.0), (21.5, 12.0)))
986 }
987 };
988 distance < half_stroke(icon)
989}
990
991#[cfg(test)]
992mod tests {
993 use super::*;
994
995 #[test]
996 fn pieces_survive_the_grid() {
997 for icon in [
998 Icon::Files,
999 Icon::Search,
1000 Icon::Git,
1001 Icon::Settings,
1002 Icon::Layers,
1003 ] {
1004 let piece = Piece {
1005 icon,
1006 width: 3,
1007 height: 2,
1008 column: 2,
1009 row: 1,
1010 };
1011 let text = piece.symbol().to_string();
1012 assert_eq!(Piece::decode(&text), Some(piece));
1013 }
1014 assert_eq!(Piece::decode("a"), None);
1015 }
1016
1017 #[test]
1018 fn every_icon_has_ink() {
1019 for icon in [
1020 Icon::Files,
1021 Icon::Search,
1022 Icon::Git,
1023 Icon::Settings,
1024 Icon::Agents,
1025 Icon::Layers,
1026 Icon::Folder,
1027 Icon::File,
1028 Icon::Maximize,
1029 Icon::Minimize,
1030 Icon::Panel,
1031 Icon::SymbolFunction,
1032 Icon::SymbolType,
1033 Icon::SymbolField,
1034 Icon::SymbolValue,
1035 Icon::Bell,
1036 Icon::Question,
1037 Icon::CircleCheck,
1038 Icon::CircleX,
1039 Icon::HidePane,
1040 Icon::HidePanel,
1041 Icon::ShowPane,
1042 Icon::HideSidebar,
1043 Icon::ShowSidebar,
1044 Icon::Smile,
1045 Icon::Power,
1046 Icon::FolderFilled,
1047 Icon::FileRust,
1048 Icon::FilePython,
1049 Icon::FileMarkdown,
1050 Icon::FileGit,
1051 Icon::FileJson,
1052 Icon::FileConfig,
1053 Icon::FileCode,
1054 Icon::Log,
1055 Icon::AgentClaude,
1056 Icon::AgentCodex,
1057 Icon::AgentGemini,
1058 Icon::Program,
1059 Icon::AgentOpenCode,
1060 Icon::AgentCopilot,
1061 Icon::AgentCursor,
1062 ] {
1063 let dots = (0..50)
1064 .flat_map(|y| (0..50).map(move |x| (x, y)))
1065 .filter(|(x, y)| inked(icon, *x as f32 / 50.0, *y as f32 / 50.0))
1066 .count();
1067 assert!(dots > 150, "{icon:?} has {dots}");
1068 }
1069 }
1070}