Editor
A retained native code editor with syntax coloring, line numbers, indentation, and both-axis scrolling.
No language grammars are included by default. Register a linked grammar in Rust, or load one portable pack of selected Tree-sitter Wasm grammars and queries using loadLanguagePack (TypeScript) / LoadLanguagePack (Go).
Unstyled by default: text and line-number colors inherit, and the component adds no background, border, rounding, padding, or syntax/diff palette. Supply application styles and explicit colors to opt into an appearance.
#Import
Enable QuickGUI's opt-in editor crate feature and import the retained editor types.
use quickgui::{Editor, IntoElement, SyntaxLanguage, View, ViewContext};#Usage
struct EditorExample {
editor: Editor,
}
impl View for EditorExample {
fn render(&mut self, cx: &mut ViewContext<'_, Self>) -> impl IntoElement {
let changed = cx.input_listener("source", |view, value, cx| {
if view.editor.set_text(value).changed {
cx.invalidate();
}
});
self.editor.element("source").on_input(changed)
}
}#Syntax highlighting
SyntaxLanguage selects a registered Tree-sitter grammar and highlight query. Query captures are flattened into eight stable SyntaxTheme classes and applied as foreground-only HighlightStyle spans, so color never changes text metrics. Source or language changes reparse the bounded document; palette changes only remap the retained captures, and scrolling does no syntax work. Parsing is limited to 2 MiB, individual lines over 32 KiB stay plain, and the capture count is capped. This is structural syntax highlighting, not language-server semantic tokens.
#API reference
Expand an entry for its description and complete signature. A dash means no declaration default is documented.
Editor
View sourcepub fn new() -> Selfwith_textpub fn with_text(source: &str) -> Self—
with_languagepub fn with_language(mut self, language: SyntaxLanguage) -> Self—
Configures with language for this part.
pub fn with_language(mut self, language: SyntaxLanguage) -> SelfView sourcewith_stylepub fn with_style(mut self, style: EditorStyle) -> Self—
Configures with style for this part.
pub fn with_style(mut self, style: EditorStyle) -> SelfView sourcewith_behaviorpub fn with_behavior(mut self, behavior: TextInputIndentation) -> Self—
Configures with behavior for this part.
pub fn with_behavior(mut self, behavior: TextInputIndentation) -> SelfView sourcetextpub fn text(&self) -> &str—
languagepub const fn language(&self) -> SyntaxLanguage—
stylepub const fn style(&self) -> EditorStyle—
behaviorpub const fn behavior(&self) -> TextInputIndentation—
is_truncatedpub const fn is_truncated(&self) -> bool—
set_textpub fn set_text(&mut self, source: &str) -> EditorUpdate—
Configures set text for this part.
pub fn set_text(&mut self, source: &str) -> EditorUpdateView sourceset_languagepub fn set_language(&mut self, language: SyntaxLanguage) -> bool—
Configures set language for this part.
pub fn set_language(&mut self, language: SyntaxLanguage) -> boolView sourceset_stylepub fn set_style(&mut self, style: EditorStyle) -> bool—
Configures set style for this part.
pub fn set_style(&mut self, style: EditorStyle) -> boolView sourceset_behaviorpub fn set_behavior(&mut self, behavior: TextInputIndentation) -> bool—
Configures set behavior for this part.
pub fn set_behavior(&mut self, behavior: TextInputIndentation) -> boolView sourceset_read_onlypub fn set_read_only(&mut self, read_only: bool) -> bool—
Configures set read only for this part.
pub fn set_read_only(&mut self, read_only: bool) -> boolView sourcerefresh_syntax_languagespub fn refresh_syntax_languages(&mut self) -> bool—
Refresh captures after registering a grammar used by this document or an injection. Returns false without parsing when the registry is unchanged; preserves editing state.
pub fn refresh_syntax_languages(&mut self) -> boolView sourceEditor::element
View sourcepub fn element(&self, id: impl Into<ElementId>) -> ElementBuild the editor leaf. Attach a stable [`crate::InputListener`] with [`Element::on_input`](crate::Element::on_input).
