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