render

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package render is the wire protocol between the ui runtime (Go) and a host's native renderer. Its generated Swift and Java ship inside the host kits: regenerate with `go test ./ui/render -update` after changing it.

Lengths are points (iOS) / dp (Android). Colors are 0xRRGGBBAA; 0 means unset (transparent background, default text color).

Index

Constants

View Source
const SchemaHash uint64 = 0x9f8e24ae5a72a614

SchemaHash identifies this schema's wire layout. Hosts pass it (combined with any other schemas) to nn_start, which refuses a mismatch.

Variables

This section is empty.

Functions

func AppendMessage

func AppendMessage(b []byte, v Message) []byte

AppendMessage appends a Message: its variant index (0 for nil), then the variant.

func AppendOp

func AppendOp(b []byte, v Op) []byte

AppendOp appends a Op: its variant index (0 for nil), then the variant.

func Encode

func Encode(m Message) []byte

Encode returns m's wire encoding: its message id, then its fields.

Types

type Align

type Align uint8

Align is horizontal text alignment.

const (
	AlignStart Align = iota
	AlignCenter
	AlignEnd
)

type Box

type Box struct {
	Tag         uint32
	Background  uint32
	Radius      float32
	BorderWidth float32
	BorderColor uint32
	Opacity     float32 // 0..1
	Clip        bool
	Label       string // accessibility label
	TestID      string // accessibilityIdentifier / view tag, for tests
	Href        string // where a pressable leads (the web host makes it a link)
}

Box is the visual style every view kind shares.

func (*Box) AppendWire

func (m *Box) AppendWire(b []byte) []byte

AppendWire appends m's wire encoding to b.

func (*Box) ReadWire

func (m *Box) ReadWire(r *wire.Reader)

ReadWire decodes m from r. Check r.Err() afterwards.

type Changed

type Changed struct {
	Tag  uint32
	Text string
}

Changed reports an input's new text.

func (*Changed) AppendWire

func (m *Changed) AppendWire(b []byte) []byte

AppendWire appends m's wire encoding to b.

func (*Changed) ReadWire

func (m *Changed) ReadWire(r *wire.Reader)

ReadWire decodes m from r. Check r.Err() afterwards.

type Children

type Children struct {
	Tag      uint32
	Children []uint32
}

Children sets a view's child views, in order. Views of Tag not listed are removed. For a scroll view the children go in its content.

func (*Children) AppendWire

func (m *Children) AppendWire(b []byte) []byte

AppendWire appends m's wire encoding to b.

func (*Children) ReadWire

func (m *Children) ReadWire(r *wire.Reader)

ReadWire decodes m from r. Check r.Err() afterwards.

type Chrome

type Chrome struct {
	Dark       bool
	Background uint32 // screens, modals, the root
	Text       uint32
	TextMuted  uint32 // unselected tabs
	Accent     uint32 // back buttons, selected tabs
	Bar        uint32 // navigation and tab bar backgrounds
	BarText    uint32 // titles on bars
	Border     uint32 // bar separators
}

Chrome is the theme for what the host draws itself: navigation and tab bars, screen and modal backgrounds, the status bar. Sent when it changes.

func (*Chrome) AppendWire

func (m *Chrome) AppendWire(b []byte) []byte

AppendWire appends m's wire encoding to b.

func (*Chrome) ReadWire

func (m *Chrome) ReadWire(r *wire.Reader)

ReadWire decodes m from r. Check r.Err() afterwards.

type Commit

type Commit struct {
	Seq  uint64
	Root uint32 // the root view's tag, when it changes; 0 otherwise
	Ops  []Op

	// Where the time went in Go, for diagnostics.
	BuildNs  uint64 // components and reconciliation
	LayoutNs uint64 // flexbox, including text measurement
	Measures uint32 // text measurements that reached the host
}

Commit is one render: apply its ops in order, in one UI-thread pass.

func (*Commit) AppendWire

func (m *Commit) AppendWire(b []byte) []byte

AppendWire appends m's wire encoding to b.

func (*Commit) ReadWire

func (m *Commit) ReadWire(r *wire.Reader)

ReadWire decodes m from r. Check r.Err() afterwards.

type Create

type Create struct {
	Tag  uint32
	Kind Kind
}

Create makes a view for Tag. It is not shown until a Children op places it.

func (*Create) AppendWire

func (m *Create) AppendWire(b []byte) []byte

AppendWire appends m's wire encoding to b.

func (*Create) ReadWire

func (m *Create) ReadWire(r *wire.Reader)

ReadWire decodes m from r. Check r.Err() afterwards.

type Destroy

type Destroy struct{ Tags []uint32 }

Destroy forgets views (and removes them from their parents).

func (*Destroy) AppendWire

func (m *Destroy) AppendWire(b []byte) []byte

AppendWire appends m's wire encoding to b.

func (*Destroy) ReadWire

func (m *Destroy) ReadWire(r *wire.Reader)

ReadWire decodes m from r. Check r.Err() afterwards.

type Dismissed

type Dismissed struct{ Tag uint32 }

Dismissed reports that the user closed a modal (swipe down, back button).

func (*Dismissed) AppendWire

func (m *Dismissed) AppendWire(b []byte) []byte

AppendWire appends m's wire encoding to b.

func (*Dismissed) ReadWire

func (m *Dismissed) ReadWire(r *wire.Reader)

ReadWire decodes m from r. Check r.Err() afterwards.

type Fit

type Fit uint8

Fit is how an image fills its frame.

const (
	FitCover Fit = iota
	FitContain
	FitStretch
)

type Font

type Font struct {
	Size   float32
	Weight uint16 // 100..900; 0 means 400
}

Font is shared by text, inputs and measurement.

func (*Font) AppendWire

func (m *Font) AppendWire(b []byte) []byte

AppendWire appends m's wire encoding to b.

func (*Font) ReadWire

func (m *Font) ReadWire(r *wire.Reader)

ReadWire decodes m from r. Check r.Err() afterwards.

type Frame

type Frame struct {
	Tag        uint32
	X, Y, W, H float32
}

Frame places a view relative to its parent (scroll views: their content).

func (*Frame) AppendWire

func (m *Frame) AppendWire(b []byte) []byte

AppendWire appends m's wire encoding to b.

func (*Frame) ReadWire

func (m *Frame) ReadWire(r *wire.Reader)

ReadWire decodes m from r. Check r.Err() afterwards.

type Image

type Image struct {
	Tag uint32
	URL string
	Fit Fit
}

func (*Image) AppendWire

func (m *Image) AppendWire(b []byte) []byte

AppendWire appends m's wire encoding to b.

func (*Image) ReadWire

func (m *Image) ReadWire(r *wire.Reader)

ReadWire decodes m from r. Check r.Err() afterwards.

type Input

type Input struct {
	Tag         uint32
	Value       string
	Placeholder string
	Font        Font
	Color       uint32
	Secure      bool
	Keyboard    Keyboard
	Multiline   bool // wraps and grows with Return making new lines
}

Input sets a text field. The host replaces the field's text only when it differs, so typing is never interrupted.

func (*Input) AppendWire

func (m *Input) AppendWire(b []byte) []byte

AppendWire appends m's wire encoding to b.

func (*Input) ReadWire

func (m *Input) ReadWire(r *wire.Reader)

ReadWire decodes m from r. Check r.Err() afterwards.

type Keyboard

type Keyboard uint8

Keyboard is the soft keyboard an input asks for.

const (
	KeyboardText Keyboard = iota
	KeyboardNumber
	KeyboardEmail
	KeyboardURL
)

type Kind

type Kind uint8

Kind is the native view a tag stands for.

const (
	KindView Kind = iota
	KindText
	KindImage
	KindPressable
	KindScroll
	KindInput
	KindSpinner
	// KindStack is a navigation stack: its children are screens, shown one
	// at a time under a native bar, with native push / pop transitions.
	KindStack
	// KindTabs is a tab bar: its children are the tabs' root views, one
	// shown at a time above the native tab bar.
	KindTabs
	// KindModal is a view presented over everything (a sheet on iOS). It is
	// not placed by a Children op: Present shows it, Destroy dismisses it.
	KindModal
	// KindSwitch is an on/off toggle: UISwitch, Android's Switch.
	KindSwitch
)

type MeasureText

type MeasureText struct {
	Text     string
	Font     Font
	MaxWidth float32 // < 0: no limit
	Lines    uint32
}

MeasureText asks the host for a text's size (synchronous host call).

func (*MeasureText) AppendWire

func (m *MeasureText) AppendWire(b []byte) []byte

AppendWire appends m's wire encoding to b.

func (*MeasureText) ReadWire

func (m *MeasureText) ReadWire(r *wire.Reader)

ReadWire decodes m from r. Check r.Err() afterwards.

type Message

type Message interface {
	// contains filtered or unexported methods
}

Message is any top-level message in this schema.

func Decode

func Decode(b []byte) (Message, error)

Decode reads exactly one message.

func ReadMessage

func ReadMessage(r *wire.Reader) Message

ReadMessage decodes a Message (nil for index 0).

type Op

type Op interface {
	// contains filtered or unexported methods
}

Op changes one native view.

func ReadOp

func ReadOp(r *wire.Reader) Op

ReadOp decodes a Op (nil for index 0).

type PluginAck

type PluginAck struct{ Err string }

PluginAck answers PluginCall: Err is empty when the call started.

func (*PluginAck) AppendWire

func (m *PluginAck) AppendWire(b []byte) []byte

AppendWire appends m's wire encoding to b.

func (*PluginAck) ReadWire

func (m *PluginAck) ReadWire(r *wire.Reader)

ReadWire decodes m from r. Check r.Err() afterwards.

type PluginCall

type PluginCall struct {
	ID     uint64
	Plugin string
	Method string
	Args   string
}

PluginCall asks a native plugin to run a method (synchronous host call). The host answers at once with PluginAck and sends the outcome later as a PluginResult with the same ID. Args and results are JSON.

func (*PluginCall) AppendWire

func (m *PluginCall) AppendWire(b []byte) []byte

AppendWire appends m's wire encoding to b.

func (*PluginCall) ReadWire

func (m *PluginCall) ReadWire(r *wire.Reader)

ReadWire decodes m from r. Check r.Err() afterwards.

type PluginResult

type PluginResult struct {
	ID    uint64
	Value string
	Code  string
	Err   string
}

PluginResult is a plugin call's outcome. A failure has a Code ("unavailable", "cancelled", "denied", "not_found", "failed") and Err.

func (*PluginResult) AppendWire

func (m *PluginResult) AppendWire(b []byte) []byte

AppendWire appends m's wire encoding to b.

func (*PluginResult) ReadWire

func (m *PluginResult) ReadWire(r *wire.Reader)

ReadWire decodes m from r. Check r.Err() afterwards.

type Popped

type Popped struct {
	Tag   uint32
	Depth uint32
}

Popped reports that the user went back in a stack (back button, swipe or system back), leaving Depth screens.

func (*Popped) AppendWire

func (m *Popped) AppendWire(b []byte) []byte

AppendWire appends m's wire encoding to b.

func (*Popped) ReadWire

func (m *Popped) ReadWire(r *wire.Reader)

ReadWire decodes m from r. Check r.Err() afterwards.

type Present

type Present struct{ Tag uint32 }

Present shows a KindModal view over the app, with the platform's transition.

func (*Present) AppendWire

func (m *Present) AppendWire(b []byte) []byte

AppendWire appends m's wire encoding to b.

func (*Present) ReadWire

func (m *Present) ReadWire(r *wire.Reader)

ReadWire decodes m from r. Check r.Err() afterwards.

type Press

type Press struct{ Tag uint32 }

Press reports a tap on a pressable.

func (*Press) AppendWire

func (m *Press) AppendWire(b []byte) []byte

AppendWire appends m's wire encoding to b.

func (*Press) ReadWire

func (m *Press) ReadWire(r *wire.Reader)

ReadWire decodes m from r. Check r.Err() afterwards.

type Reattach

type Reattach struct{ Reason string }

Reattach reports a new native view hierarchy for a runtime that is already running (an Android activity created again): Go sends every view again, and the UI carries on with its state.

func (*Reattach) AppendWire

func (m *Reattach) AppendWire(b []byte) []byte

AppendWire appends m's wire encoding to b.

func (*Reattach) ReadWire

func (m *Reattach) ReadWire(r *wire.Reader)

ReadWire decodes m from r. Check r.Err() afterwards.

type Refresh

type Refresh struct{ Tag uint32 }

Refresh reports that the user pulled a refreshable scroll view.

func (*Refresh) AppendWire

func (m *Refresh) AppendWire(b []byte) []byte

AppendWire appends m's wire encoding to b.

func (*Refresh) ReadWire

func (m *Refresh) ReadWire(r *wire.Reader)

ReadWire decodes m from r. Check r.Err() afterwards.

type Resized

type Resized struct {
	Tag    uint32
	W, H   float32
	Bottom float32
}

Resized reports the size a stack or tab bar gives its screens. Bottom is how much of that height a bar covers (iOS tabs run under the tab bar); content should keep clear of it.

func (*Resized) AppendWire

func (m *Resized) AppendWire(b []byte) []byte

AppendWire appends m's wire encoding to b.

func (*Resized) ReadWire

func (m *Resized) ReadWire(r *wire.Reader)

ReadWire decodes m from r. Check r.Err() afterwards.

type Screen

type Screen struct {
	Tag   uint32
	Title string
}

Screen sets a stack screen's title. Tag is the screen's root view, a child of a KindStack view.

func (*Screen) AppendWire

func (m *Screen) AppendWire(b []byte) []byte

AppendWire appends m's wire encoding to b.

func (*Screen) ReadWire

func (m *Screen) ReadWire(r *wire.Reader)

ReadWire decodes m from r. Check r.Err() afterwards.

type Scroll

type Scroll struct {
	Tag        uint32
	W, H       float32
	Horizontal bool
	Report     bool
	// Refreshable shows pull to refresh; pulling sends Refresh. Refreshing
	// keeps the indicator showing until Go clears it.
	Refreshable bool
	Refreshing  bool
}

Scroll sets a scroll view's content size. With Report, the host sends Scrolled whenever the view scrolls (lists need it to know what to show).

func (*Scroll) AppendWire

func (m *Scroll) AppendWire(b []byte) []byte

AppendWire appends m's wire encoding to b.

func (*Scroll) ReadWire

func (m *Scroll) ReadWire(r *wire.Reader)

ReadWire decodes m from r. Check r.Err() afterwards.

type Scrolled

type Scrolled struct {
	Tag  uint32
	X, Y float32
	W, H float32
}

Scrolled reports a scroll view's offset and visible size (only for views whose Scroll op asked for it).

func (*Scrolled) AppendWire

func (m *Scrolled) AppendWire(b []byte) []byte

AppendWire appends m's wire encoding to b.

func (*Scrolled) ReadWire

func (m *Scrolled) ReadWire(r *wire.Reader)

ReadWire decodes m from r. Check r.Err() afterwards.

type Selected

type Selected struct {
	Tag   uint32
	Index uint32
}

Selected reports that the user picked the tab at Index.

func (*Selected) AppendWire

func (m *Selected) AppendWire(b []byte) []byte

AppendWire appends m's wire encoding to b.

func (*Selected) ReadWire

func (m *Selected) ReadWire(r *wire.Reader)

ReadWire decodes m from r. Check r.Err() afterwards.

type Spinner

type Spinner struct {
	Tag   uint32
	Color uint32
}

func (*Spinner) AppendWire

func (m *Spinner) AppendWire(b []byte) []byte

AppendWire appends m's wire encoding to b.

func (*Spinner) ReadWire

func (m *Spinner) ReadWire(r *wire.Reader)

ReadWire decodes m from r. Check r.Err() afterwards.

type Switch

type Switch struct {
	Tag     uint32
	On      bool
	Enabled bool
	Tint    uint32 // the on color; 0 is the platform's
}

Switch sets a toggle's state.

func (*Switch) AppendWire

func (m *Switch) AppendWire(b []byte) []byte

AppendWire appends m's wire encoding to b.

func (*Switch) ReadWire

func (m *Switch) ReadWire(r *wire.Reader)

ReadWire decodes m from r. Check r.Err() afterwards.

type TabItem

type TabItem struct {
	Tag   uint32
	Title string
	Icon  string
}

TabItem sets a tab's title and icon (an SF Symbol name on iOS). Tag is the tab's root view, a child of a KindTabs view.

func (*TabItem) AppendWire

func (m *TabItem) AppendWire(b []byte) []byte

AppendWire appends m's wire encoding to b.

func (*TabItem) ReadWire

func (m *TabItem) ReadWire(r *wire.Reader)

ReadWire decodes m from r. Check r.Err() afterwards.

type TabSelect

type TabSelect struct {
	Tag   uint32
	Index uint32
}

TabSelect shows the tab at Index.

func (*TabSelect) AppendWire

func (m *TabSelect) AppendWire(b []byte) []byte

AppendWire appends m's wire encoding to b.

func (*TabSelect) ReadWire

func (m *TabSelect) ReadWire(r *wire.Reader)

ReadWire decodes m from r. Check r.Err() afterwards.

type Text

type Text struct {
	Tag   uint32
	Text  string
	Font  Font
	Color uint32
	Align Align
	Lines uint32 // 0 = unlimited; truncated with an ellipsis
}

Text sets a text view's content and style.

func (*Text) AppendWire

func (m *Text) AppendWire(b []byte) []byte

AppendWire appends m's wire encoding to b.

func (*Text) ReadWire

func (m *Text) ReadWire(r *wire.Reader)

ReadWire decodes m from r. Check r.Err() afterwards.

type TextSize

type TextSize struct{ W, H float32 }

TextSize answers MeasureText.

func (*TextSize) AppendWire

func (m *TextSize) AppendWire(b []byte) []byte

AppendWire appends m's wire encoding to b.

func (*TextSize) ReadWire

func (m *TextSize) ReadWire(r *wire.Reader)

ReadWire decodes m from r. Check r.Err() afterwards.

type Toggled

type Toggled struct {
	Tag uint32
	On  bool
}

Toggled reports that the user flipped a switch.

func (*Toggled) AppendWire

func (m *Toggled) AppendWire(b []byte) []byte

AppendWire appends m's wire encoding to b.

func (*Toggled) ReadWire

func (m *Toggled) ReadWire(r *wire.Reader)

ReadWire decodes m from r. Check r.Err() afterwards.

type Viewport

type Viewport struct {
	W, H                float32
	Scale               float32 // pixels per point / dp
	SafeTop, SafeBottom float32
	SafeLeft, SafeRight float32
	Platform            string // "ios" | "android"
	Dark                bool
	// Keyboard is how far the on-screen keyboard covers the root view from
	// its bottom edge; 0 when hidden or when the window already shrank.
	Keyboard float32
}

Viewport is the space the root fills; hosts send it at start and whenever it changes.

func (*Viewport) AppendWire

func (m *Viewport) AppendWire(b []byte) []byte

AppendWire appends m's wire encoding to b.

func (*Viewport) ReadWire

func (m *Viewport) ReadWire(r *wire.Reader)

ReadWire decodes m from r. Check r.Err() afterwards.

Jump to

Keyboard shortcuts

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