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.
52    pub const CHEVRON_RIGHT: char = '\u{eab6}';
53    /// `chevron-down` (U+EAB4) — the expanded-fold gutter indicator.
54    pub const CHEVRON_DOWN: char = '\u{eab4}';
55    /// `arrow-up` (U+EAA1) — find "previous match".
56    pub const ARROW_UP: char = '\u{eaa1}';
57    /// `arrow-down` (U+EA9A) — find "next match".
58    pub const ARROW_DOWN: char = '\u{ea9a}';
59    /// `close` (U+EA76) — find "close".
60    pub const CLOSE: char = '\u{ea76}';
61}