Editor
シンタックスカラー、行番号、インデント、両軸スクロールに対応した保持型ネイティブコードエディターです。
既定では言語文法を含みません。Rust はリンク済み文法を登録でき、Go / TypeScript は LoadLanguagePack / loadLanguagePack で選択した Tree-sitter Wasm 文法とクエリをまとめた単一の移植可能なパックを読み込めます。
既定では見た目のスタイルを持ちません。文字と行番号の色は継承され、背景、枠線、角丸、余白、構文・差分の配色は追加されません。外観はアプリ側で明示的に指定します。
#インポート
QuickGUI の任意の editor crate feature を有効にし、保持型エディターの型をインポートします。
use quickgui::{Editor, IntoElement, SyntaxLanguage, View, ViewContext};#使い方
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)
}
}#シンタックスハイライト
SyntaxLanguage は同梱の Tree-sitter 文法とハイライトクエリを選択します。クエリのキャプチャは 8 種類の安定した SyntaxTheme クラスへ平坦化され、前景色だけの HighlightStyle 範囲として適用されるため、色はテキスト寸法を変えません。ソースまたは言語が変わると上限付きドキュメントを再解析し、配色変更では保持済みキャプチャだけを再マッピングします。スクロール時に構文処理は行いません。解析は最大 2 MiB、32 KiB を超える単一行は通常色のまま、キャプチャ数にも上限があります。これは構造的な構文強調であり、言語サーバーのセマンティックトークンではありません。
#API リファレンス
項目を展開すると説明と完全なシグネチャが表示されます。ダッシュは宣言に既定値が記載されていないことを示します。
Editor
ソースを見るpub 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) -> Selfソースを見るwith_stylepub fn with_style(mut self, style: EditorStyle) -> Self—
with_behaviorpub fn with_behavior(mut self, behavior: TextInputIndentation) -> Self—
Configures with behavior for this part.
pub fn with_behavior(mut self, behavior: TextInputIndentation) -> Selfソースを見るtextpub 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—
set_languagepub fn set_language(&mut self, language: SyntaxLanguage) -> bool—
Configures set language for this part.
pub fn set_language(&mut self, language: SyntaxLanguage) -> boolソースを見るset_stylepub fn set_style(&mut self, style: EditorStyle) -> bool—
set_behaviorpub fn set_behavior(&mut self, behavior: TextInputIndentation) -> bool—
Configures set behavior for this part.
pub fn set_behavior(&mut self, behavior: TextInputIndentation) -> boolソースを見るset_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) -> boolソースを見るrefresh_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) -> boolソースを見るEditor::element
ソースを見るpub fn element(&self, id: impl Into<ElementId>) -> ElementBuild the editor leaf. Attach a stable [`crate::InputListener`] with [`Element::on_input`](crate::Element::on_input).
