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