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