CodeBlock
Selectable, caret-free source code with Tree-sitter coloring and virtualized logical rows.
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
go get github.com/egoist/quickgui/extensions/editorimport (
"github.com/egoist/quickgui/extensions/editor"
"github.com/egoist/quickgui/go/ui"
)#Usage
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)},
})
}#Syntax highlighting
Language selects a registered Tree-sitter grammar and highlight query. Captures map through SyntaxTheme to foreground-only spans, so highlighting does not change layout. The Rust core parses when source or language changes; scrolling only mounts logical rows and materializes their precomputed spans. Parsing is limited to 2 MiB, individual lines over 32 KiB stay plain, and the capture count is capped.
#API reference
Expand an entry for its description and complete signature. A dash means no declaration default is documented.
editor.CodeBlock
View sourceeditor.CodeBlock(props CodeBlockProps) *ui.ElementStyleStyleBuilder—
Reusable layout, typography, color, and interaction-state styles. Build with ui.Style() and compose with Merge.
StyleBuilderView sourceChildrenany—
Content mounted inside the component. Compound child callbacks run after the parent context exists.
anyView sourceOnClickfunc(*native.Event)—
Called after QuickGUI resolves an activation, including supported keyboard activation.
func(*native.Event)View sourceOnMouseEnterfunc(*native.Event)—
Callback for mouse enter. The signature below lists the event payload.
func(*native.Event)View sourceOnMouseLeavefunc(*native.Event)—
Callback for mouse leave. The signature below lists the event payload.
func(*native.Event)View sourceOnInputfunc(*native.Event)—
Receives edits from the text control. Write the new text into the controlled value.
func(*native.Event)View sourceOnSubmitfunc(*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)View sourceOnSelectfunc(*native.Event)—
OnKeyDownfunc(*native.Event)—
OnKeyUpfunc(*native.Event)—
OnMouseDownfunc(*native.Event)—
OnMouseUpfunc(*native.Event)—
OnMouseMovefunc(*native.Event)—
OnDoubleClickfunc(*native.Event)—
Callback for double click. The signature below lists the event payload.
func(*native.Event)View sourceOnWheelfunc(*native.Event)—
OnContextMenufunc(*native.Event)—
Callback for context menu. The signature below lists the event payload.
func(*native.Event)View sourceOnPinchfunc(*native.Event)—
OnRotatefunc(*native.Event)—
OnSmartMagnifyfunc(*native.Event)—
Callback for smart magnify. The signature below lists the event payload.
func(*native.Event)View sourceOnPressurefunc(*native.Event)—
OnFocusfunc(*native.Event)—
OnBlurfunc(*native.Event)—
OnActionfunc(*native.Event)—
OnDragStartfunc(*native.Event)—
OnDragEndfunc(*native.Event)—
OnDropfunc(*native.Event)—
OnFilesDroppedfunc(*native.Event)—
Callback for files dropped. The signature below lists the event payload.
func(*native.Event)View sourceOnComponentChangefunc(*native.Event)—
Receives the component change payload, including values for coordinated controls.
func(*native.Event)View sourceOnCommitfunc(*native.Event)—
Disabledany—
Prevents activation and exposes the disabled state to accessibility. Compound parts inherit a disabled root.
anyView sourceValueany—
The current controlled value. Update application state from the change callback to accept a new value.
anyView sourcePlaceholderstring—
Multilinebool—
AriaLabelany—
Accessible name, especially for icon-only controls or controls without a visible label.
anyView sourceSelectedany—
Groupany—
FocusOnPointerany—
FocusableWhenDisabledany—
Allows a disabled button to remain keyboard focusable while activation stays disabled.
anyView sourceHitSlopany—
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)View sourcePasswordany—
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.
anyView sourceOverlayany—
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.
ContentPaddingView sourceGutterPaddingGutterPadding—
Configures gutter padding for this part. The declared type and source define the accepted value.
GutterPaddingView sourceLanguageany—
Configures language for this part. The declared type and source define the accepted value.
anyView sourceLineNumbersany—
Configures line numbers for this part. The declared type and source define the accepted value.
anyView sourceWrapany—
Configures wrap for this part. The declared type and source define the accepted value.
anyView sourceGutterBackgroundany—
GutterColorany—
Configures gutter color for this part. The declared type and source define the accepted value.
anyView sourceSyntaxThemeSyntaxTheme—
Configures syntax theme for this part. The declared type and source define the accepted value.
SyntaxThemeView source