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查看源码