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 BackgroundRun
- type Blur
- type Box
- type Changed
- type Children
- type Chrome
- type Commit
- type Create
- type Destroy
- type Dismissed
- type Draw
- type Fit
- type Font
- type Frame
- type Image
- type Input
- type Keyboard
- type Kind
- type LongPressed
- type MeasureText
- type Message
- type Native
- type NativeEvent
- type Op
- type Open
- type Panned
- type Pinched
- 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 Slid
- type Slider
- type Span
- type Spinner
- type Submitted
- type Switch
- type TabItem
- type TabSelect
- type Text
- type TextSize
- type Toggled
- type Viewport
Constants ¶
const ( PanAny uint8 = iota + 1 PanX PanY )
Which drags a view reports (Box.Pan).
const ( GestureBegan uint8 = iota GestureChanged GestureEnded GestureCancelled )
The phases of a gesture (Panned, Pinched).
const ( CornerTopLeft = 1 CornerTopRight = 2 CornerBottomRight = 4 CornerBottomLeft = 8 )
The corners in Box.Corners.
const ( DrawMoveTo uint8 = iota DrawLineTo DrawQuadTo DrawCubicTo DrawClose DrawCircle DrawRect DrawFill DrawStroke DrawFillGradient DrawArc DrawOval DrawEvenOdd DrawStrokeGradient DrawClip DrawSave DrawRestore DrawLayer DrawTranslate DrawRotate DrawScale DrawBlend DrawShadow DrawDash DrawLineStyle DrawTrim DrawImage DrawText DrawBind DrawTag DrawFillShader )
The commands in Draw.Cmds.
const AnimSize = 12
AnimSize is how many numbers each animation takes in Draw.Anims.
const SchemaHash uint64 = 0xc217f49188f442a9
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 BackgroundRun ¶ added in v0.0.13
type BackgroundRun struct{ Name string }
BackgroundRun asks Go to run a background task (plugins/backgroundtasks).
func (*BackgroundRun) AppendWire ¶ added in v0.0.13
func (m *BackgroundRun) AppendWire(b []byte) []byte
AppendWire appends m's wire encoding to b.
func (*BackgroundRun) ReadWire ¶ added in v0.0.13
func (m *BackgroundRun) ReadWire(r *wire.Reader)
ReadWire decodes m from r. Check r.Err() afterwards.
type Blur ¶ added in v0.0.13
type Blur uint8
Blur is how strongly what is behind a view is blurred: the platform's materials on iOS, a blur radius elsewhere.
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)
// Transition animates changes to this view's frame, opacity and
// background over this many milliseconds; 0 changes them at once.
Transition uint32
LongPress bool // a pressable that reports long presses
// Blur shows what is behind the view, blurred; Background tints it.
Blur Blur
// A gradient painted over Background: colors at stops (0..1; evenly
// spaced when there are none), from (GradientX0, GradientY0) to
// (GradientX1, GradientY1) in the view's unit square. A radial one
// spreads from the first point out to the distance to the second.
GradientColors []uint32
GradientStops []float32
GradientRadial bool
GradientX0, GradientY0, GradientX1, GradientY1 float32
// A shadow under the view: its color (0 for none), blur radius and offset.
ShadowColor uint32
ShadowRadius, ShadowX, ShadowY float32
// Corners are the corners Radius rounds: a mask of Corner*; 0 is all four.
Corners uint8
// Hidden takes the view off the screen (Style.Hidden): not drawn, not tapped.
Hidden bool
// Scale (1 when 0) and Rotate (degrees) transform the view about its
// centre, after layout: its place among its siblings doesn't change.
Scale, Rotate float32
// Pan is the drags the view reports (PanAny, PanX, PanY; 0 for none):
// a one-way drag leaves the other way to whatever scrolls around it.
Pan uint8
// Pinch makes the view report two-finger pinches.
Pinch bool
// Back makes a pressable take the system's back button: the host presses
// the newest one before anything else goes back.
Back bool
}
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 Draw ¶ added in v0.0.13
type Draw struct {
Tag uint32
W, H float32
Cmds []uint8
Nums []float32
Colors []uint32
Strs []string
Anims []float32
Touch bool
}
Draw sets what a canvas draws: commands in a W×H space fitted to the view (centred, keeping its aspect, like an SVG viewBox). Each command takes its numbers from Nums, its colors from Colors and its strings from Strs, in order:
DrawMoveTo x y · DrawLineTo x y · DrawQuadTo cx cy x y
DrawCubicTo c1x c1y c2x c2y x y · DrawClose
DrawCircle cx cy r · DrawRect x y w h radius (add to the path)
DrawArc cx cy r start sweep · DrawOval x y w h (add to the path: a new subpath;
degrees, clockwise from 3 o'clock)
DrawEvenOdd (the path fills by the even-odd rule)
DrawFill color · DrawStroke width color (paint the path, then start a new one)
DrawFillGradient kind x0 y0 x1 y1 n stop×n colors×n
(kind 0: from (x0, y0) to (x1, y1);
1: from (x0, y0) out to the distance to (x1, y1);
2: around (x0, y0), starting toward (x1, y1))
DrawStrokeGradient width kind x0 y0 x1 y1 n stop×n colors×n
DrawClip (later drawing stays inside the path; a new path)
DrawSave · DrawRestore (the state below, and the clip)
DrawLayer opacity (a Save whose drawing is blended in at Restore)
DrawTranslate x y · DrawRotate degrees · DrawScale sx sy
DrawBlend mode · DrawShadow dx dy blur color (blur: a CSS blur radius; color 0 for none)
DrawDash n len×n (strokes dashed; n 0 for solid)
DrawLineStyle cap join (cap 0 round, 1 butt, 2 square;
join 0 round, 1 miter, 2 bevel)
DrawTrim length start end (the next stroke shows start..end of
its length, as fractions)
DrawImage url x y w h fit (url a string; Fit)
DrawText text family x y width size weight align lines color
(text and family strings; (x, y) its top left,
wrapped at width when over 0; color 0 the default)
DrawBind arg anim from to (the next command's arg-th number is
from + (to - from) × anim's value)
DrawTag n (the next Fill, Stroke or gradient paints
shape n, from 1, for taps and drag handles)
DrawFillShader x y w h n u×n fallback source (fill with a shader, run over the box
(x, y, w, h) that holds the path; its
uniforms; a color where it can't run; the
platform's source, its main taking a point
in the canvas's units)
Anims holds the animations DrawBind uses, AnimSize numbers each: id, run, kind (0: a clock from 0 to 1; 1: follows to, from where it is; 2: a drag, which also follows to), ms, delay, ease, bounce, repeat (-1 forever; a drag's axis, 0 across, 1 down), reverse (0 or 1; a drag's handle, the shape it starts on, 0 for anywhere), to, min, max (a drag's range). The host runs them itself, from when it first sees each id or run, and sends a NativeEvent named "anim" with "id:run" when one ends.
With Touch, the canvas takes touches: a tap sends a NativeEvent named "tap" with "shape,x,y" (the topmost tagged shape under it, 0 for none, and where, in the canvas's units), and a drag moves its number with the finger, in the canvas's units, sending "drag" with "id:value" when it's let go.
func (*Draw) AppendWire ¶ added in v0.0.13
AppendWire appends m's wire encoding to b.
type Font ¶
type Font struct {
Size float32
Weight uint16 // 100..900; 0 means 400
Family string // a font the app bundles (nimbus native font add); "" is the system font
// Tracking is extra space between letters, in points (negative tightens).
Tracking float32
// LineHeight is the distance between lines, in points; 0 is the font's own.
LineHeight float32
// Tabular gives every digit the same width, so figures line up and
// don't jiggle as they change.
Tabular bool
}
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
// Submit makes Return send (Submitted) instead of a new line; the key
// says Send.
Submit bool
// AutoFocus focuses the input when it appears, keyboard up.
AutoFocus bool
}
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 // KindSlider picks a number in a range: UISlider, Android's SeekBar. KindSlider // KindCanvas draws shapes Go describes (Draw). KindCanvas // KindNative holds a view the host makes itself, such as a map (Native). KindNative )
type LongPressed ¶ added in v0.0.9
type LongPressed struct{ Tag uint32 }
LongPressed reports a long press on a pressable that asked for them.
func (*LongPressed) AppendWire ¶ added in v0.0.9
func (m *LongPressed) AppendWire(b []byte) []byte
AppendWire appends m's wire encoding to b.
func (*LongPressed) ReadWire ¶ added in v0.0.9
func (m *LongPressed) ReadWire(r *wire.Reader)
ReadWire decodes m from r. Check r.Err() afterwards.
type MeasureText ¶
type MeasureText struct {
Text string
Font Font
MaxWidth float32 // < 0: no limit
Lines uint32
Spans []Span // a rich text's runs (Text is them joined)
}
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 Native ¶ added in v0.0.13
Native sets a KindNative view's kind, once, and its props, as JSON.
func (*Native) AppendWire ¶ added in v0.0.13
AppendWire appends m's wire encoding to b.
type NativeEvent ¶ added in v0.0.13
NativeEvent is what a native view has to say (ui.Native): a name, and JSON.
func (*NativeEvent) AppendWire ¶ added in v0.0.13
func (m *NativeEvent) AppendWire(b []byte) []byte
AppendWire appends m's wire encoding to b.
func (*NativeEvent) ReadWire ¶ added in v0.0.13
func (m *NativeEvent) ReadWire(r *wire.Reader)
ReadWire decodes m from r. Check r.Err() afterwards.
type Op ¶
type Op interface {
// contains filtered or unexported methods
}
Op changes one native view.
type Open ¶ added in v0.0.9
type Open struct{ URL string }
Open reports a link that opened the app (myapp://orders/42, or a web link the app handles), at launch or while it runs.
func (*Open) AppendWire ¶ added in v0.0.9
AppendWire appends m's wire encoding to b.
type Panned ¶ added in v0.0.13
Panned reports a drag on a view that asked for them: how far it has come from where it began (X, Y) and how fast it's going (VX, VY, per second), in points. A view that moves with the finger doesn't change these.
func (*Panned) AppendWire ¶ added in v0.0.13
AppendWire appends m's wire encoding to b.
type Pinched ¶ added in v0.0.13
Pinched reports a two-finger pinch: Scale is the fingers' distance over what it was at the start.
func (*Pinched) AppendWire ¶ added in v0.0.13
AppendWire appends m's wire encoding to b.
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
// StickToEnd keeps the end in view as the content grows (a chat): when
// it gets longer, the view scrolls to show its end.
StickToEnd 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 Slid ¶ added in v0.0.9
Slid reports the value the user dragged a slider to.
func (*Slid) AppendWire ¶ added in v0.0.9
AppendWire appends m's wire encoding to b.
type Slider ¶ added in v0.0.9
Slider sets a slider.
func (*Slider) AppendWire ¶ added in v0.0.9
AppendWire appends m's wire encoding to b.
type Span ¶ added in v0.0.13
Span is a run of a text with its own font and color.
func (*Span) AppendWire ¶ added in v0.0.13
AppendWire appends m's wire encoding to b.
type Spinner ¶
func (*Spinner) AppendWire ¶
AppendWire appends m's wire encoding to b.
type Submitted ¶ added in v0.0.13
type Submitted struct {
Tag uint32
}
Submitted reports Return on an input that submits (Input.Submit).
func (*Submitted) AppendWire ¶ added in v0.0.13
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
// MinScale lets a one-line text shrink to fit its width, down to this
// share of its size (0.6: 60%); 0 truncates instead.
MinScale float32
// Spans, when there are any, are the text in runs of their own look
// (Text is then all of them, joined).
Spans []Span
// Style.Padding: the text is drawn this far inside its frame.
PadLeft, PadTop, PadRight, PadBottom float32
}
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.