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
- func AppendMessage(b []byte, v Message) []byte
- func AppendOp(b []byte, v Op) []byte
- func Encode(m Message) []byte
- type Align
- type Box
- type Changed
- type Children
- type Chrome
- type Commit
- type Create
- type Destroy
- type Dismissed
- type Fit
- type Font
- type Frame
- type Image
- type Input
- type Keyboard
- type Kind
- type MeasureText
- type Message
- type Op
- type PluginAck
- type PluginCall
- type PluginResult
- type Popped
- type Present
- type Press
- type Reattach
- type Refresh
- type Resized
- type Screen
- type Scroll
- type Scrolled
- type Selected
- type Spinner
- type Switch
- type TabItem
- type TabSelect
- type Text
- type TextSize
- type Toggled
- type Viewport
Constants ¶
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 ¶
AppendMessage appends a Message: its variant index (0 for nil), then the variant.
Types ¶
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 ¶
AppendWire appends m's wire encoding to b.
type Changed ¶
Changed reports an input's new text.
func (*Changed) AppendWire ¶
AppendWire appends m's wire encoding to b.
type Children ¶
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 ¶
AppendWire appends m's wire encoding to b.
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 ¶
AppendWire appends m's wire encoding to b.
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 ¶
AppendWire appends m's wire encoding to b.
type Create ¶
Create makes a view for Tag. It is not shown until a Children op places it.
func (*Create) AppendWire ¶
AppendWire appends m's wire encoding to b.
type Destroy ¶
type Destroy struct{ Tags []uint32 }
Destroy forgets views (and removes them from their parents).
func (*Destroy) AppendWire ¶
AppendWire appends m's wire encoding to b.
type Dismissed ¶
type Dismissed struct{ Tag uint32 }
Dismissed reports that the user closed a modal (swipe down, back button).
func (*Dismissed) AppendWire ¶
AppendWire appends m's wire encoding to b.
type Font ¶
Font is shared by text, inputs and measurement.
func (*Font) AppendWire ¶
AppendWire appends m's wire encoding to b.
type Frame ¶
Frame places a view relative to its parent (scroll views: their content).
func (*Frame) AppendWire ¶
AppendWire appends m's wire encoding to b.
type Image ¶
func (*Image) AppendWire ¶
AppendWire appends m's wire encoding to b.
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 ¶
AppendWire appends m's wire encoding to b.
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 ¶
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 ReadMessage ¶
ReadMessage decodes a Message (nil for index 0).
type Op ¶
type Op interface {
// contains filtered or unexported methods
}
Op changes one native view.
type PluginAck ¶
type PluginAck struct{ Err string }
PluginAck answers PluginCall: Err is empty when the call started.
func (*PluginAck) AppendWire ¶
AppendWire appends m's wire encoding to b.
type PluginCall ¶
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 ¶
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 ¶
Popped reports that the user went back in a stack (back button, swipe or system back), leaving Depth screens.
func (*Popped) AppendWire ¶
AppendWire appends m's wire encoding to b.
type Present ¶
type Present struct{ Tag uint32 }
Present shows a KindModal view over the app, with the platform's transition.
func (*Present) AppendWire ¶
AppendWire appends m's wire encoding to b.
type Press ¶
type Press struct{ Tag uint32 }
Press reports a tap on a pressable.
func (*Press) AppendWire ¶
AppendWire appends m's wire encoding to b.
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 ¶
AppendWire appends m's wire encoding to b.
type Refresh ¶
type Refresh struct{ Tag uint32 }
Refresh reports that the user pulled a refreshable scroll view.
func (*Refresh) AppendWire ¶
AppendWire appends m's wire encoding to b.
type Resized ¶
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 ¶
AppendWire appends m's wire encoding to b.
type Screen ¶
Screen sets a stack screen's title. Tag is the screen's root view, a child of a KindStack view.
func (*Screen) AppendWire ¶
AppendWire appends m's wire encoding to b.
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 ¶
AppendWire appends m's wire encoding to b.
type Scrolled ¶
Scrolled reports a scroll view's offset and visible size (only for views whose Scroll op asked for it).
func (*Scrolled) AppendWire ¶
AppendWire appends m's wire encoding to b.
type Selected ¶
Selected reports that the user picked the tab at Index.
func (*Selected) AppendWire ¶
AppendWire appends m's wire encoding to b.
type Spinner ¶
func (*Spinner) AppendWire ¶
AppendWire appends m's wire encoding to b.
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 ¶
AppendWire appends m's wire encoding to b.
type TabItem ¶
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 ¶
AppendWire appends m's wire encoding to b.
type TabSelect ¶
TabSelect shows the tab at Index.
func (*TabSelect) AppendWire ¶
AppendWire appends m's wire encoding to b.
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 ¶
AppendWire appends m's wire encoding to b.
type TextSize ¶
type TextSize struct{ W, H float32 }
TextSize answers MeasureText.
func (*TextSize) AppendWire ¶
AppendWire appends m's wire encoding to b.
type Toggled ¶
Toggled reports that the user flipped a switch.
func (*Toggled) AppendWire ¶
AppendWire appends m's wire encoding to b.
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 ¶
AppendWire appends m's wire encoding to b.