CodeBlock
Tree-sitter カラーリングと論理行の仮想化を備えた、選択可能でキャレットのないコード表示です。
既定では言語文法を含みません。Rust はリンク済み文法を登録でき、Go / TypeScript は LoadLanguagePack / loadLanguagePack で選択した Tree-sitter Wasm 文法とクエリをまとめた単一の移植可能なパックを読み込めます。
既定では見た目のスタイルを持ちません。文字と行番号の色は継承され、背景、枠線、角丸、余白、構文・差分の配色は追加されません。外観はアプリ側で明示的に指定します。
#インポート
go get github.com/egoist/quickgui/extensions/editorimport (
"github.com/egoist/quickgui/extensions/editor"
"github.com/egoist/quickgui/go/ui"
)#使い方
func CodeExample() *ui.Element {
return editor.CodeBlock(editor.CodeBlockProps{
Value: "package main\n\nfunc main() {}\n",
Language: "go",
LineNumbers: true,
Wrap: false,
Props: ui.Props{Style: ui.Style().Width("100%").Height(280)},
})
}#シンタックスハイライト
Language は同梱の Tree-sitter 文法とハイライトクエリを選択します。キャプチャは SyntaxTheme を通して前景色だけの範囲へ変換されるため、ハイライトはレイアウトを変えません。Rust コアはソースまたは言語が変わったときに解析し、スクロール時は論理行をマウントして事前計算済みの範囲を生成するだけです。解析は最大 2 MiB、32 KiB を超える単一行は通常色のまま、キャプチャ数にも上限があります。
#API リファレンス
項目を展開すると説明と完全なシグネチャが表示されます。ダッシュは宣言に既定値が記載されていないことを示します。
editor.CodeBlock
ソースを見るeditor.CodeBlock(props CodeBlockProps) *ui.ElementStyleStyleBuilder—
Reusable layout, typography, color, and interaction-state styles. Build with ui.Style() and compose with Merge.
StyleBuilderソースを見るChildrenany—
Content mounted inside the component. Compound child callbacks run after the parent context exists.
anyソースを見るOnClickfunc(*native.Event)—
Called after QuickGUI resolves an activation, including supported keyboard activation.
func(*native.Event)ソースを見るOnMouseEnterfunc(*native.Event)—
OnMouseLeavefunc(*native.Event)—
OnInputfunc(*native.Event)—
Receives edits from the text control. Write the new text into the controlled value.
func(*native.Event)ソースを見るOnSubmitfunc(*native.Event)—
OnDismissfunc(*native.Event)—
OnPointerfunc(*native.Event)—
OnPresentationChangefunc(*native.Event)—
Callback for presentation change. The signature below lists the event payload.
func(*native.Event)ソースを見るOnSelectfunc(*native.Event)—
OnKeyDownfunc(*native.Event)—
OnKeyUpfunc(*native.Event)—
OnMouseDownfunc(*native.Event)—
OnMouseUpfunc(*native.Event)—
OnMouseMovefunc(*native.Event)—
OnDoubleClickfunc(*native.Event)—
OnWheelfunc(*native.Event)—
OnContextMenufunc(*native.Event)—
OnPinchfunc(*native.Event)—
OnRotatefunc(*native.Event)—
OnSmartMagnifyfunc(*native.Event)—
OnPressurefunc(*native.Event)—
OnFocusfunc(*native.Event)—
OnBlurfunc(*native.Event)—
OnActionfunc(*native.Event)—
OnDragStartfunc(*native.Event)—
OnDragEndfunc(*native.Event)—
OnDropfunc(*native.Event)—
OnFilesDroppedfunc(*native.Event)—
OnComponentChangefunc(*native.Event)—
Receives the component change payload, including values for coordinated controls.
func(*native.Event)ソースを見るOnCommitfunc(*native.Event)—
Disabledany—
Prevents activation and exposes the disabled state to accessibility. Compound parts inherit a disabled root.
anyソースを見るValueany—
The current controlled value. Update application state from the change callback to accept a new value.
anyソースを見るPlaceholderstring—
Multilinebool—
AriaLabelany—
Selectedany—
Groupany—
FocusOnPointerany—
FocusableWhenDisabledany—
HitSlopany—
HitSlopTopany—
HitSlopRightany—
HitSlopBottomany—
HitSlopLeftany—
Reffunc(*native.Node)—
Receives the retained native node after construction. Keep imperative work in event or lifecycle callbacks.
func(*native.Node)ソースを見るPasswordany—
EstimatedItemHeightany—
Overscanany—
OverscanPixelsany—
ItemHeightsany—
ListAlignmentstring—
FollowModestring—
ObjectFitstring—
ShaderParametersany—
Invalidany—
Roleany—
TabIndexany—
Controls sequential keyboard focus order. Omit to retain the component’s default focus behavior.
anyソースを見るOverlayany—
FocusTrapany—
RestorePreviousFocusany—
AutoFocusany—
AriaModalany—
DismissOnEscapeany—
DismissOnPointerOutsideany—
TooltipTextany—
TooltipPlacementany—
TooltipDelayany—
TooltipGapany—
TooltipViewportMarginany—
AnchorTargetany—
AnchorPlacementany—
AnchorGapany—
ViewportMarginany—
Keymapany—
Draggableany—
DropKindsany—
ContentPaddingContentPadding—
Configures content padding for this part. The declared type and source define the accepted value.
ContentPaddingソースを見るGutterPaddingGutterPadding—
Configures gutter padding for this part. The declared type and source define the accepted value.
GutterPaddingソースを見るLanguageany—
LineNumbersany—
Configures line numbers for this part. The declared type and source define the accepted value.
anyソースを見るWrapany—
GutterBackgroundany—
GutterColorany—
Configures gutter color for this part. The declared type and source define the accepted value.
anyソースを見るSyntaxThemeSyntaxTheme—
Configures syntax theme for this part. The declared type and source define the accepted value.
SyntaxThemeソースを見る