Skip to main content

cellix_render/
icon.rs

1//! Interface icons. A font glyph is one cell and looks tiny beside a real IDE, so icons
2//! span several cells: the pixel tier draws them as shapes, and the cell tier as block art.
3
4/// Base of the Unicode private plane used to carry icon pieces through the grid.
5const 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    /// Sheets stacked: what an agent's context is built from.
25    Layers = 15,
26    // The document toolbar's, which only ever appear as paint.
27    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    /// Lucide's maximize-2 and minimize-2: arrows out to two corners, and back in.
55    Maximize = 42,
56    Minimize = 43,
57    /// Lucide's panel-bottom: a window with a panel along its foot.
58    Panel = 44,
59    /// A symbol's kind, as Go to Symbol lists them: a cube for a function or method, braces
60    /// for a type, a bar for a field, and two lines for a constant, variable or module.
61    SymbolFunction = 45,
62    SymbolType = 46,
63    SymbolField = 47,
64    SymbolValue = 48,
65    /// What waits for the person.
66    Bell = 49,
67    /// The inbox's marks for what's waiting: asking, done, failed.
68    Question = 50,
69    CircleCheck = 51,
70    CircleX = 52,
71    /// A window with its right part filled, as VS Code's title bar has: the side pane
72    /// shown, and the button that hides it. Not an ×, so the only × in the corner quits.
73    HidePane = 54,
74}
75
76/// One cell of an icon that is `width` by `height` cells.
77#[derive(Clone, Copy, Debug, PartialEq, Eq)]
78pub struct Piece {
79    pub icon: Icon,
80    pub width: u8,
81    pub height: u8,
82    pub column: u8,
83    pub row: u8,
84}
85
86impl Piece {
87    pub fn symbol(self) -> char {
88        let code = (self.icon as u32) << 8
89            | u32::from(self.width) << 6
90            | u32::from(self.height) << 4
91            | u32::from(self.column) << 2
92            | u32::from(self.row);
93        char::from_u32(BASE + code).expect("the private plane holds every code")
94    }
95
96    pub fn decode(symbol: &str) -> Option<Self> {
97        let mut chars = symbol.chars();
98        let code = (chars.next()? as u32).checked_sub(BASE)?;
99        if chars.next().is_some() || code >= 1 << 12 {
100            return None;
101        }
102        let icon = match code >> 8 {
103            0 => Icon::Files,
104            1 => Icon::Search,
105            2 => Icon::Git,
106            13 => Icon::Agents,
107            14 => Icon::Outline,
108            15 => Icon::Layers,
109            _ => Icon::Settings,
110        };
111        Some(Self {
112            icon,
113            width: (code >> 6 & 3) as u8,
114            height: (code >> 4 & 3) as u8,
115            column: (code >> 2 & 3) as u8,
116            row: (code & 3) as u8,
117        })
118    }
119
120    /// What the cell tier shows, since terminals can't draw the private plane.
121    pub fn fallback(self) -> &'static str {
122        const ART: [[[&str; 3]; 2]; 7] = [
123            [["▛", "▀", "▜"], ["▙", "▄", "▟"]],
124            [["▞", "▀", "▚"], ["▚", "▄", "▟"]],
125            [["●", "─", "●"], ["●", "─", "╯"]],
126            [["▚", "▀", "▞"], ["▞", "▄", "▚"]],
127            [["▗", "▄", "▖"], ["▐", "█", "▌"]],
128            [["▪", "─", "─"], [" ", "▪", "─"]],
129            [["▗", "▀", "▖"], ["▝", "▀", "▘"]],
130        ];
131        let art = match self.icon {
132            Icon::Agents => 4,
133            Icon::Outline => 5,
134            Icon::Layers => 6,
135            other => (other as usize).min(3),
136        };
137        if self.width == 1 || self.height == 1 {
138            if self.column > 0 {
139                return " ";
140            }
141            return match self.icon {
142                Icon::Files => "▤",
143                Icon::Search => "⌕",
144                Icon::Git => "⎇",
145                Icon::Agents => "◉",
146                Icon::Outline => "≡",
147                Icon::Layers => "≋",
148                _ => "⚙",
149            };
150        }
151        ART[art][self.row.min(1) as usize][self.column.min(2) as usize]
152    }
153}
154
155type Point = (f32, f32);
156
157fn segment(p: Point, a: Point, b: Point) -> f32 {
158    let (dx, dy) = (b.0 - a.0, b.1 - a.1);
159    let t = (((p.0 - a.0) * dx + (p.1 - a.1) * dy) / (dx * dx + dy * dy)).clamp(0.0, 1.0);
160    ((p.0 - a.0 - t * dx).powi(2) + (p.1 - a.1 - t * dy).powi(2)).sqrt()
161}
162
163/// Distance to a line through several points. Segments have round ends, so joins do too.
164fn path(p: Point, points: &[Point]) -> f32 {
165    points
166        .windows(2)
167        .map(|pair| segment(p, pair[0], pair[1]))
168        .fold(f32::MAX, f32::min)
169}
170
171fn circle(p: Point, c: Point) -> f32 {
172    ((p.0 - c.0).powi(2) + (p.1 - c.1).powi(2)).sqrt()
173}
174
175/// Distance to a circle's outline.
176fn ring(p: Point, c: Point, radius: f32) -> f32 {
177    (circle(p, c) - radius).abs()
178}
179
180/// Distance to the outline of a box with round corners.
181fn rounded(p: Point, min: Point, max: Point, radius: f32) -> f32 {
182    let (cx, cy) = ((min.0 + max.0) / 2.0, (min.1 + max.1) / 2.0);
183    let (qx, qy) = (
184        (p.0 - cx).abs() - (max.0 - min.0) / 2.0 + radius,
185        (p.1 - cy).abs() - (max.1 - min.1) / 2.0 + radius,
186    );
187    let outside = (qx.max(0.0).powi(2) + qy.max(0.0).powi(2)).sqrt();
188    (outside + qx.max(qy).min(0.0) - radius).abs()
189}
190
191/// Distance to a box with round corners, filled: nothing inside it.
192fn solid(p: Point, min: Point, max: Point, radius: f32) -> f32 {
193    let (cx, cy) = ((min.0 + max.0) / 2.0, (min.1 + max.1) / 2.0);
194    let (qx, qy) = (
195        (p.0 - cx).abs() - (max.0 - min.0) / 2.0 + radius,
196        (p.1 - cy).abs() - (max.1 - min.1) / 2.0 + radius,
197    );
198    let outside = (qx.max(0.0).powi(2) + qy.max(0.0).powi(2)).sqrt();
199    (outside + qx.max(qy).min(0.0) - radius).max(0.0)
200}
201
202/// A box at the bottom left, an arrow turning up from it, and the corners of the box it
203/// becomes at the top right.
204fn replace(p: Point) -> f32 {
205    rounded(p, (2.0, 14.0), (10.0, 22.0), 2.0)
206        .min(path(
207            p,
208            &[(6.0, 10.0), (6.0, 5.0), (6.9, 2.9), (9.0, 2.0), (10.0, 2.0)],
209        ))
210        .min(path(p, &[(3.0, 7.0), (6.0, 10.0), (9.0, 7.0)]))
211        .min(path(p, &[(14.0, 4.0), (14.6, 2.6), (16.0, 2.0)]))
212        .min(path(p, &[(16.0, 10.0), (14.6, 9.4), (14.0, 8.0)]))
213        .min(path(p, &[(20.0, 2.0), (21.4, 2.6), (22.0, 4.0)]))
214        .min(path(p, &[(22.0, 8.0), (21.4, 9.4), (20.0, 10.0)]))
215}
216
217/// Half the stroke's width, in 24ths of the icon. The large icons stay fine-lined, and the
218/// small ones are heavier so they keep their weight at a few pixels across.
219fn half_stroke(icon: Icon) -> f32 {
220    match icon {
221        Icon::Files
222        | Icon::Search
223        | Icon::Git
224        | Icon::Settings
225        | Icon::Outline
226        | Icon::Layers
227        | Icon::File
228        | Icon::Folder
229        | Icon::FolderOpen
230        | Icon::ChevronRight
231        | Icon::ChevronDown
232        | Icon::Close
233        | Icon::ArrowUp
234        | Icon::ArrowDown
235        | Icon::Replace
236        | Icon::Maximize
237        | Icon::Minimize
238        | Icon::SymbolFunction
239        | Icon::SymbolType
240        | Icon::SymbolField
241        | Icon::SymbolValue
242        | Icon::HidePane
243        | Icon::ReplaceAll => 0.9,
244        Icon::Agents => 0.8,
245        Icon::Check => 1.7,
246        _ => 1.15,
247    }
248}
249
250/// Whether a point in the icon's unit square is inked. Icons share a 24-unit grid and one
251/// round-ended stroke, which is what makes them read as a set.
252pub fn inked(icon: Icon, u: f32, v: f32) -> bool {
253    let p = (u * 24.0, v * 24.0);
254    let distance = match icon {
255        // A page with its corner folded, and the edge of one behind it.
256        Icon::Files => path(
257            p,
258            &[
259                (9.0, 18.0),
260                (7.6, 17.4),
261                (7.0, 16.0),
262                (7.0, 4.0),
263                (7.6, 2.6),
264                (9.0, 2.0),
265                (16.0, 2.0),
266                (20.0, 6.0),
267                (20.0, 16.0),
268                (19.4, 17.4),
269                (18.0, 18.0),
270                (9.0, 18.0),
271            ],
272        )
273        .min(path(
274            p,
275            &[
276                (20.0, 7.0),
277                (17.0, 7.0),
278                (15.6, 6.4),
279                (15.0, 5.0),
280                (15.0, 2.0),
281            ],
282        ))
283        .min(path(
284            p,
285            &[
286                (3.0, 7.6),
287                (3.0, 20.4),
288                (3.5, 21.5),
289                (4.6, 22.0),
290                (14.4, 22.0),
291            ],
292        )),
293        Icon::Search => ring(p, (11.0, 11.0), 7.0).min(segment(p, (16.65, 16.65), (20.0, 20.0))),
294        Icon::Git => {
295            let joint = (9.0, 9.0);
296            let quarter = p.0 >= joint.0 && p.1 >= joint.1;
297            let curve = if quarter {
298                ring(p, joint, 9.0)
299            } else {
300                f32::MAX
301            };
302            ring(p, (6.0, 18.0), 3.0)
303                .min(ring(p, (18.0, 6.0), 3.0))
304                .min(segment(p, (6.0, 3.0), (6.0, 15.0)))
305                .min(curve)
306        }
307        // Two sliders, as settings are in most of today's apps.
308        Icon::Settings => segment(p, (20.0, 7.0), (11.0, 7.0))
309            .min(segment(p, (14.0, 17.0), (5.0, 17.0)))
310            .min(ring(p, (17.0, 17.0), 3.0))
311            .min(ring(p, (7.0, 7.0), 3.0)),
312        Icon::Agents => rounded(p, (4.0, 8.5), (20.0, 20.5), 3.0)
313            .min(path(p, &[(12.0, 8.5), (12.0, 3.5), (8.5, 3.5)]))
314            .min(segment(p, (9.0, 13.0), (9.0, 15.5)))
315            .min(segment(p, (15.0, 13.0), (15.0, 15.5)))
316            .min(segment(p, (1.5, 14.5), (4.0, 14.5)))
317            .min(segment(p, (20.0, 14.5), (22.5, 14.5))),
318        // Lucide's file, folder and folder-open.
319        Icon::File => path(
320            p,
321            &[
322                (15.0, 2.0),
323                (6.0, 2.0),
324                (4.6, 2.6),
325                (4.0, 4.0),
326                (4.0, 20.0),
327                (4.6, 21.4),
328                (6.0, 22.0),
329                (18.0, 22.0),
330                (19.4, 21.4),
331                (20.0, 20.0),
332                (20.0, 7.0),
333                (15.0, 2.0),
334            ],
335        )
336        .min(path(
337            p,
338            &[
339                (14.0, 2.0),
340                (14.0, 6.0),
341                (14.6, 7.4),
342                (16.0, 8.0),
343                (20.0, 8.0),
344            ],
345        )),
346        Icon::Folder => path(
347            p,
348            &[
349                (20.0, 20.0),
350                (21.4, 19.4),
351                (22.0, 18.0),
352                (22.0, 8.0),
353                (21.4, 6.6),
354                (20.0, 6.0),
355                (12.1, 6.0),
356                (10.4, 5.1),
357                (9.6, 3.9),
358                (7.9, 3.0),
359                (4.0, 3.0),
360                (2.6, 3.6),
361                (2.0, 5.0),
362                (2.0, 18.0),
363                (2.6, 19.4),
364                (4.0, 20.0),
365                (20.0, 20.0),
366            ],
367        ),
368        Icon::FolderOpen => path(
369            p,
370            &[
371                (6.0, 14.0),
372                (7.5, 11.1),
373                (9.2, 10.0),
374                (20.0, 10.0),
375                (21.9, 12.5),
376                (20.4, 18.5),
377                (18.5, 20.0),
378                (4.0, 20.0),
379                (2.6, 19.4),
380                (2.0, 18.0),
381                (2.0, 5.0),
382                (2.6, 3.6),
383                (4.0, 3.0),
384                (7.9, 3.0),
385                (9.6, 3.9),
386                (10.4, 5.1),
387                (12.1, 6.0),
388                (18.0, 6.0),
389                (19.4, 6.6),
390                (20.0, 8.0),
391                (20.0, 10.0),
392            ],
393        ),
394        // Three sheets stacked, the top one whole.
395        Icon::Layers => path(
396            p,
397            &[
398                (12.0, 2.5),
399                (21.5, 7.5),
400                (12.0, 12.5),
401                (2.5, 7.5),
402                (12.0, 2.5),
403            ],
404        )
405        .min(path(p, &[(2.5, 12.5), (12.0, 17.5), (21.5, 12.5)]))
406        .min(path(p, &[(2.5, 17.0), (12.0, 22.0), (21.5, 17.0)])),
407        // A tree of headings.
408        Icon::Outline => segment(p, (21.0, 6.0), (8.0, 6.0))
409            .min(segment(p, (21.0, 12.0), (13.0, 12.0)))
410            .min(segment(p, (21.0, 18.0), (13.0, 18.0)))
411            .min(path(
412                p,
413                &[
414                    (3.0, 6.0),
415                    (3.0, 10.0),
416                    (3.6, 11.4),
417                    (5.0, 12.0),
418                    (8.0, 12.0),
419                ],
420            ))
421            .min(path(
422                p,
423                &[
424                    (3.0, 10.0),
425                    (3.0, 16.0),
426                    (3.6, 17.4),
427                    (5.0, 18.0),
428                    (8.0, 18.0),
429                ],
430            )),
431        Icon::ListBullet => (circle(p, (5.0, 6.5)) - 0.4)
432            .min(circle(p, (5.0, 12.0)) - 0.4)
433            .min(circle(p, (5.0, 17.5)) - 0.4)
434            .min(segment(p, (9.5, 6.5), (20.5, 6.5)))
435            .min(segment(p, (9.5, 12.0), (20.5, 12.0)))
436            .min(segment(p, (9.5, 17.5), (20.5, 17.5))),
437        Icon::ListNumber => path(p, &[(3.8, 5.2), (5.4, 4.0), (5.4, 9.5)])
438            .min(path(
439                p,
440                &[
441                    (3.6, 15.0),
442                    (5.0, 13.8),
443                    (6.8, 14.8),
444                    (3.6, 19.8),
445                    (7.2, 19.8),
446                ],
447            ))
448            .min(segment(p, (10.5, 6.8), (20.5, 6.8)))
449            .min(segment(p, (10.5, 16.8), (20.5, 16.8))),
450        Icon::ListTask => rounded(p, (4.0, 4.0), (20.0, 20.0), 3.5)
451            .min(path(p, &[(8.0, 12.2), (11.0, 15.2), (16.2, 9.0)])),
452        Icon::Quote => segment(p, (4.5, 5.0), (4.5, 19.0))
453            .min(segment(p, (9.5, 7.0), (20.5, 7.0)))
454            .min(segment(p, (9.5, 12.0), (20.5, 12.0)))
455            .min(segment(p, (9.5, 17.0), (16.5, 17.0))),
456        Icon::Code => path(p, &[(8.5, 6.5), (3.0, 12.0), (8.5, 17.5)])
457            .min(path(p, &[(15.5, 6.5), (21.0, 12.0), (15.5, 17.5)])),
458        Icon::Link => rounded(p, (2.5, 8.0), (13.5, 16.0), 4.0).min(rounded(
459            p,
460            (10.5, 8.0),
461            (21.5, 16.0),
462            4.0,
463        )),
464        Icon::Table => rounded(p, (3.0, 4.5), (21.0, 19.5), 2.5)
465            .min(segment(p, (3.0, 9.5), (21.0, 9.5)))
466            .min(segment(p, (3.0, 14.5), (21.0, 14.5)))
467            .min(segment(p, (12.0, 4.5), (12.0, 19.5))),
468        // A pencil over a line.
469        Icon::Track => path(
470            p,
471            &[
472                (4.0, 16.5),
473                (15.5, 5.0),
474                (19.0, 8.5),
475                (7.5, 20.0),
476                (4.0, 20.0),
477                (4.0, 16.5),
478            ],
479        )
480        .min(path(p, &[(13.0, 20.5), (21.0, 20.5)])),
481        Icon::Diagram => rounded(p, (2.5, 3.5), (10.0, 9.5), 1.5)
482            .min(rounded(p, (14.0, 3.5), (21.5, 9.5), 1.5))
483            .min(rounded(p, (14.0, 14.5), (21.5, 20.5), 1.5))
484            .min(path(p, &[(10.0, 6.5), (14.0, 6.5)]))
485            .min(path(p, &[(6.2, 9.5), (6.2, 17.5), (14.0, 17.5)])),
486        Icon::Picture => rounded(p, (3.0, 4.5), (21.0, 19.5), 2.5)
487            .min(ring(p, (8.5, 9.8), 1.5))
488            .min(path(
489                p,
490                &[
491                    (3.5, 18.0),
492                    (9.5, 12.8),
493                    (13.5, 16.2),
494                    (16.2, 13.8),
495                    (20.5, 17.5),
496                ],
497            )),
498        Icon::Sigma => path(
499            p,
500            &[
501                (18.0, 7.5),
502                (18.0, 4.5),
503                (5.5, 4.5),
504                (12.5, 12.0),
505                (5.5, 19.5),
506                (18.0, 19.5),
507                (18.0, 16.5),
508            ],
509        ),
510        Icon::Rule => segment(p, (3.0, 12.0), (21.0, 12.0))
511            .min(segment(p, (8.0, 6.5), (16.0, 6.5)))
512            .min(segment(p, (8.0, 17.5), (16.0, 17.5))),
513        Icon::Comment => rounded(p, (3.0, 4.0), (21.0, 16.5), 3.5)
514            .min(path(p, &[(8.0, 16.5), (8.0, 20.5), (12.5, 16.5)])),
515        Icon::Export => path(p, &[(12.0, 3.5), (12.0, 15.0)])
516            .min(path(p, &[(7.0, 10.5), (12.0, 15.5), (17.0, 10.5)]))
517            .min(segment(p, (4.0, 20.0), (20.0, 20.0))),
518        Icon::Play => path(p, &[(7.0, 4.5), (19.5, 12.0), (7.0, 19.5), (7.0, 4.5)]),
519        Icon::PlayAll => path(p, &[(3.0, 5.5), (12.0, 12.0), (3.0, 18.5), (3.0, 5.5)]).min(path(
520            p,
521            &[(12.0, 5.5), (21.0, 12.0), (12.0, 18.5), (12.0, 5.5)],
522        )),
523        Icon::Stop => rounded(p, (6.0, 6.0), (18.0, 18.0), 1.5),
524        Icon::Restart => {
525            // A circle with a gap at the top right, and an arrowhead closing it.
526            let angle = (p.1 - 12.0).atan2(p.0 - 12.0);
527            let gap = angle > -1.1 && angle < 0.1;
528            let arc = if gap {
529                f32::MAX
530            } else {
531                ring(p, (12.0, 12.0), 7.5)
532            };
533            arc.min(path(p, &[(19.5, 4.0), (19.5, 10.0), (13.8, 10.0)]))
534        }
535        Icon::AddCell => rounded(p, (3.0, 6.0), (21.0, 18.0), 2.0)
536            .min(segment(p, (12.0, 9.0), (12.0, 15.0)))
537            .min(segment(p, (9.0, 12.0), (15.0, 12.0))),
538        Icon::AddText => segment(p, (3.0, 6.0), (21.0, 6.0))
539            .min(segment(p, (3.0, 11.0), (13.0, 11.0)))
540            .min(segment(p, (3.0, 16.0), (10.0, 16.0)))
541            .min(segment(p, (18.0, 13.0), (18.0, 21.0)))
542            .min(segment(p, (14.0, 17.0), (22.0, 17.0))),
543        Icon::Cite => path(p, &[(9.0, 4.5), (5.5, 4.5), (5.5, 19.5), (9.0, 19.5)])
544            .min(path(
545                p,
546                &[(15.0, 4.5), (18.5, 4.5), (18.5, 19.5), (15.0, 19.5)],
547            ))
548            .min(segment(p, (12.0, 9.0), (12.0, 15.0))),
549        Icon::More => (circle(p, (5.0, 12.0)) - 0.5)
550            .min(circle(p, (12.0, 12.0)) - 0.5)
551            .min(circle(p, (19.0, 12.0)) - 0.5),
552        Icon::ChevronRight => path(p, &[(9.5, 6.5), (15.0, 12.0), (9.5, 17.5)]),
553        Icon::ChevronDown => path(p, &[(6.5, 9.5), (12.0, 15.0), (17.5, 9.5)]),
554        Icon::Close => {
555            segment(p, (6.5, 6.5), (17.5, 17.5)).min(segment(p, (17.5, 6.5), (6.5, 17.5)))
556        }
557        Icon::Replace => replace(p),
558        Icon::ArrowUp => path(p, &[(5.0, 12.0), (12.0, 5.0), (19.0, 12.0)]).min(segment(
559            p,
560            (12.0, 5.0),
561            (12.0, 19.0),
562        )),
563        Icon::ArrowDown => path(p, &[(19.0, 12.0), (12.0, 19.0), (5.0, 12.0)]).min(segment(
564            p,
565            (12.0, 5.0),
566            (12.0, 19.0),
567        )),
568        Icon::ReplaceAll => replace(p)
569            .min(path(
570                p,
571                &[
572                    (14.0, 14.0),
573                    (15.4, 14.6),
574                    (16.0, 16.0),
575                    (16.0, 20.0),
576                    (15.4, 21.4),
577                    (14.0, 22.0),
578                ],
579            ))
580            .min(path(
581                p,
582                &[
583                    (20.0, 14.0),
584                    (21.4, 14.6),
585                    (22.0, 16.0),
586                    (22.0, 20.0),
587                    (21.4, 21.4),
588                    (20.0, 22.0),
589                ],
590            )),
591        Icon::Check => path(p, &[(4.5, 12.5), (9.5, 17.5), (19.5, 6.5)]),
592        // Lucide's panel-right, its right part filled.
593        Icon::HidePane => rounded(p, (3.0, 3.0), (21.0, 21.0), 2.0)
594            .min(segment(p, (15.0, 3.0), (15.0, 21.0)))
595            .min(solid(p, (15.0, 3.0), (21.0, 21.0), 2.0)),
596        Icon::Maximize => path(p, &[(15.0, 3.0), (21.0, 3.0), (21.0, 9.0)])
597            .min(path(p, &[(9.0, 21.0), (3.0, 21.0), (3.0, 15.0)]))
598            .min(segment(p, (21.0, 3.0), (14.0, 10.0)))
599            .min(segment(p, (3.0, 21.0), (10.0, 14.0))),
600        Icon::Minimize => path(p, &[(4.0, 14.0), (10.0, 14.0), (10.0, 20.0)])
601            .min(path(p, &[(20.0, 10.0), (14.0, 10.0), (14.0, 4.0)]))
602            .min(segment(p, (14.0, 10.0), (21.0, 3.0)))
603            .min(segment(p, (3.0, 21.0), (10.0, 14.0))),
604        // Lucide's box.
605        Icon::SymbolFunction => path(
606            p,
607            &[
608                (12.0, 2.5),
609                (20.5, 7.2),
610                (20.5, 16.8),
611                (12.0, 21.5),
612                (3.5, 16.8),
613                (3.5, 7.2),
614                (12.0, 2.5),
615            ],
616        )
617        .min(path(p, &[(3.8, 7.3), (12.0, 12.0), (20.2, 7.3)]))
618        .min(segment(p, (12.0, 12.0), (12.0, 21.5))),
619        Icon::SymbolType => path(
620            p,
621            &[
622                (8.5, 3.0),
623                (7.0, 3.0),
624                (5.5, 4.5),
625                (5.5, 10.0),
626                (3.5, 12.0),
627                (5.5, 14.0),
628                (5.5, 19.5),
629                (7.0, 21.0),
630                (8.5, 21.0),
631            ],
632        )
633        .min(path(
634            p,
635            &[
636                (15.5, 3.0),
637                (17.0, 3.0),
638                (18.5, 4.5),
639                (18.5, 10.0),
640                (20.5, 12.0),
641                (18.5, 14.0),
642                (18.5, 19.5),
643                (17.0, 21.0),
644                (15.5, 21.0),
645            ],
646        )),
647        Icon::SymbolField => {
648            rounded(p, (3.0, 7.5), (21.0, 16.5), 2.5).min(segment(p, (7.0, 12.0), (12.0, 12.0)))
649        }
650        Icon::SymbolValue => {
651            segment(p, (4.5, 9.0), (19.5, 9.0)).min(segment(p, (4.5, 15.0), (19.5, 15.0)))
652        }
653        Icon::Terminal => path(p, &[(3.5, 6.0), (10.0, 12.0), (3.5, 18.0)]).min(segment(
654            p,
655            (12.5, 18.0),
656            (20.5, 18.0),
657        )),
658        Icon::Panel => {
659            rounded(p, (3.0, 3.0), (21.0, 21.0), 4.0).min(segment(p, (3.0, 15.0), (21.0, 15.0)))
660        }
661        Icon::Diff => rounded(p, (3.0, 3.0), (21.0, 21.0), 4.0)
662            .min(segment(p, (12.0, 6.5), (12.0, 12.5)))
663            .min(segment(p, (9.0, 9.5), (15.0, 9.5)))
664            .min(segment(p, (9.0, 16.5), (15.0, 16.5))),
665        // Lucide's bell: a dome on a flared rim, and the clapper under it.
666        Icon::Bell => {
667            let dome = if p.1 <= 9.0 {
668                ring(p, (12.0, 9.0), 6.0)
669            } else {
670                f32::MAX
671            };
672            dome.min(path(
673                p,
674                &[(6.0, 9.0), (6.0, 12.5), (5.2, 15.4), (3.2, 17.5)],
675            ))
676            .min(path(
677                p,
678                &[(18.0, 9.0), (18.0, 12.5), (18.8, 15.4), (20.8, 17.5)],
679            ))
680            .min(segment(p, (3.2, 17.5), (20.8, 17.5)))
681            .min(path(p, &[(10.2, 20.8), (12.0, 21.8), (13.8, 20.8)]))
682        }
683        Icon::Question => ring(p, (12.0, 12.0), 9.5)
684            .min(path(
685                p,
686                &[
687                    (9.3, 9.2),
688                    (10.1, 7.6),
689                    (12.0, 7.0),
690                    (14.0, 7.7),
691                    (14.8, 9.4),
692                    (14.0, 11.0),
693                    (12.0, 12.2),
694                    (12.0, 13.6),
695                ],
696            ))
697            .min(circle(p, (12.0, 17.0)) - 0.4),
698        Icon::CircleCheck => {
699            ring(p, (12.0, 12.0), 9.5).min(path(p, &[(8.0, 12.3), (10.8, 15.0), (16.0, 9.5)]))
700        }
701        Icon::CircleX => ring(p, (12.0, 12.0), 9.5)
702            .min(segment(p, (8.8, 8.8), (15.2, 15.2)))
703            .min(segment(p, (15.2, 8.8), (8.8, 15.2))),
704        Icon::Globe => {
705            let (x, y) = ((p.0 - 12.0) / 4.5, (p.1 - 12.0) / 9.5);
706            let meridian = ((x * x + y * y).sqrt() - 1.0).abs() * 4.5;
707            ring(p, (12.0, 12.0), 9.5)
708                .min(meridian)
709                .min(segment(p, (2.5, 12.0), (21.5, 12.0)))
710        }
711    };
712    distance < half_stroke(icon)
713}
714
715#[cfg(test)]
716mod tests {
717    use super::*;
718
719    #[test]
720    fn pieces_survive_the_grid() {
721        for icon in [
722            Icon::Files,
723            Icon::Search,
724            Icon::Git,
725            Icon::Settings,
726            Icon::Layers,
727        ] {
728            let piece = Piece {
729                icon,
730                width: 3,
731                height: 2,
732                column: 2,
733                row: 1,
734            };
735            let text = piece.symbol().to_string();
736            assert_eq!(Piece::decode(&text), Some(piece));
737        }
738        assert_eq!(Piece::decode("a"), None);
739    }
740
741    #[test]
742    fn every_icon_has_ink() {
743        for icon in [
744            Icon::Files,
745            Icon::Search,
746            Icon::Git,
747            Icon::Settings,
748            Icon::Agents,
749            Icon::Layers,
750            Icon::Folder,
751            Icon::File,
752            Icon::Maximize,
753            Icon::Minimize,
754            Icon::Panel,
755            Icon::SymbolFunction,
756            Icon::SymbolType,
757            Icon::SymbolField,
758            Icon::SymbolValue,
759            Icon::Bell,
760            Icon::Question,
761            Icon::CircleCheck,
762            Icon::CircleX,
763            Icon::HidePane,
764        ] {
765            let dots = (0..50)
766                .flat_map(|y| (0..50).map(move |x| (x, y)))
767                .filter(|(x, y)| inked(icon, *x as f32 / 50.0, *y as f32 / 50.0))
768                .count();
769            assert!(dots > 150, "{icon:?} has {dots}");
770        }
771    }
772}