Skip to main content

Crate scrive_iced

Crate scrive_iced 

Source
Expand description

scrive-iced — the iced 0.14 integration for the scrive code editor.

Turns scrive_core into an on-screen widget: a direct iced::advanced::Widget (deliberately not a canvas::Program, because only the low-level widget API exposes the operate() hook needed to join iced’s focus/operation protocol), with a gutter, N-caret selections, syntect highlighting, diagnostic squiggles, a completion popup, and hover.

§Two tiers

  • CodeEditorstart here. The batteries-included tier: it owns a scrive_core::Document and runs the highlighting, find, focus, and language-intelligence plumbing internally, so integrating is three wires (update, view, subscription) plus registering required_fonts at startup. Highlighting is coloured at load with no scroll needed; the find bar, selection, undo, and folding are on by default. See examples/minimal.rs.
  • Editor — the low-level controlled widget: it renders a Document and emits semantic Actions the application applies by hand. Full control, all the plumbing on you. See examples/scratch.rs.

The minimal integration:

use iced::{Element, Subscription, Task};
use scrive_iced::{CodeEditor, Event};

struct App { editor: CodeEditor }

#[derive(Debug, Clone)]
enum Message { Editor(Event) }

impl App {
    fn new() -> Self { Self { editor: CodeEditor::new("fn main() {}\n") } }
    fn update(&mut self, m: Message) -> Task<Message> {
        match m { Message::Editor(e) => self.editor.update(e).map(Message::Editor) }
    }
    fn view(&self) -> Element<'_, Message> { self.editor.view().map(Message::Editor) }
    fn subscription(&self) -> Subscription<Message> {
        self.editor.subscription().map(Message::Editor)
    }
}

Re-exports§

pub use code_editor::CodeEditor;
pub use code_editor::Event;
pub use editor::default_autoscroll_margin;
pub use editor::Action;
pub use editor::Editor;
pub use editor::SCROLLBAR_WIDTH;
pub use metrics::Metrics;

Modules§

code_editor
CodeEditor — the batteries-included editor tier.
editor
The editor widget: a direct iced::advanced::Widget.
icon
Codicon glyph codepoints scrive draws. Names and values are from the codicon mapping.json (verified against v0.0.45); the private-use-area codepoints are only meaningful rendered in the CODICON font.
metrics
Monospace text metrics, measured once per (font, size) from the renderer’s own shaper — never a hardcoded advance.
popup
Completion-popup geometry: the pure placement, windowing, and sizing math for the completion popup. The rendering itself lives in the editor widget (it reuses the widget’s fill/text helpers); this module is the testable geometry it drives. Every function is recomputed each frame against the live caret, so the popup tracks the caret rather than freezing at the position it opened.

Constants§

CODICON
The iced::Font handle for the bundled CODICON_FONT (family "codicon").
CODICON_FONT
The bundled Codicon icon font (v0.0.45) — VS Code’s own UI glyph set. The host application must load these bytes into iced’s font system at startup (e.g. iced::application(..).font(scrive_iced::CODICON_FONT)); after that the widget’s fold-gutter chevrons and any app chrome can draw glyphs in the CODICON font. Icons © Microsoft, CC BY 4.0 (see assets/CODICON-LICENSE.md).

Functions§

required_fonts
Every font the widget needs registered in iced’s font system at startup — register them all and the fold-gutter chevrons and find-bar icons render; omit one and its glyphs fall back to per-machine tofu. One owner so an integrator can load the whole set instead of enumerating it by hand (today just CODICON_FONT): scrive_iced::required_fonts().iter().fold(app, |app, f| app.font(*f)).
scrive_dark_theme
The bundled Scrive Dark syntax theme — an original, MIT-licensed dark theme (the one that shipped with 0.1.0). It is the sensible default so a host gets colored text from a grammar alone, without supplying a .tmTheme: the batteries-included editor tier applies it unless the host overrides it with another TokenTheme.