本文へスキップ

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 リファレンス

項目を展開すると説明と完全なシグネチャが表示されます。ダッシュは宣言に既定値が記載されていないことを示します。

pub fn new() -> Self
with_textpub fn with_text(source: &str) -> Self—

Configures with text for this part.

pub 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—

Configures with style for this part.

pub 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—

Configures text for this part.

pub fn text(&self) -> &str
ソースを見る
languagepub const fn language(&self) -> SyntaxLanguage—

Configures language for this part.

pub const fn language(&self) -> SyntaxLanguage
ソースを見る
stylepub const fn style(&self) -> EditorStyle—

Configures style for this part.

pub const fn style(&self) -> EditorStyle
ソースを見る
behaviorpub const fn behavior(&self) -> TextInputIndentation—

Configures behavior for this part.

pub const fn behavior(&self) -> TextInputIndentation
ソースを見る
is_truncatedpub const fn is_truncated(&self) -> bool—

Configures is truncated for this part.

pub 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) -> 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—

Configures set style for this part.

pub 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>) -> Element

Build the editor leaf. Attach a stable [`crate::InputListener`] with [`Element::on_input`](crate::Element::on_input).