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
CodeEditor— start here. The batteries-included tier: it owns ascrive_core::Documentand runs the highlighting, find, focus, and language-intelligence plumbing internally, so integrating is three wires (update,view,subscription) plus registeringrequired_fontsat startup. Highlighting is coloured at load with no scroll needed; the find bar, selection, undo, and folding are on by default. Seeexamples/minimal.rs.Editor— the low-level controlled widget: it renders aDocumentand emits semanticActions the application applies by hand. Full control, all the plumbing on you. Seeexamples/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 theCODICONfont. - 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::Fonthandle for the bundledCODICON_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 theCODICONfont. Icons © Microsoft, CC BY 4.0 (seeassets/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 anotherTokenTheme.