跳到正文

CodeBlock

可选择、无插入光标的代码视图,支持 Tree-sitter 着色和逻辑行虚拟化。

默认不包含任何语言语法。Rust 可注册静态链接的语法;Go 和 TypeScript 可通过 LoadLanguagePack / loadLanguagePack 加载单个跨平台包,其中包含所选 Tree-sitter Wasm 语法与查询。

组件默认不带视觉样式:文本和行号继承颜色,不添加背景、边框、圆角、内边距或语法/差异配色。外观由应用显式提供样式与颜色。

#导入

go get github.com/egoist/quickgui/extensions/editor
import (
	"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.Element
StyleStyleBuilder—

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

Callback for mouse enter. The signature below lists the event payload.

func(*native.Event)
查看源码
OnMouseLeavefunc(*native.Event)—

Callback for mouse leave. The signature below lists the event payload.

func(*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)—

Called when the control submits its current value.

func(*native.Event)
查看源码
OnDismissfunc(*native.Event)—

Reports toast identifiers dismissed by the core.

func(*native.Event)
查看源码
OnPointerfunc(*native.Event)—

Callback for pointer. The signature below lists the event payload.

func(*native.Event)
查看源码
OnPresentationChangefunc(*native.Event)—

Callback for presentation change. The signature below lists the event payload.

func(*native.Event)
查看源码
OnSelectfunc(*native.Event)—

Reports the menu entry selected by the core.

func(*native.Event)
查看源码
OnKeyDownfunc(*native.Event)—

Callback for key down. The signature below lists the event payload.

func(*native.Event)
查看源码
OnKeyUpfunc(*native.Event)—

Callback for key up. The signature below lists the event payload.

func(*native.Event)
查看源码
OnMouseDownfunc(*native.Event)—

Callback for mouse down. The signature below lists the event payload.

func(*native.Event)
查看源码
OnMouseUpfunc(*native.Event)—

Callback for mouse up. The signature below lists the event payload.

func(*native.Event)
查看源码
OnMouseMovefunc(*native.Event)—

Callback for mouse move. The signature below lists the event payload.

func(*native.Event)
查看源码
OnDoubleClickfunc(*native.Event)—

Callback for double click. The signature below lists the event payload.

func(*native.Event)
查看源码
OnWheelfunc(*native.Event)—

Callback for wheel. The signature below lists the event payload.

func(*native.Event)
查看源码
OnContextMenufunc(*native.Event)—

Callback for context menu. The signature below lists the event payload.

func(*native.Event)
查看源码
OnPinchfunc(*native.Event)—

Callback for pinch. The signature below lists the event payload.

func(*native.Event)
查看源码
OnRotatefunc(*native.Event)—

Callback for rotate. The signature below lists the event payload.

func(*native.Event)
查看源码
OnSmartMagnifyfunc(*native.Event)—

Callback for smart magnify. The signature below lists the event payload.

func(*native.Event)
查看源码
OnPressurefunc(*native.Event)—

Callback for pressure. The signature below lists the event payload.

func(*native.Event)
查看源码
OnFocusfunc(*native.Event)—

Callback for focus. The signature below lists the event payload.

func(*native.Event)
查看源码
OnBlurfunc(*native.Event)—

Callback for blur. The signature below lists the event payload.

func(*native.Event)
查看源码
OnActionfunc(*native.Event)—

Callback for action. The signature below lists the event payload.

func(*native.Event)
查看源码
OnDragStartfunc(*native.Event)—

Callback for drag start. The signature below lists the event payload.

func(*native.Event)
查看源码
OnDragEndfunc(*native.Event)—

Callback for drag end. The signature below lists the event payload.

func(*native.Event)
查看源码
OnDropfunc(*native.Event)—

Callback for drop. The signature below lists the event payload.

func(*native.Event)
查看源码
OnFilesDroppedfunc(*native.Event)—

Callback for files dropped. The signature below lists the event payload.

func(*native.Event)
查看源码
OnComponentChangefunc(*native.Event)—

Receives the component change payload, including values for coordinated controls.

func(*native.Event)
查看源码
OnCommitfunc(*native.Event)—

Reports one explicit commit boundary and its final value details.

func(*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—

Hint displayed while the text value is empty.

string
查看源码
Multilinebool—

Allows multiple lines in the core text editor.

bool
查看源码
AriaLabelany—

Accessible name, especially for icon-only controls or controls without a visible label.

any
查看源码
Selectedany—

Exposes the selected state of this item.

any
查看源码
Groupany—

Names this element as a group for descendant interaction-state styling.

any
查看源码
FocusOnPointerany—

Whether a pointer press moves keyboard focus to the control.

any
查看源码
FocusableWhenDisabledany—

Allows a disabled button to remain keyboard focusable while activation stays disabled.

any
查看源码
HitSlopany—

Expands the pointer hit area without changing the visual bounds.

any
查看源码
HitSlopTopany—

Extra pointer hit area above the visual bounds.

any
查看源码
HitSlopRightany—

Extra pointer hit area to the right of the visual bounds.

any
查看源码
HitSlopBottomany—

Extra pointer hit area below the visual bounds.

any
查看源码
HitSlopLeftany—

Extra pointer hit area to the left of the visual bounds.

any
查看源码
Reffunc(*native.Node)—

Receives the retained native node after construction. Keep imperative work in event or lifecycle callbacks.

func(*native.Node)
查看源码
Passwordany—

Conceals the entered text while preserving the editor’s value.

any
查看源码
EstimatedItemHeightany—

Initial logical row-height estimate used by virtualization.

any
查看源码
Overscanany—

Extra rows mounted before and after the visible range.

any
查看源码
OverscanPixelsany—

Extra logical distance mounted before and after the visible range.

any
查看源码
ItemHeightsany—

Exact row heights supplied without waiting for layout measurement.

any
查看源码
ListAlignmentstring—

Pins short list content to the top or bottom.

string
查看源码
FollowModestring—

Chooses ordinary scrolling or tail-following behavior.

string
查看源码
ObjectFitstring—

How image content fits its declared box.

string
查看源码
ShaderParametersany—

Up to sixteen numeric values packed into fixed shader parameter vectors.

any
查看源码
Invalidany—

Projects invalid state to the field and its parts.

any
查看源码
Roleany—

Accessibility role override. Prefer the component’s built-in semantics.

any
查看源码
TabIndexany—

Controls sequential keyboard focus order. Omit to retain the component’s default focus behavior.

any
查看源码
Overlayany—

Places this content in the overlay paint plane.

any
查看源码
FocusTrapany—

Keeps keyboard focus within the active modal surface.

any
查看源码
RestorePreviousFocusany—

Restores the previously focused element when the surface closes.

any
查看源码
AutoFocusany—

Requests initial keyboard focus when the element mounts.

any
查看源码
AriaModalany—

Exposes the modal state of the surface to accessibility.

any
查看源码
DismissOnEscapeany—

Allows Escape to dismiss the surface.

any
查看源码
DismissOnPointerOutsideany—

Allows a pointer press outside the surface to dismiss it.

any
查看源码
TooltipTextany—

Text displayed by the element’s tooltip.

any
查看源码
TooltipPlacementany—

Preferred side and alignment of the tooltip.

any
查看源码
TooltipDelayany—

Delay before the tooltip opens.

any
查看源码
TooltipGapany—

Space between the tooltip and its trigger.

any
查看源码
TooltipViewportMarginany—

Minimum space between the tooltip and the window edges.

any
查看源码
AnchorTargetany—

Identity of the element used to position the surface.

any
查看源码
AnchorPlacementany—

Preferred side and alignment relative to the anchor.

any
查看源码
AnchorGapany—

Space between the anchor and its surface, in logical pixels.

any
查看源码
ViewportMarginany—

Minimum space reserved around the surface within the viewport.

any
查看源码
Keymapany—

Keyboard bindings used by the editor.

any
查看源码
Draggableany—

Enables the element as a drag source.

any
查看源码
DropKindsany—

Kinds of drop payload this target accepts.

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

Configures language for this part. The declared type and source define the accepted value.

any
查看源码
LineNumbersany—

Configures line numbers for this part. The declared type and source define the accepted value.

any
查看源码
Wrapany—

Configures wrap for this part. The declared type and source define the accepted value.

any
查看源码
GutterBackgroundany—

Overrides the line-number gutter background.

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