scene

package
v0.0.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 11, 2026 License: Apache-2.0 Imports: 2 Imported by: 0

README

Snapshot construction

github.com/moriyoshi/gpui-go/scene builds the low-level protobuf snapshots accepted by client. It has no client, native startup or reactive graph dependency.

Use Div, Text, TextInput, Image, Canvas and UniformList, with node methods for styling, interaction, actions and accessibility. Pixels, Percent, Rems, Auto, RGB and Padding construct protobuf style values. Builders are mutable and belong to their application's state goroutine; constructors, setters and Proto copy supplied data. Choose stable nonzero element IDs within a window.

Author views using public values from this package:

scene.Div(1, scene.Text(2, "Hello")).Style(&scene.Style{
    FlexDirection: scene.FlexColumn.Enum(),
    AlignItems:    scene.AlignCenter.Enum(),
    FontSize:      scene.Ptr[float32](15),
    Background:    scene.RGB(0x0f172a),
}).Accessible("Greeting", &scene.Accessibility{Role: scene.RoleText})

Public type aliases cover geometry/length/color, styles, interaction/accessibility, actions, drawing and snapshot values. Concise enum families are Flex*, Align*, Justify*, Overflow*, Cursor*, Position*, Display*, TextAlign*, Role* and Path*. Aliases preserve the protobuf type identity, accessors, enum .Enum() methods and serialization; existing generated-type callers remain compatible without conversion.

Use Ptr(value) for optional scalar fields. Explicit zero or false values stay present; nil means absent. For numeric fields, specify the type, such as Ptr[float32](0) or Ptr[uint32](600). Drawing oneof cases are DrawCommandRect and DrawCommandPath. Callback/event and client-service values live in client, including client.Event. Ordinary view authoring needs no generated-binding or protobuf-helper imports; raw wire envelopes remain available in gen/gpui/v1 for transport work.

Image(id, handle) takes an opaque protobuf resource handle. Upload and release the resource through the client, and pass resource.Handle() when constructing the snapshot. Image nodes copy that handle; snapshots do not own resource release.

InputState.Accept acknowledges native edit revisions. Reset advances the Go-owned epoch for an authoritative replacement. These operations preserve the existing native input ownership contract; see text input.

ui adds persistent reactive nodes above this snapshot API. The root gpui package retains aliases and forwarding builders for existing applications; its Image wrapper continues to accept *gpui.Resource.

Documentation

Overview

Package scene builds independently owned protobuf snapshots for GPUI. It contains no client, native runtime or reactive graph dependency.

Index

Constants

FlexDirection values use concise application-facing names.

Alignment values use concise application-facing names.

Justification values use concise application-facing names.

View Source
const (
	OverflowUnspecified = pb.Overflow_OVERFLOW_UNSPECIFIED
	OverflowVisible     = pb.Overflow_OVERFLOW_VISIBLE
	OverflowHidden      = pb.Overflow_OVERFLOW_HIDDEN
	OverflowScroll      = pb.Overflow_OVERFLOW_SCROLL
)

Overflow values use concise application-facing names.

View Source
const (
	CursorUnspecified = pb.Cursor_CURSOR_UNSPECIFIED
	CursorArrow       = pb.Cursor_CURSOR_ARROW
	CursorPointer     = pb.Cursor_CURSOR_POINTER
)

Cursor values use concise application-facing names.

View Source
const (
	PositionUnspecified = pb.Position_POSITION_UNSPECIFIED
	PositionRelative    = pb.Position_POSITION_RELATIVE
	PositionAbsolute    = pb.Position_POSITION_ABSOLUTE
)

Position values use concise application-facing names.

View Source
const (
	DisplayUnspecified = pb.Display_DISPLAY_UNSPECIFIED
	DisplayFlex        = pb.Display_DISPLAY_FLEX
	DisplayGrid        = pb.Display_DISPLAY_GRID
	DisplayNone        = pb.Display_DISPLAY_NONE
)

Display values use concise application-facing names.

View Source
const (
	ColorSchemeUnspecified = pb.ColorScheme_COLOR_SCHEME_UNSPECIFIED
	ColorSchemeLight       = pb.ColorScheme_COLOR_SCHEME_LIGHT
	ColorSchemeDark        = pb.ColorScheme_COLOR_SCHEME_DARK
)

ColorScheme values use concise application-facing names.

TextAlignment values use concise application-facing names.

AccessibleRole values use concise application-facing names.

PathVerb values use concise application-facing names.

Variables

This section is empty.

Functions

func Ptr

func Ptr[T any](value T) *T

Ptr sets an optional scalar field, including an explicit zero or false value. For numeric fields, specify the scalar type, for example Ptr[float32](15).

Types

type Accessibility

type Accessibility = pb.Accessibility

Interaction and accessibility values configure native behavior declaratively.

type AccessibleRole

type AccessibleRole = pb.AccessibleRole

Interaction and accessibility values configure native behavior declaratively.

type Action

type Action = pb.Action

Interaction and accessibility values configure native behavior declaratively.

type Alignment

type Alignment = pb.Alignment

Style values retain optional-field presence and generated enum methods.

type Bounds

type Bounds = pb.Bounds

Snapshot values are aliases of the wire types, preserving protobuf methods and identity.

type Color

type Color = pb.Color

Snapshot values are aliases of the wire types, preserving protobuf methods and identity.

func RGB

func RGB(value uint32) *Color

type ColorScheme added in v0.0.2

type ColorScheme = pb.ColorScheme

Style values retain optional-field presence and generated enum methods.

type ConditionalStyle added in v0.0.2

type ConditionalStyle = pb.ConditionalStyle

Style values retain optional-field presence and generated enum methods.

type Cursor

type Cursor = pb.Cursor

Style values retain optional-field presence and generated enum methods.

type Display

type Display = pb.Display

Style values retain optional-field presence and generated enum methods.

type DragData

type DragData = pb.DragData

Interaction and accessibility values configure native behavior declaratively.

type DrawCommand

type DrawCommand = pb.DrawCommand

Drawing values include the exported oneof cases used to construct commands.

type DrawCommandPath

type DrawCommandPath = pb.DrawCommand_Path

Drawing values include the exported oneof cases used to construct commands.

type DrawCommandRect

type DrawCommandRect = pb.DrawCommand_Rect

Drawing values include the exported oneof cases used to construct commands.

type DrawPath

type DrawPath = pb.DrawPath

Drawing values include the exported oneof cases used to construct commands.

type DrawRect

type DrawRect = pb.DrawRect

Drawing values include the exported oneof cases used to construct commands.

type Drawing

type Drawing = pb.Drawing

Drawing values include the exported oneof cases used to construct commands.

type Edges

type Edges = pb.Edges

Snapshot values are aliases of the wire types, preserving protobuf methods and identity.

func Padding

func Padding(value float32) *Edges

type Element

type Element = pb.Element

Snapshot values are aliases of the wire types, preserving protobuf methods and identity.

type EventBinding

type EventBinding = pb.EventBinding

Snapshot values are aliases of the wire types, preserving protobuf methods and identity.

type FlexDirection

type FlexDirection = pb.FlexDirection

Style values retain optional-field presence and generated enum methods.

type FocusTarget

type FocusTarget = pb.FocusTarget

Interaction and accessibility values configure native behavior declaratively.

type Handle

type Handle = pb.Handle

Snapshot values are aliases of the wire types, preserving protobuf methods and identity.

type InputState

type InputState struct {
	Value        string
	Epoch        uint64
	EditRevision uint64
}

InputState mirrors a native text field on the application's state-owning goroutine. Its zero value is an empty field. Reset is an explicit Go edit; Accept acknowledges native edits without disturbing selection or IME state.

func (*InputState) Accept

func (s *InputState) Accept(change *TextChanged) bool

func (*InputState) Reset

func (s *InputState) Reset(value string)

type Interaction

type Interaction = pb.Interaction

Interaction and accessibility values configure native behavior declaratively.

type Justification

type Justification = pb.Justification

Style values retain optional-field presence and generated enum methods.

type KeyBinding

type KeyBinding = pb.KeyBinding

Interaction and accessibility values configure native behavior declaratively.

type Length

type Length = pb.Length

Snapshot values are aliases of the wire types, preserving protobuf methods and identity.

func Auto

func Auto() *Length

func Percent

func Percent(value float32) *Length

func Pixels

func Pixels(value float32) *Length

func Rems

func Rems(value float32) *Length

type Modifiers

type Modifiers = pb.Modifiers

Snapshot values are aliases of the wire types, preserving protobuf methods and identity.

type Node

type Node struct {
	// contains filtered or unexported fields
}

Node is a builder for a protobuf element snapshot. Builders are mutable and should remain on their owner's goroutine. Proto returns an independent copy.

func Canvas

func Canvas(id uint64, commands ...*DrawCommand) *Node

Canvas submits local-coordinate drawing commands to GPUI. Paths are filled when stroke_width is zero, otherwise stroked. No Go paint callback is used.

func Div

func Div(id uint64, children ...*Node) *Node

func Embedded

func Embedded(id, instance uint64) *Node

Embedded places a native view owned by a host extension, such as an embedded Zed editor. Each instance can appear once per view. The backend must support the embedded-views capability.

func FromProto

func FromProto(element *Element) *Node

FromProto copies a caller-supplied element. Unsupported models are rejected by the bridge, rather than silently discarded.

func Image

func Image(id uint64, resource *Handle) *Node

func Text

func Text(id uint64, text string) *Node

func TextInput

func TextInput(id uint64, value InputState, options TextInputOptions) *Node

TextInput builds a single-line editable field. Style its container with width, padding, colors, and borders as for any other Node. Newlines are normalized to spaces for native typing/paste. Input values are limited to 64 KiB. Reuse the same element ID to retain focus and selection.

func UniformList

func UniformList(id uint64, rowHeight float32, rows ...*Node) *Node

UniformList virtualizes native layout/painting. Go supplies all row snapshots up front; this is not a paging protocol. The normal snapshot limits apply.

func (*Node) Accessible

func (n *Node) Accessible(label string, metadata *Accessibility) *Node

func (*Node) Animate

func (n *Node) Animate(animation *OpacityAnimation) *Node

func (*Node) BindKey

func (n *Node) BindKey(keystroke string, action *Action, handlerID uint64) *Node

BindKey attaches a native shortcut to this node's subtree. Chords use GPUI's native multi-stroke matching. The node is made focusable automatically.

func (*Node) BindKeyWithContext

func (n *Node) BindKeyWithContext(keystroke, predicate string, action *Action, handlerID uint64) *Node

BindKeyWithContext adds a shortcut with a GPUI keymap predicate, evaluated against Interaction.KeyContext on the native focus path.

func (*Node) Focusable

func (n *Node) Focusable(tabIndex int32) *Node

func (*Node) Hover

func (n *Node) Hover(style *Style) *Node

Hover adds a partial style refinement applied by GPUI while hovered. It does not require a Go event or another view snapshot.

func (*Node) Interact

func (n *Node) Interact(options *Interaction) *Node

func (*Node) OnAction

func (n *Node) OnAction(name string, handlerID uint64) *Node

OnAction binds a logical action for programmatic/native menu dispatch.

func (*Node) OnClick

func (n *Node) OnClick(handlerID uint64) *Node

func (*Node) Proto

func (n *Node) Proto() *Element

func (*Node) StopPropagation

func (n *Node) StopPropagation() *Node

func (*Node) Style

func (n *Node) Style(style *Style) *Node

func (*Node) When added in v0.0.2

func (n *Node) When(conditions ...*ConditionalStyle) *Node

When sets refinements that GPUI applies while the window matches each one's width range and color scheme, without a Go event or another snapshot. The backend needs the conditional-styles capability.

type OpacityAnimation

type OpacityAnimation = pb.OpacityAnimation

Style values retain optional-field presence and generated enum methods.

type Overflow

type Overflow = pb.Overflow

Style values retain optional-field presence and generated enum methods.

type PathStep

type PathStep = pb.PathStep

Drawing values include the exported oneof cases used to construct commands.

type PathVerb

type PathVerb = pb.PathVerb

Drawing values include the exported oneof cases used to construct commands.

type Point

type Point = pb.Point

Snapshot values are aliases of the wire types, preserving protobuf methods and identity.

type Position

type Position = pb.Position

Style values retain optional-field presence and generated enum methods.

type Shadow

type Shadow = pb.Shadow

Style values retain optional-field presence and generated enum methods.

type Size

type Size = pb.Size

Snapshot values are aliases of the wire types, preserving protobuf methods and identity.

type Style

type Style = pb.Style

Style values retain optional-field presence and generated enum methods.

type TextAlignment

type TextAlignment = pb.TextAlignment

Style values retain optional-field presence and generated enum methods.

type TextChanged

type TextChanged = pb.TextChanged

Snapshot values are aliases of the wire types, preserving protobuf methods and identity.

type TextInputOptions

type TextInputOptions struct {
	Placeholder string
	OnChange    uint64
	Disabled    bool
	// Masked draws bullets instead of the text and blocks copy and cut. Change
	// events still carry the real value.
	Masked bool
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL