Skip to main content

scrive_iced/
lib.rs

1//! `scrive-iced` — the iced 0.14 integration for the scrive code editor.
2//!
3//! Turns [`scrive_core`] into an on-screen widget: a direct
4//! `iced::advanced::Widget` (deliberately *not* a `canvas::Program`, because
5//! only the low-level widget API exposes the `operate()` hook needed to join
6//! iced's focus/operation protocol), with a gutter, N-caret selections, syntect
7//! highlighting, diagnostic squiggles, a completion popup, and hover.
8//!
9//! [`Editor`] renders a [`scrive_core::Document`] and emits [`Action`]s the
10//! application applies to its document. See `examples/scratch.rs` for the
11//! wiring and a runnable window.
12
13#![deny(missing_docs)]
14#![forbid(unsafe_code)]
15
16mod clipboard;
17pub mod editor;
18mod geo;
19pub mod metrics;
20pub mod popup;
21
22pub use editor::{default_autoscroll_margin, Action, Editor, SCROLLBAR_WIDTH};
23pub use metrics::Metrics;
24
25/// The bundled [Codicon](https://github.com/microsoft/vscode-codicons) icon font
26/// (v0.0.45) — VS Code's own UI glyph set. The host application **must** load
27/// these bytes into iced's font system at startup (e.g.
28/// `iced::application(..).font(scrive_iced::CODICON_FONT)`); after that the
29/// widget's fold-gutter chevrons and any app chrome can draw glyphs in the
30/// [`CODICON`] font. Icons © Microsoft, CC BY 4.0 (see `assets/CODICON-LICENSE.md`).
31pub const CODICON_FONT: &[u8] = include_bytes!("../assets/codicon.ttf");
32
33/// The [`iced::Font`] handle for the bundled [`CODICON_FONT`] (family `"codicon"`).
34pub const CODICON: iced::Font = iced::Font::with_name("codicon");
35
36/// Every font the widget needs registered in iced's font system at startup —
37/// register them all and the fold-gutter chevrons and find-bar icons render;
38/// omit one and its glyphs fall back to per-machine tofu. One owner so an
39/// integrator can load the whole set instead of enumerating it by hand (today
40/// just [`CODICON_FONT`]):
41/// `scrive_iced::required_fonts().iter().fold(app, |app, f| app.font(*f))`.
42#[must_use]
43pub fn required_fonts() -> &'static [&'static [u8]] {
44    &[CODICON_FONT]
45}
46
47/// Codicon glyph codepoints scrive draws. Names and values are from the codicon
48/// `mapping.json` (verified against v0.0.45); the private-use-area codepoints are
49/// only meaningful rendered in the [`CODICON`] font.
50pub mod icon {
51    /// `chevron-right` (U+EAB6) — the collapsed-fold gutter indicator, and the
52    /// find bar's collapsed replace-row toggle.
53    pub const CHEVRON_RIGHT: char = '\u{eab6}';
54    /// `chevron-down` (U+EAB4) — the expanded-fold gutter indicator, and the
55    /// find bar's expanded replace-row toggle.
56    pub const CHEVRON_DOWN: char = '\u{eab4}';
57    /// `arrow-up` (U+EAA1) — find "previous match".
58    pub const ARROW_UP: char = '\u{eaa1}';
59    /// `arrow-down` (U+EA9A) — find "next match".
60    pub const ARROW_DOWN: char = '\u{ea9a}';
61    /// `close` (U+EA76) — find "close".
62    pub const CLOSE: char = '\u{ea76}';
63    /// `replace` (U+EB3D) — find "replace this match".
64    pub const REPLACE: char = '\u{eb3d}';
65    /// `replace-all` (U+EB3C) — find "replace every match".
66    pub const REPLACE_ALL: char = '\u{eb3c}';
67    /// `case-sensitive` (U+EAB1) — the find bar's `Aa` option toggle.
68    pub const CASE_SENSITIVE: char = '\u{eab1}';
69    /// `preserve-case` (U+EB2E) — the replace bar's `AB` option toggle.
70    pub const PRESERVE_CASE: char = '\u{eb2e}';
71    /// `whole-word` (U+EB7E) — the find bar's `ab|` option toggle.
72    pub const WHOLE_WORD: char = '\u{eb7e}';
73    /// `regex` (U+EB38) — the find bar's `.*` option toggle.
74    pub const REGEX: char = '\u{eb38}';
75    /// `list-selection` (U+EB85) — the find bar's "find in selection" toggle.
76    /// The codicon set names this glyph `list-selection`; `selection` is an
77    /// alias for it, and is what VS Code calls the same button.
78    pub const SELECTION: char = '\u{eb85}';
79}