mobile 实验性
实验性
本包属于实验层:任何 0.x 版本都可能有不兼容变化(docs/release.md「API 稳定性」)。
import "github.com/tangoui/tango/ui/mobile"本页由
site/tools/apigen从源码注释生成(按 darwin 构建标签选文件),请勿手改。
Package mobile provides touch-first widgets for the Tango self-drawn UI in the visual language of Ant Design Mobile (default), Vant and a mobile derivation of shadcn/ui (Shadcn: chosen automatically under a theme.Shadcn ui theme; Drawer-style bottom sheets with a grab handle, grouped action sheet cards, Sonner toasts, segmented tabs): NavBar, TabBar, List/Cell, SwipeCell, PullToRefresh, InfiniteList, ActionSheet, Popup, Dialog, Toast, Picker (cascade, date/time), Stepper, SearchBar, Tabs, Swiper, Grid, NoticeBar, Skeleton, Empty, Result, Badge, Tag, Button, Form, IndexBar, FloatingBubble and SafeArea.
Gestures (tap, long press, swipe with direction and speed, drag, inertial scrolling, rubber-band edges) are recognized from the ui layer's pointer events by a gesture arena (see Area and Touchable); pinch comes from the ui layer's multi-touch events (input.TouchEvent). Drags that start on plain ui widgets inside a scroll view or swipe cell are handed to the container by the ui layer's pointer takeover. The scroll physics (Scroller) and recognizers (Track, PinchRecognizer, RefreshMachine) are pure types usable on their own. Long lists of fixed-height rows build only the visible rows with ScrollViewW.Rows.
Under a high-contrast ui theme (theme.HighContrast) the mobile neutrals are lifted to WCAG AA like the ui theme's (NewTheme).
Components read ConfigProvider defaults under "mobile.<Component>" names (ui.ConfigProvider(c).Defaults("mobile.Button", ui.Props{"size": "large"})); explicit modifiers win. Each constructor documents its keys.
On iOS and Android the widgets run in a self-drawn canvas page that uihost.Open shows natively (touch, safe area, keyboard, input methods and accessibility come from the platform; see docs/specs/mobile-canvas.md and examples/mobile-ui). On the desktop they run in any uihost window.
Wrap a mobile page in Provider to pick the design style and safe area:
mobile.Provider(c, mobile.Options{Style: mobile.Vant}, func() {
mobile.NavBar(c, "标题").Back("")
mobile.ScrollView(c).Layout(layout.Grow(1)).Body(func() { ... })
mobile.TabBar(c, tabs, &active)
})
Experimental: this package's API may change in any 0.x release (see docs/release.md, "API 稳定性").
常量
const (
// DecelerationRate is the fraction of velocity kept per millisecond of
// a fling (iOS "normal" deceleration).
DecelerationRate = 0.998
// RubberBand is the resistance of dragging past an edge: the content
// follows by dim·(1 − 1/(d·RubberBand/dim + 1)).
RubberBand = 0.55
// SpringOmega is the angular frequency (1/s) of the critically damped
// spring that pulls an over-scrolled view back to its edge.
SpringOmega = 13.0
)Physics constants of the scroll model.
const (
TouchSlop = 8 // px a finger may wander before a tap becomes a drag
LongPressDelay = 500 * time.Millisecond // hold time of a long press
SwipeMinVelocity = 250 // px/s for a release to count as a swipe (flick)
SwipeMinDistance = 30 // px of travel that counts as a swipe at any speed
)Gesture thresholds.
函数
func Badge
func Badge(c *ui.Context, content string, fn func()) *ui.BoxBadge wraps content with a badge at its top-end corner (top right; top left in RTL): content is the text ("99+"), "dot" for a dot, or "" for none.
func ClearToast
func ClearToast(c *ui.Context)ClearToast hides the imperative toast.
func Decay
func Decay(p0, v0, t float64) (p, v float64)Decay returns the position and velocity t seconds into a fling that started at p0 with velocity v0 (px/s).
func DecayTarget
func DecayTarget(p0, v0 float64) float64DecayTarget is where a fling from p0 with velocity v0 comes to rest.
func DrawBadge
func DrawBadge(l *paint.List, th *Theme, s string, cx, cy float32)DrawBadge paints a badge centred at (cx, cy): s is the count text, "" or "dot" for a dot. Use it in custom painters (avatars, icons).
func Provider
func Provider(c *ui.Context, o Options, fn func())Provider runs fn with the mobile options o (design style, safe area) and then renders imperative toasts queued with ShowToast. Wrap a mobile page in one Provider; without it components use the Ant Design Mobile style.
func Rubber
func Rubber(d, dim float64) float64Rubber maps an overshoot d (px past the edge, ≥ 0) to the displayed overshoot for a viewport of size dim.
func RubberInverse
func RubberInverse(v, dim float64) float64RubberInverse is the inverse of Rubber: the finger overshoot that displays as v.
func SafeArea
func SafeArea(c *ui.Context, edge Edge) *ui.BoxSafeArea adds a blank of the safe-area inset of edge (Top: status bar / notch, Bottom: home indicator), filled with the box color.
func SafeAreaInsets
func SafeAreaInsets(c *ui.Context) geom.InsetsSafeAreaInsets returns the insets in effect: the innermost Provider override, else the window's (ui.Context.SafeArea).
func ShowToast
func ShowToast(c *ui.Context, msg string, o ...ToastOptions)ShowToast shows msg as a toast from event-handling code (replacing the current one). It is drawn by the enclosing Provider.
func Spring
func Spring(x0, v0, omega, t float64) (x, v float64)Spring returns the displacement and velocity t seconds after a critically damped spring was released at displacement x0 with velocity v0 (target is 0).
func Within
func Within(c *ui.Context, id ui.ID, fn func())Within builds fn as the content of area id: touchables and areas created inside attach to it.
类型
Action
type Action struct {
Key string
Text string
Description string
Danger bool
Bold bool
Disabled bool
}Action is one entry of an ActionSheet.
ActionSheetW
type ActionSheetW struct {
// contains filtered or unexported fields
}ActionSheetW is a bottom menu of actions.
func ActionSheet
func ActionSheet(c *ui.Context, open *bool, actions []Action) *ActionSheetWActionSheet opens a bottom action menu bound to *open. It renders when Show is called (after options) and closes after a selection. In the shadcn style the actions sit in an outlined rounded card floating above the bottom edge, the cancel button in a second card below.
ConfigProvider defaults ("mobile.ActionSheet"): "cancelText" (string, shows the cancel button), "closeOnMaskClick" (bool).
func (*ActionSheetW) Cancel
func (w *ActionSheetW) Cancel(s string) *ActionSheetWCancel adds a separated cancel button ("" uses the localized "取消").
func (*ActionSheetW) Cancelled
func (w *ActionSheetW) Cancelled() boolCancelled reports a tap on the cancel button or the mask this frame.
func (*ActionSheetW) Extra
func (w *ActionSheetW) Extra(s string) *ActionSheetWExtra shows a caption above the actions.
func (*ActionSheetW) Selected
func (w *ActionSheetW) Selected() (int, bool)Selected returns the index of the action tapped this frame.
func (*ActionSheetW) Show
func (w *ActionSheetW) Show() *ActionSheetWShow renders the sheet.
Axis
type Axis uint8Axis is the set of drag directions an area accepts.
const (
AxisNone Axis = 0
AxisHorizontal Axis = 1 << 0
AxisVertical Axis = 1 << 1
AxisBoth = AxisHorizontal | AxisVertical
)ButtonW
type ButtonW struct {
// contains filtered or unexported fields
}ButtonW is a touch button sized for fingers.
func Button
func Button(c *ui.Context, label string) *ButtonWButton adds a button labelled label. In the shadcn style the default color is the outline variant, "primary" the near-black default variant and "danger" the destructive one, with medium-weight labels and h-11 (Middle) touch heights.
ConfigProvider defaults ("mobile.Button"): "size" ("mini", "small", "middle", "large", a mobile.Size or a ui.ControlSize; otherwise the ConfigProvider size), "shape" ("round" or "default"), "fill" ("solid", "outline", "none"), "color" (string), "block" (bool).
func (*ButtonW) A11yLabel
func (w *ButtonW) A11yLabel(s string) *ButtonWA11yLabel sets the accessible name (icon-only buttons).
func (*ButtonW) Block
func (w *ButtonW) Block() *ButtonWBlock stretches the button to the full width.
func (*ButtonW) Clicked
func (w *ButtonW) Clicked() boolClicked reports a tap this frame.
func (*ButtonW) Color
func (w *ButtonW) Color(s string) *ButtonWColor sets the color: "default", "primary", "success", "warning", "danger".
func (*ButtonW) Danger
func (w *ButtonW) Danger() *ButtonWDanger is Color("danger").
func (*ButtonW) Disabled
func (w *ButtonW) Disabled(on bool) *ButtonWDisabled greys the button out.
func (*ButtonW) Fill
func (w *ButtonW) Fill(s string) *ButtonWFill sets "solid" (default), "outline" or "none".
func (*ButtonW) ID
func (w *ButtonW) ID() ui.IDID returns the button's ID.
func (*ButtonW) Icon
func (w *ButtonW) Icon(ic *icon.Icon) *ButtonWIcon adds a leading icon.
func (*ButtonW) Layout
func (w *ButtonW) Layout(opts ...layout.Option) *ButtonWLayout applies layout options.
func (*ButtonW) Loading
func (w *ButtonW) Loading(on bool) *ButtonWLoading shows a spinner and ignores taps.
func (*ButtonW) Primary
func (w *ButtonW) Primary() *ButtonWPrimary is Color("primary").
func (*ButtonW) Round
func (w *ButtonW) Round() *ButtonWRound makes the ends fully rounded.
func (*ButtonW) Size
func (w *ButtonW) Size(s Size) *ButtonWSize sets the size.
CellW
type CellW struct {
// contains filtered or unexported fields
}CellW is a list row: optional icon, title with description, value at the end, arrow, or switch (the end is the right; the left in RTL, where the arrow points left).
func Cell
func Cell(c *ui.Context, title string) *CellWCell adds a list row titled title.
ConfigProvider defaults ("mobile.Cell"): "arrow", "clickable" (bool).
func (*CellW) Arrow
func (w *CellW) Arrow() *CellWArrow shows the navigation arrow and pressed feedback.
func (*CellW) Changed
func (w *CellW) Changed() boolChanged reports a switch toggle this frame.
func (*CellW) Clickable
func (w *CellW) Clickable() *CellWClickable shows pressed feedback without an arrow.
func (*CellW) Clicked
func (w *CellW) Clicked() boolClicked reports a tap on the row (not on its switch).
func (*CellW) Desc
func (w *CellW) Desc(s string) *CellWDesc shows a description line under the title.
func (*CellW) Disabled
func (w *CellW) Disabled(on bool) *CellWDisabled greys the row out and ignores taps.
func (*CellW) Extra
func (w *CellW) Extra(s string) *CellWExtra shows a value at the end.
func (*CellW) ID
func (w *CellW) ID() ui.IDID returns the row's ID.
func (*CellW) Icon
func (w *CellW) Icon(ic *icon.Icon) *CellWIcon shows an icon before the title.
func (*CellW) LongPressed
func (w *CellW) LongPressed() boolLongPressed reports a long press on the row.
func (*CellW) Required
func (w *CellW) Required() *CellWRequired marks the title with a red asterisk (forms).
func (*CellW) Switch
func (w *CellW) Switch(on *bool) *CellWSwitch shows a switch bound to *on; tapping it toggles.
DatePrecision
type DatePrecision uint8DatePrecision is the finest column of a date picker.
const (
PrecisionYear DatePrecision = iota
PrecisionMonth
PrecisionDay
PrecisionHour
PrecisionMinute
)DialogW
type DialogW struct {
// contains filtered or unexported fields
}DialogW is a centred modal with a title, message and buttons.
func Dialog
func Dialog(c *ui.Context, open *bool, title string) *DialogWDialog creates a modal dialog bound to *open. By default it is an alert with one acknowledge button; Confirm adds a cancel button. Call Show (or a query) after the options.
In the shadcn style the dialog follows AlertDialog on small screens: an outlined card with a centred title, a muted message and full-width stacked buttons (solid confirm above an outline cancel).
ConfigProvider defaults ("mobile.Dialog"): "closeOnMaskClick" (bool), "confirmText" (string, the acknowledge / OK text), "cancelText" (string, used by Confirm when it gets "").
func (*DialogW) Cancelled
func (w *DialogW) Cancelled() boolCancelled reports a cancel this frame (button or mask).
func (*DialogW) CloseOnMask
func (w *DialogW) CloseOnMask() *DialogWCloseOnMask lets a mask tap dismiss the dialog (cancel).
func (*DialogW) Confirm
func (w *DialogW) Confirm(ok, cancel string) *DialogWConfirm turns the dialog into a confirm box with OK / Cancel buttons ("" keeps the localized texts).
func (*DialogW) Confirmed
func (w *DialogW) Confirmed() boolConfirmed reports a tap on the OK / acknowledge button this frame.
func (*DialogW) Content
func (w *DialogW) Content(s string) *DialogWContent sets the message.
func (*DialogW) Custom
func (w *DialogW) Custom(fn func()) *DialogWCustom builds custom content under the message.
func (*DialogW) OKText
func (w *DialogW) OKText(s string) *DialogWOKText sets the acknowledge button text of an alert.
func (*DialogW) PanelID
func (w *DialogW) PanelID() ui.IDPanelID returns the ID of the dialog panel (0 while closed).
func (*DialogW) Show
func (w *DialogW) Show() *DialogWShow renders the dialog.
Direction
type Direction uint8Direction is the dominant direction of a movement.
const (
DirNone Direction = iota
DirLeft
DirRight
DirUp
DirDown
)func DirectionOf
func DirectionOf(v geom.Point) DirectionDirectionOf returns the dominant direction of v.
func (Direction) Horizontal
func (d Direction) Horizontal() boolHorizontal reports whether d is left or right.
func (Direction) String
func (d Direction) String() stringEdge
type Edge uint8Edge selects a side of the screen.
const (
Top Edge = iota
Bottom
Left
Right
)EmptyW
type EmptyW struct {
// contains filtered or unexported fields
}EmptyW is an empty-state placeholder.
func Empty
func Empty(c *ui.Context) *EmptyWEmpty adds an empty state with the localized "暂无数据" (shadcn: an icon on a muted tile above the muted caption).
ConfigProvider defaults ("mobile.Empty"): "description" (string).
func (*EmptyW) Description
func (w *EmptyW) Description(s string) *EmptyWDescription replaces the caption.
FieldW
type FieldW struct {
// contains filtered or unexported fields
}FieldW is a borderless single-line text input for forms and cells.
func Field
func Field(c *ui.Context, val *string) *FieldWField adds a borderless text input bound to *val. It reuses ui.Input (editing, IME, clipboard) and hides its frame.
ConfigProvider defaults ("mobile.Field"): "clearable" (bool), "maxLength" (int), "placeholder" (string).
func (*FieldW) Changed
func (w *FieldW) Changed() boolChanged reports an edit this frame.
func (*FieldW) EnterKey
func (w *FieldW) EnterKey(k input.EnterKey) *FieldWEnterKey labels the soft keyboard's return key (input.EnterNext, input.EnterDone, …); pressing it still reports Submitted.
func (*FieldW) Input
func (w *FieldW) Input() *ui.InputWInput returns the underlying ui.InputW.
func (*FieldW) MaxLength
func (w *FieldW) MaxLength(n int) *FieldWMaxLength limits the length.
func (*FieldW) Password
func (w *FieldW) Password() *FieldWPassword masks the text.
func (*FieldW) Placeholder
func (w *FieldW) Placeholder(s string) *FieldWPlaceholder sets the hint text.
func (*FieldW) Submitted
func (w *FieldW) Submitted() boolSubmitted reports Enter.
func (*FieldW) Type
func (w *FieldW) Type(k input.TextKind) *FieldWType tells the soft keyboard what the field holds (input.TextNumber, input.TextEmail, input.TextPhone, …): its layout and suggestions. input.TextPassword also masks the text.
FloatingBubbleW
type FloatingBubbleW struct {
// contains filtered or unexported fields
}FloatingBubbleW is a draggable round button that floats over the page and sticks to the nearest side when released.
func FloatingBubble
func FloatingBubble(c *ui.Context, ic *icon.Icon, axis Axis, magnetic bool) *FloatingBubbleWFloatingBubble adds a floating bubble showing ic. axis limits dragging (AxisBoth by default); magnetic snaps it to the left or right edge. It starts in the bottom end corner (bottom right; bottom left in RTL).
ConfigProvider defaults ("mobile.FloatingBubble"): "size" (number, at least the 44pt touch minimum; default 48).
func (*FloatingBubbleW) A11yLabel
func (w *FloatingBubbleW) A11yLabel(s string) *FloatingBubbleWA11yLabel sets the accessible name of the bubble (it shows an icon only).
func (*FloatingBubbleW) Clicked
func (w *FloatingBubbleW) Clicked() boolClicked reports a tap on the bubble.
FormItemW
type FormItemW struct {
// contains filtered or unexported fields
}FormItemW is one labelled field of a Form.
func FormItem
func FormItem(c *ui.Context, label string) *FormItemWFormItem starts a labelled field; build the control in Body.
func (*FormItemW) Arrow
func (w *FormItemW) Arrow() *FormItemWArrow shows a navigation arrow (pickers opened from the row).
func (*FormItemW) Body
func (w *FormItemW) Body(fn func()) *FormItemWBody builds the field control.
func (*FormItemW) Clicked
func (w *FormItemW) Clicked() boolClicked reports a tap on the row (open a picker from an Arrow item).
func (*FormItemW) Error
func (w *FormItemW) Error(msg string) *FormItemWError shows a validation message under the field ("" for none).
func (*FormItemW) Help
func (w *FormItemW) Help(s string) *FormItemWHelp shows a hint under the field.
func (*FormItemW) Required
func (w *FormItemW) Required() *FormItemWRequired marks the label with an asterisk.
FormW
type FormW struct {
// contains filtered or unexported fields
}FormW lays out labelled fields in a white group, labels on the left (default) or on top.
func Form
func Form(c *ui.Context) *FormWForm starts a mobile form; add FormItems in Body.
ConfigProvider defaults ("mobile.Form"): "layout" ("horizontal" or "vertical"), "mode" ("default" or "card").
func (*FormW) Body
func (w *FormW) Body(fn func())Body builds the items.
func (*FormW) Card
func (w *FormW) Card() *FormWCard insets the group with rounded corners.
func (*FormW) Header
func (w *FormW) Header(s string) *FormWHeader shows a group caption.
func (*FormW) Vertical
func (w *FormW) Vertical() *FormWVertical puts labels above their fields.
Gesture
type Gesture struct {
ID ui.ID
Pan Pan
Tap bool // a tap landed inside the area (bubbles from touchables)
TapPos geom.Point
LongPress bool
LongPos geom.Point
TouchStart bool // a finger went down inside the area this frame
Outside bool // a finger went down outside the area this frame
Swipe Swipe
Swiped bool // the drag owned by this area ended as a swipe
Pinch Pinch
}Gesture is the per-frame gesture state of an area.
func Area
func Area(c *ui.Context, b *ui.Box, axis Axis, accept func(Direction) bool) GestureArea makes box b a gesture area accepting drags along axis (accept, if non-nil, can refuse a direction at claim time) and returns its state. Build the area's content with Within so nested touchables and areas attach to it.
GridItem
type GridItem struct {
Text string
Icon *icon.Icon
Badge string // "", "dot" or count text
}GridItem is one cell of a Grid.
GridW
type GridW struct {
// contains filtered or unexported fields
}GridW is a grid of icon + text entries.
func Grid
func Grid(c *ui.Context, cols int, items []GridItem) *GridWGrid adds a grid of items in cols columns. In the shadcn style the icons sit on muted rounded-xl tiles and cells have no separators.
ConfigProvider defaults ("mobile.Grid"): "bordered" (bool).
func (*GridW) Border
func (w *GridW) Border(on bool) *GridWBorder toggles cell separators.
func (*GridW) Clicked
func (w *GridW) Clicked() (int, bool)Clicked returns the index tapped this frame.
IndexBarW
type IndexBarW struct {
// contains filtered or unexported fields
}IndexBarW is a grouped list with an alphabet index at the end (on the right; on the left in RTL): tap or drag along the index to jump to a group. The current group's title sticks to the top.
func IndexBar
func IndexBar(c *ui.Context, indexes []string) *IndexBarWIndexBar creates an index bar for groups titled indexes.
func (*IndexBarW) Body
func (w *IndexBarW) Body(group func(i int)) *IndexBarWBody builds the groups; group(i) builds the rows of group i.
func (*IndexBarW) Layout
func (w *IndexBarW) Layout(opts ...layout.Option) *IndexBarWLayout applies layout options to the container (give it a height).
ListW
type ListW struct {
// contains filtered or unexported fields
}ListW is a group of cells with an optional header.
func List
func List(c *ui.Context, header string) *ListWList starts a cell group titled header ("" for none); add cells in Body.
ConfigProvider defaults ("mobile.List"): "mode" ("default" or "card").
func (*ListW) Body
func (w *ListW) Body(fn func())Body builds the cells.
func (*ListW) Card
func (w *ListW) Card() *ListWCard insets the group with rounded corners (Ant Mobile mode="card", Vant inset).
func (*ListW) Layout
func (w *ListW) Layout(opts ...layout.Option) *ListWLayout applies layout options to the outer box.
NavBarW
type NavBarW struct {
// contains filtered or unexported fields
}NavBarW is the top navigation bar: back arrow and text at the start (left; right in RTL, the arrow mirrored to point right), centred title, text or icon at the end.
func NavBar
func NavBar(c *ui.Context, title string) *NavBarWNavBar adds a navigation bar titled title.
ConfigProvider defaults ("mobile.NavBar"): "bordered" (bool).
func (*NavBarW) Back
func (w *NavBarW) Back(text string) *NavBarWBack shows the back arrow with optional text (Ant Mobile shows the arrow only by default; Vant styles typically pass "返回").
func (*NavBarW) BackClicked
func (w *NavBarW) BackClicked() boolBackClicked reports a tap on the back area.
func (*NavBarW) Border
func (w *NavBarW) Border(on bool) *NavBarWBorder toggles the bottom hairline (Vant and shadcn default on, Ant Mobile off).
func (*NavBarW) ID
func (w *NavBarW) ID() ui.IDID returns the bar's ID.
func (*NavBarW) Right
func (w *NavBarW) Right(text string) *NavBarWRight shows a text action at the end (right; left in RTL).
func (*NavBarW) RightClicked
func (w *NavBarW) RightClicked() boolRightClicked reports a tap on the right action.
func (*NavBarW) RightIcon
func (w *NavBarW) RightIcon(ic *icon.Icon) *NavBarWRightIcon shows an icon action at the end; name it with RightLabel unless Right gives it a text.
func (*NavBarW) RightLabel
func (w *NavBarW) RightLabel(s string) *NavBarWRightLabel sets the accessible name of the right action (needed for an icon-only action).
NoticeBarW
type NoticeBarW struct {
// contains filtered or unexported fields
}NoticeBarW is a one-line announcement bar, optionally scrolling.
func NoticeBar
func NoticeBar(c *ui.Context, msg string) *NoticeBarWNoticeBar adds an announcement bar showing msg (a neutral shadcn Alert strip in the shadcn style).
ConfigProvider defaults ("mobile.NoticeBar"): "color" (string), "closeable", "scroll" (bool).
func (*NoticeBarW) Closeable
func (w *NoticeBarW) Closeable() *NoticeBarWCloseable shows a close button.
func (*NoticeBarW) Closed
func (w *NoticeBarW) Closed() boolClosed reports a tap on the close button this frame.
func (*NoticeBarW) Color
func (w *NoticeBarW) Color(s string) *NoticeBarWColor sets "default" (orange), "alert", "error" or "info".
func (*NoticeBarW) Scroll
func (w *NoticeBarW) Scroll() *NoticeBarWScroll makes long text scroll (marquee; towards the start, so to the right in RTL).
Options
type Options struct {
Style Style
// SafeArea overrides the window's safe-area insets (ui.Context.SafeArea,
// set by the host through ui.SafeAreaWindow or Runner.SetSafeArea).
SafeArea *geom.Insets
}Options configure the mobile components inside a Provider.
Pan
type Pan struct {
Active bool // the area owns a drag in progress
Began bool // ownership started this frame
Ended bool // the finger lifted this frame
Delta geom.Point // travel since the drag was claimed
Velocity geom.Point // px/s (release velocity when Ended)
Dir Direction // direction at claim time
}Pan is the drag state of a gesture area that owns the current drag.
PickerViewW
type PickerViewW struct {
// contains filtered or unexported fields
}PickerViewW is an inline set of scroll wheels.
func CascadePickerView
func CascadePickerView(c *ui.Context, opts []ui.CascaderOption, value *[]string) *PickerViewWCascadePickerView shows linked wheels for a tree of options (province / city / district); value holds the Value path.
func DatePickerView
func DatePickerView(c *ui.Context, value *time.Time, p DatePrecision, bounds ...time.Time) *PickerViewWDatePickerView shows year / month / day (… hour / minute) wheels bound to *value. Optional bounds are the earliest and latest selectable time (default: ten years either side of the value).
func PickerView
func PickerView(c *ui.Context, cols [][]ui.Option, value *[]string) *PickerViewWPickerView shows one wheel per column; value holds the selected option Value of each column. The shadcn style marks the selected row with a muted rounded-md band instead of hairlines.
ConfigProvider defaults ("mobile.PickerView", also read by the views of Picker, CascadePickerView and DatePickerView): "visibleItemCount" (int, at least 3).
func (*PickerViewW) A11yLabel
func (w *PickerViewW) A11yLabel(s string) *PickerViewWA11yLabel names the wheels for screen readers (each wheel is an adjustable slider whose value is the selected option); A11yLabels names them one by one. Date pickers name their columns year, month, day ….
func (*PickerViewW) A11yLabels
func (w *PickerViewW) A11yLabels(names ...string) *PickerViewWA11yLabels sets the accessible name of each wheel.
func (*PickerViewW) Changed
func (w *PickerViewW) Changed() boolChanged reports a wheel settling on a new value this frame.
func (*PickerViewW) ID
func (w *PickerViewW) ID() ui.IDID returns the wheel row's ID.
func (*PickerViewW) Show
func (w *PickerViewW) Show() *PickerViewWShow renders the wheels.
func (*PickerViewW) Visible
func (w *PickerViewW) Visible(n int) *PickerViewWVisible sets how many rows each wheel shows (odd numbers centre best).
PickerW
type PickerW struct {
// contains filtered or unexported fields
}PickerW is a bottom popup with a toolbar (cancel / title / confirm) and wheels; the bound value only changes on confirm.
func Picker
func Picker(c *ui.Context, open *bool, title string) *PickerWPicker creates a popup picker bound to *open; choose the wheels with Columns, Cascade or Date, then call Show. The shadcn style shows it as a Drawer (grab handle, semibold title).
ConfigProvider defaults ("mobile.Picker"): "closeOnMaskClick" (bool); the wheels read "mobile.PickerView".
func (*PickerW) Cancelled
func (w *PickerW) Cancelled() boolCancelled reports a cancel this frame.
func (*PickerW) Cascade
func (w *PickerW) Cascade(opts []ui.CascaderOption, value *[]string) *PickerWCascade shows linked wheels for a tree of options.
func (*PickerW) Columns
func (w *PickerW) Columns(cols [][]ui.Option, value *[]string) *PickerWColumns shows independent wheels; value receives the Values on confirm.
func (*PickerW) Confirmed
func (w *PickerW) Confirmed() boolConfirmed reports a confirm this frame (the bound value was updated).
func (*PickerW) Date
func (w *PickerW) Date(value *time.Time, p DatePrecision, bounds ...time.Time) *PickerWDate shows date / time wheels down to precision p (optional bounds as in DatePickerView).
func (*PickerW) Show
func (w *PickerW) Show() *PickerWShow renders the popup.
Pinch
type Pinch struct {
Scale float32 // current finger distance / start distance
Rotation float64 // radians, positive clockwise
Center geom.Point // midpoint of the fingers
Pan geom.Point // movement of the midpoint since the start
Active bool
}Pinch is the state of a two-finger gesture relative to its start.
PinchRecognizer
type PinchRecognizer struct {
// contains filtered or unexported fields
}PinchRecognizer turns two-finger frames into scale / rotation / pan. Gesture areas feed it from the ui layer's touch events (Gesture.Pinch); custom code can call Update with the fingers of a ui.Box.Touches stream.
func (*PinchRecognizer) Update
func (r *PinchRecognizer) Update(pts []TouchPoint) PinchUpdate consumes the current set of touching fingers and returns the pinch state (Active false with fewer than two fingers).
PopupW
type PopupW struct {
// contains filtered or unexported fields
}PopupW is a sliding panel over a dimmed mask.
func Popup
func Popup(c *ui.Context, open *bool) *PopupWPopup creates a popup bound to *open (bottom sheet by default); set options, then build the content with Body. Tapping the mask or pressing Escape closes it. In the shadcn style a bottom popup is a Drawer: an outlined sheet with rounded top corners and a grab handle that can be dragged down to close it.
ConfigProvider defaults ("mobile.Popup"): "position" ("bottom", "top", "center", "left", "right", "start", "end"), "round", "mask", "closeOnMaskClick", "handle" (bool).
func (*PopupW) A11yLabel
func (w *PopupW) A11yLabel(s string) *PopupWA11yLabel sets the accessible name of the panel (a dialog for screen readers; name it after its content).
func (*PopupW) Bg
func (w *PopupW) Bg(col paintColor) *PopupWBg sets the panel background.
func (*PopupW) Body
func (w *PopupW) Body(fn func()) *PopupWBody builds the panel content (only while open or animating out).
func (*PopupW) CloseOnMask
func (w *PopupW) CloseOnMask(on bool) *PopupWCloseOnMask toggles closing on a mask tap (default on).
func (*PopupW) Closed
func (w *PopupW) Closed() boolClosed reports that the user dismissed the popup this frame.
func (*PopupW) Handle
func (w *PopupW) Handle(on bool) *PopupWHandle toggles the drawer grab handle of a bottom popup (shadcn default on): a bar on top of the sheet; dragging it down closes the popup.
func (*PopupW) Layout
func (w *PopupW) Layout(opts ...layout.Option) *PopupWLayout applies layout options to the panel.
func (*PopupW) Mask
func (w *PopupW) Mask(on bool) *PopupWMask toggles the dimmed backdrop (default on).
func (*PopupW) Position
func (w *PopupW) Position(p Position) *PopupWPosition sets where the panel appears.
func (*PopupW) Round
func (w *PopupW) Round(on bool) *PopupWRound toggles rounded corners on the inner edge.
Position
type Position uint8Position places a popup. PosLeft and PosRight are physical sides; PosStart and PosEnd are logical: the left and right edge left to right, the right and left edge in RTL.
const (
PosBottom Position = iota
PosTop
PosCenter
PosLeft
PosRight
PosStart
PosEnd
)Press
type Press struct {
Pressed bool // a finger is down on it and has not moved away
PressPos geom.Point // where the finger went down
Tap bool // tapped this frame
TapPos geom.Point
LongPress bool // held for LongPressDelay this frame
LongPos geom.Point
// KeyTap reports that Tap came from the keyboard (Enter / Space on the
// focused widget) or a screen reader (Press action); TapPos is then
// the centre of the widget.
KeyTap bool
}Press is the per-frame touch state of a touchable widget.
func Touchable
func Touchable(c *ui.Context, b *ui.Box) PressTouchable registers box b as a tappable widget and returns its touch state for this frame. Call it once per frame per widget. Inside a gesture area b gets no ui hit (the area captures the finger and the arena forwards taps); elsewhere b becomes hit-testable and a keyboard focus stop (Enter / Space tap it). In both cases a screen reader's Press action on b reports a Tap, so give b a role (b.Semantics) to expose it.
RefreshMachine
type RefreshMachine struct {
Status RefreshStatus
Threshold float64 // pull distance that arms the refresh
Delay time.Duration // how long RefreshComplete stays
// contains filtered or unexported fields
}RefreshMachine is the pull-to-refresh state machine (pure).
func (*RefreshMachine) Finish
func (m *RefreshMachine) Finish(now time.Time)Finish ends a refresh at now.
func (*RefreshMachine) Holding
func (m *RefreshMachine) Holding() boolHolding reports whether the header is held open.
func (*RefreshMachine) Pull
func (m *RefreshMachine) Pull(d float64)Pull updates the status for a drag at distance d (displayed px).
func (*RefreshMachine) Release
func (m *RefreshMachine) Release() boolRelease ends the drag; it reports whether a refresh starts.
func (*RefreshMachine) Start
func (m *RefreshMachine) Start()Start enters the refreshing state programmatically.
func (*RefreshMachine) Tick
func (m *RefreshMachine) Tick(now time.Time) (next time.Time)Tick advances timed transitions; it returns the time of the next one.
RefreshStatus
type RefreshStatus uint8RefreshStatus is the phase of a pull-to-refresh header.
const (
RefreshIdle RefreshStatus = iota
RefreshPulling // dragged down, below the threshold
RefreshCanRelease // past the threshold: releasing refreshes
RefreshRefreshing // loading; the header stays open
RefreshComplete // finished; shows the success text briefly
)ResultW
type ResultW struct {
// contains filtered or unexported fields
}ResultW is a full-width outcome page block.
func Result
func Result(c *ui.Context, status, title string) *ResultWResult adds an outcome block: status "success", "error", "info", "waiting" or "warning".
func (*ResultW) Description
func (w *ResultW) Description(s string) *ResultWDescription adds an explanation under the title.
Sample
type Sample struct {
Pos geom.Point
T time.Time
}Sample is one pointer position at a time.
ScrollMode
type ScrollMode uint8ScrollMode is what a Scroller is doing.
const (
Idle ScrollMode = iota
Dragging // following the finger
Flinging // inertial deceleration
Springing // bouncing back to an edge or settling on a snap point
)ScrollViewW
type ScrollViewW struct {
// contains filtered or unexported fields
}ScrollViewW is a touch scroll container: finger tracking, inertial fling, rubber-band edges and bounce back, with optional pull-to-refresh header and infinite-load footer.
func InfiniteList
func InfiniteList(c *ui.Context, loading *bool) *ScrollViewWInfiniteList creates a ScrollView that loads more when scrolled near the end: it sets *loading = true and LoadMore reports it. Set *loading back to false after appending rows; call Finished(true) when nothing is left.
func PullToRefresh
func PullToRefresh(c *ui.Context, refreshing *bool) *ScrollViewWPullToRefresh creates a ScrollView with a pull-down refresh header. Dragging past the threshold and releasing sets *refreshing = true and Refreshed reports it; set it back to false when the data has loaded.
func ScrollView
func ScrollView(c *ui.Context) *ScrollViewWScrollView creates a vertical touch scroll container. Give it a bounded height (Layout(layout.Grow(1)) in a sized column, or layout.H), set options, then build the content with Body.
func (*ScrollViewW) Bg
func (w *ScrollViewW) Bg(col paintColor) *ScrollViewWBg sets the background color.
func (*ScrollViewW) Body
func (w *ScrollViewW) Body(fn func()) *ScrollViewWBody builds the scrolling content.
func (*ScrollViewW) ContentID
func (w *ScrollViewW) ContentID() ui.IDContentID returns the ID of the moving content box.
func (*ScrollViewW) Failed
func (w *ScrollViewW) Failed(failed *bool) *ScrollViewWFailed binds a load error flag: the footer offers a retry tap.
func (*ScrollViewW) Finished
func (w *ScrollViewW) Finished(on bool) *ScrollViewWFinished marks the list complete (footer shows "no more").
func (*ScrollViewW) ID
func (w *ScrollViewW) ID() ui.IDID returns the container's ID.
func (*ScrollViewW) Infinite
func (w *ScrollViewW) Infinite(loading *bool) *ScrollViewWInfinite enables the load-more footer bound to *loading.
func (*ScrollViewW) Layout
func (w *ScrollViewW) Layout(opts ...layout.Option) *ScrollViewWLayout applies layout options to the container.
func (*ScrollViewW) LoadMore
func (w *ScrollViewW) LoadMore() boolLoadMore reports that the list asked for more rows this frame.
func (*ScrollViewW) Offset
func (w *ScrollViewW) Offset(px float32) *ScrollViewWOffset sets how close (px) to the end loading starts (default 50).
func (*ScrollViewW) Pull
func (w *ScrollViewW) Pull(refreshing *bool) *ScrollViewWPull enables the pull-to-refresh header bound to *refreshing.
func (*ScrollViewW) PullTexts
func (w *ScrollViewW) PullTexts(pulling, release, refreshing, complete string) *ScrollViewWPullTexts overrides the header texts (pulling, can release, refreshing, complete); empty entries keep the localized defaults.
func (*ScrollViewW) Refreshed
func (w *ScrollViewW) Refreshed() boolRefreshed reports that the user pulled to refresh this frame.
func (*ScrollViewW) Rows
func (w *ScrollViewW) Rows(n int, rowH float32, row func(i int))Rows builds a long list of n rows of a fixed height rowH inside Body, creating only the rows in or near the visible part of the view: the rest is a blank of the right height, so the scroll range, the fling and the infinite-load trigger behave as if every row were there. row(i) builds row i (keyed by i, so its state follows the index); keep the row's content within rowH. Other content may come before or after the rows in the same Body.
sv := mobile.ScrollView(c).Layout(layout.Grow(1))
sv.Body(func() {
mobile.List(c, "").Body(func() {
sv.Rows(len(items), 50, func(i int) { mobile.Cell(c, items[i]) })
})
})
Rows that are not built are not in the accessibility tree; a screen reader reaches them by scrolling. For variable row heights or a desktop scroll bar use ui.VirtualList inside the page instead.
func (*ScrollViewW) ScrollOffset
func (w *ScrollViewW) ScrollOffset() float64Offset returns the scroll offset (negative while pulled down).
func (*ScrollViewW) ScrollTo
func (w *ScrollViewW) ScrollTo(y float64) *ScrollViewWScrollTo jumps to offset y (clamped).
func (*ScrollViewW) Scrolling
func (w *ScrollViewW) Scrolling() boolScrolling reports whether the view is being dragged or still moving.
func (*ScrollViewW) Status
func (w *ScrollViewW) Status() RefreshStatusStatus returns the pull-to-refresh status.
Scroller
type Scroller struct {
Pos float64 // current offset
Min, Max float64 // scroll range
Dim float64 // viewport size on this axis (rubber band scale)
Snap float64 // > 0: rest only on multiples of Snap (from Min)
// NoBounce clamps at the edges instead of rubber-banding.
NoBounce bool
Mode ScrollMode
// contains filtered or unexported fields
}Scroller is the scroll physics of one axis: finger tracking with rubber band past the edges, inertial fling with exponential deceleration, critically damped bounce back, and optional snapping (picker wheels, pages). Positions grow as content moves up/left (like scroll offsets). It is pure: callers pass the time and read Pos.
func (*Scroller) Active
func (s *Scroller) Active() boolActive reports whether the scroller is moving on its own.
func (*Scroller) BeginDrag
func (s *Scroller) BeginDrag()BeginDrag stops any motion and starts following the finger.
func (*Scroller) DragBy
func (s *Scroller) DragBy(delta float64)DragBy moves to the drag-start position plus delta (finger travel in content direction, i.e. negative finger movement for natural scrolling).
func (*Scroller) Release
func (s *Scroller) Release(v float64, now time.Time)Release ends a drag with velocity v (px/s, content direction) at time now and starts the fling, bounce or snap that follows.
func (*Scroller) Settle
func (s *Scroller) Settle()Settle jumps to the rest position of the current motion.
func (*Scroller) SnapTo
func (s *Scroller) SnapTo(target float64, now time.Time)SnapTo glides to target (decelerating so it lands exactly there).
func (*Scroller) Step
func (s *Scroller) Step(now time.Time) boolStep advances the motion to now and reports whether it is still moving.
func (*Scroller) Stop
func (s *Scroller) Stop()Stop halts the motion where it is (a finger caught a fling).
SearchBarW
type SearchBarW struct {
// contains filtered or unexported fields
}SearchBarW is a rounded search field with an optional cancel action.
func SearchBar
func SearchBar(c *ui.Context, q *string, placeholder, cancel string) *SearchBarWSearchBar adds a search field bound to *q. placeholder "" uses the localized "搜索". Pass a non-empty cancel text to show a cancel action while the field has text. In the shadcn style the field is a muted, borderless rounded-lg input on the bar background with a ring on focus.
ConfigProvider defaults ("mobile.SearchBar"): "placeholder" (string, used when placeholder is ""), "cancelText" (string, used when cancel is ""), "shape" ("round" or "default").
func (*SearchBarW) Cancelled
func (w *SearchBarW) Cancelled() boolCancelled reports a tap on the cancel action.
func (*SearchBarW) Changed
func (w *SearchBarW) Changed() boolChanged reports an edit this frame.
func (*SearchBarW) Submitted
func (w *SearchBarW) Submitted() boolSubmitted reports Enter (search).
Size
type Size uint8Size is a mobile control size.
const (
Middle Size = iota
Mini
Small
Large
)SkeletonW
type SkeletonW struct {
// contains filtered or unexported fields
}SkeletonW is a loading placeholder of grey bars.
func Skeleton
func Skeleton(c *ui.Context) *SkeletonWSkeleton adds a placeholder; choose parts with Title, Paragraph, Avatar. The shadcn style pulses rounded-md muted bars instead of a shimmer.
ConfigProvider defaults ("mobile.Skeleton"): "title", "avatar", "animated" (bool), "rows" (int).
func (*SkeletonW) Animated
func (w *SkeletonW) Animated(on bool) *SkeletonWAnimated toggles the shimmer (on by default when animations run).
func (*SkeletonW) Avatar
func (w *SkeletonW) Avatar() *SkeletonWAvatar shows a round avatar placeholder.
func (*SkeletonW) Paragraph
func (w *SkeletonW) Paragraph(n int) *SkeletonWParagraph sets the number of text rows.
func (*SkeletonW) Title
func (w *SkeletonW) Title() *SkeletonWTitle shows a title bar.
StepperW
type StepperW struct {
// contains filtered or unexported fields
}StepperW is a − value + control.
func Stepper
func Stepper(c *ui.Context, v *float64) *StepperWStepper adds a stepper bound to *v (step 1, no bounds). Set options, then read Changed (applying the tap happens on the first query or at paint, whichever comes first, so bounds always apply). In the shadcn style it is an outlined button group (h-10) with ghost − / + buttons.
ConfigProvider defaults ("mobile.Stepper"): "step", "min", "max", "digits" (numbers), "disabled" (bool).
func (*StepperW) A11yLabel
func (w *StepperW) A11yLabel(s string) *StepperWA11yLabel sets the accessible name (inside a FormItem the label is used).
func (*StepperW) Changed
func (w *StepperW) Changed() boolChanged reports a step this frame.
func (*StepperW) Digits
func (w *StepperW) Digits(n int) *StepperWDigits fixes the decimals shown.
func (*StepperW) Disabled
func (w *StepperW) Disabled(on bool) *StepperWDisabled disables the control.
func (*StepperW) Max
func (w *StepperW) Max(v float64) *StepperWMax sets the upper bound.
func (*StepperW) Min
func (w *StepperW) Min(v float64) *StepperWMin sets the lower bound.
func (*StepperW) Step
func (w *StepperW) Step(s float64) *StepperWStep sets the increment.
Style
type Style uint8Style names the mobile design language the components imitate.
const (
AntMobile Style = iota // Ant Design Mobile (default)
Vant // Vant
// Shadcn derives a mobile look from the shadcn/ui design language
// (neutral colors, thin borders, rounded-lg/xl, near-black primary,
// Drawer-style bottom sheets, Sonner toasts). The default AntMobile
// resolves to Shadcn under a shadcn ui theme (theme.Shadcn).
Shadcn
)Swipe
type Swipe struct {
Dir Direction
Velocity geom.Point // px/s
Speed float32 // px/s along Dir
Distance float32 // px along Dir
}Swipe is a quick directional movement.
SwipeAction
type SwipeAction struct {
Key string
Text string
Color string // "primary" | "success" | "warning" | "danger" | "light" | "" (light)
}SwipeAction is a button revealed by swiping a SwipeCell.
SwipeCellW
type SwipeCellW struct {
// contains filtered or unexported fields
}SwipeCellW wraps content that can be swiped sideways to reveal actions.
Sides are logical: the Right actions sit at the end of the row and are revealed by swiping towards the start (to the left; in RTL the actions sit on the left and a swipe to the right reveals them), the Left ones at the start.
func SwipeCell
func SwipeCell(c *ui.Context) *SwipeCellWSwipeCell starts a swipeable row; set actions, then build the content with Body (typically one Cell).
ConfigProvider defaults ("mobile.SwipeCell"): "closeOnAction" (bool).
func (*SwipeCellW) Action
func (w *SwipeCellW) Action() (side, index int, ok bool)Action reports a tapped action this frame: side (1 Right / end, -1 Left / start), index into that side's actions.
func (*SwipeCellW) ActionKey
func (w *SwipeCellW) ActionKey() stringActionKey returns the Key (or Text) of the tapped action, "" if none.
func (*SwipeCellW) Body
func (w *SwipeCellW) Body(fn func()) *SwipeCellWBody builds the row content.
func (*SwipeCellW) Close
func (w *SwipeCellW) Close() *SwipeCellWClose closes the cell.
func (*SwipeCellW) IsOpen
func (w *SwipeCellW) IsOpen() boolIsOpen reports whether actions are (being) shown.
func (*SwipeCellW) KeepOpen
func (w *SwipeCellW) KeepOpen() *SwipeCellWKeepOpen keeps the cell open after an action tap.
func (*SwipeCellW) Left
func (w *SwipeCellW) Left(a ...SwipeAction) *SwipeCellWLeft sets the actions at the start, revealed by swiping right (left in RTL).
func (*SwipeCellW) Open
func (w *SwipeCellW) Open(side int) *SwipeCellWOpen opens the Right (end, side > 0) or Left (start, side < 0) actions.
func (*SwipeCellW) Right
func (w *SwipeCellW) Right(a ...SwipeAction) *SwipeCellWRight sets the actions at the end, revealed by swiping left (right in RTL).
SwiperW
type SwiperW struct {
// contains filtered or unexported fields
}SwiperW is a swipeable carousel of slides with indicator dots.
func Swiper
func Swiper(c *ui.Context, cur *int) *SwiperWSwiper creates a carousel; *cur is the current slide (nil keeps it internally). Set options, then build slides with Slides. In RTL the slides run right to left: the next slide comes in from the left, a swipe to the right shows it and the indicator starts at the right.
ConfigProvider defaults ("mobile.Swiper"): "autoplay" (time.Duration or ms), "loop", "indicator" (bool), "height", "radius" (numbers), "indicatorColor" ("white" for IndicatorWhite).
func (*SwiperW) Autoplay
func (w *SwiperW) Autoplay(d time.Duration) *SwiperWAutoplay advances every d.
func (*SwiperW) Changed
func (w *SwiperW) Changed() boolChanged reports a slide change this frame.
func (*SwiperW) Height
func (w *SwiperW) Height(px float32) *SwiperWHeight sets the slide height (default 150).
func (*SwiperW) Indicator
func (w *SwiperW) Indicator(on bool) *SwiperWIndicator toggles the dots.
func (*SwiperW) IndicatorColor
func (w *SwiperW) IndicatorColor(active, inactive theme.Color) *SwiperWIndicatorColor sets the color of the current slide's dot and of the others (a zero inactive color is active at 40% opacity). Use it when the style's dots (primary on a faint track) would vanish on the slides.
func (*SwiperW) IndicatorWhite
func (w *SwiperW) IndicatorWhite() *SwiperWIndicatorWhite draws white dots (Ant Design Mobile's indicator color "white"), for slides that are images or saturated colors.
func (*SwiperW) Loop
func (w *SwiperW) Loop() *SwiperWLoop wraps from the last slide to the first.
func (*SwiperW) Radius
func (w *SwiperW) Radius(px float32) *SwiperWRadius rounds the corners.
func (*SwiperW) Slides
func (w *SwiperW) Slides(n int, slide func(i int)) *SwiperWSlides builds n slides; slide(i) builds slide i.
TabBarW
type TabBarW struct {
// contains filtered or unexported fields
}TabBarW is the bottom tab bar.
func TabBar
func TabBar(c *ui.Context, items []TabItem, active *string) *TabBarWTabBar adds a bottom tab bar; *active holds the selected item's Key. It reserves the bottom safe-area inset below the items.
ConfigProvider defaults ("mobile.TabBar"): "bordered" (bool, the top line; default on).
func (*TabBarW) Border
func (w *TabBarW) Border(on bool) *TabBarWBorder toggles the top line (default on).
func (*TabBarW) Changed
func (w *TabBarW) Changed() boolChanged reports a tab switch this frame.
func (*TabBarW) ID
func (w *TabBarW) ID() ui.IDID returns the bar's ID.
TabItem
type TabItem struct {
Key string
Title string
Icon *icon.Icon
Badge string // "" none, "dot" for a dot, else the count text
}TabItem is one entry of a TabBar.
TabsW
type TabsW struct {
// contains filtered or unexported fields
}TabsW is a tab header with an underline and (optionally swipeable) content panes.
func Tabs
func Tabs(c *ui.Context, titles []string, active *int) *TabsWTabs adds tabs titled titles; *active is the selected index. Build the panes with Body (or Header for a header only).
In the shadcn style the header is a segmented control: a muted rounded-lg track with the selected title on a raised thumb.
In RTL the first title is at the right, the header scrolls from its right end and the panes follow the titles (the next pane comes in from the left).
ConfigProvider defaults ("mobile.Tabs"): "swipeable" (bool).
func (*TabsW) Body
func (w *TabsW) Body(pane func(i int)) *TabsWBody builds the header and the panes; pane(i) builds pane i.
func (*TabsW) Changed
func (w *TabsW) Changed() boolChanged reports a tab switch this frame.
func (*TabsW) Header
func (w *TabsW) Header() *TabsWHeader builds the header only.
func (*TabsW) Swipeable
func (w *TabsW) Swipeable() *TabsWSwipeable lets a horizontal swipe on the content switch tabs.
TagW
type TagW struct {
// contains filtered or unexported fields
}TagW is a small label.
func Tag
func Tag(c *ui.Context, label string) *TagWTag adds a tag (a shadcn Badge in the shadcn style: rounded-md, text-xs medium; "default" is the secondary variant).
ConfigProvider defaults ("mobile.Tag"): "color" (string), "fill" ("solid", "outline", "light"), "round" (bool).
func (*TagW) Color
func (w *TagW) Color(s string) *TagWColor sets "default", "primary", "success", "warning", "danger".
func (*TagW) Light
func (w *TagW) Light() *TagWLight uses a tinted background with colored text.
func (*TagW) Outline
func (w *TagW) Outline() *TagWOutline draws a border instead of a solid fill.
func (*TagW) Round
func (w *TagW) Round() *TagWRound makes the tag pill-shaped.
Theme
type Theme struct {
Style Style
Dark bool
Base *theme.Theme
// Brand and status colors.
Primary, Success, Warning, Danger theme.Color
PrimaryLight theme.Color // tinted background (tags, notice bars)
// Neutrals.
Text, TextSecondary, TextWeak, TextLight theme.Color
Border theme.Color // hairlines between cells
PageBg theme.Color // page background behind lists
Box theme.Color // cells, bars, panels
Fill theme.Color // stepper buttons, search fields, skeleton
Press theme.Color // overlay drawn over a pressed item
Mask theme.Color
ToastBg theme.Color
OnPrimary theme.Color // text on solid colored controls
// Typography (logical px; 1pt = 1px at the mobile reference density).
FontTiny, FontSmall, FontMain, FontBody, FontTitle, FontLarge float32
// Geometry.
TouchMin float32 // minimum touch target (44pt)
PadH float32 // horizontal page padding
Radius, RadiusLarge, PopupRad float32
NavBarHeight, TabBarHeight float32
CellPadV, CellMinHeight float32
ButtonHeight [4]float32 // Mini, Small, Middle, Large
ButtonFont [4]float32
ButtonRadius float32
PickerItemHeight float32
PickerVisible int // rows shown in a picker wheel
TabsHeight float32
TabsLineWidth, TabsLineHeight float32 // 0 width = as wide as the title
DialogWidth float32
ActionHeight float32
ToastPad float32
SearchHeight, SearchRadius float32
StepperHeight, StepperInputW float32
BadgeColor theme.Color
NoticeBg, NoticeText theme.Color
TitleWeight text.Weight
FormLabelWidth float32
// Tokens of the shadcn derivation; the Ant Mobile and Vant values keep
// their looks (zero colors mean "none").
OnSolid theme.Color // text on solid success / warning / danger fills
ButtonWeight text.Weight // button label weight
CardBorder theme.Color // outline of lists, cards, sheets and dialogs
DrawerHandle theme.Color // grab handle on top of bottom sheets
ToastText theme.Color // toast message color (on ToastBg)
ToastBorder theme.Color // toast outline
NoticeBorder theme.Color // notice bar top / bottom lines
SwitchOff theme.Color // switch track when off
SwitchThumb theme.Color // switch thumb when off
SwitchThumbOn theme.Color // switch thumb when on
SwitchW float32 // switch track size
SwitchH float32
Ring theme.Color // keyboard focus outline
SegmentThumb theme.Color // selected tab of the segmented (shadcn) Tabs
}Theme holds the mobile design tokens. It is derived from the ui theme (dark mode, brand color, mask) and the selected Style (sizes, neutrals). Components capture it at build time; read it with ThemeOf.
func NewTheme
func NewTheme(base *theme.Theme, style Style) *ThemeNewTheme derives the mobile tokens for style from the ui theme base. Under a high-contrast base (theme.HighContrast) the neutrals are lifted to WCAG AA like the ui theme's: text 4.5:1, arrows, borders and switch tracks 3:1 (see highContrast).
func ThemeOf
func ThemeOf(c *ui.Context) *ThemeThemeOf returns the mobile theme in effect.
func (*Theme) ColorOf
func (t *Theme) ColorOf(name string) theme.ColorColorOf maps a status name ("primary", "success", "warning", "danger", "default") to a color.
func (*Theme) Font
func (t *Theme) Font(px float32, w text.Weight) text.StyleFont returns a text style of px size and weight with a mobile line height (1.5×, rounded).
ToastOptions
type ToastOptions struct {
Icon string // "success", "fail", "loading" or ""
Duration time.Duration // default 2 s
Position Position // default PosCenter
}ToastOptions configure ShowToast.
ToastW
type ToastW struct {
// contains filtered or unexported fields
}ToastW is a short centred message.
func Toast
func Toast(c *ui.Context, show *bool, msg string) *ToastWToast shows msg while *show is true and clears it after the duration (2 s; 0 keeps it). Call Show after the options. In the shadcn style it is a Sonner toast: an outlined popover card with the icon inline, shown at the bottom by default.
ConfigProvider defaults ("mobile.Toast"): "duration" (time.Duration or ms), "position" ("top", "center", "bottom").
func (*ToastW) Duration
func (w *ToastW) Duration(d time.Duration) *ToastWDuration sets the auto-hide delay (0 = stay).
func (*ToastW) Icon
func (w *ToastW) Icon(kind string) *ToastWIcon adds an icon: "success", "fail", "loading".
func (*ToastW) Position
func (w *ToastW) Position(p Position) *ToastWPosition sets the vertical placement (PosTop, PosCenter, PosBottom).
func (*ToastW) Show
func (w *ToastW) Show() *ToastWShow renders the toast.
TouchPoint
type TouchPoint struct {
ID int64
Pos geom.Point
}TouchPoint is one finger of a multi-touch frame.
Track
type Track struct {
Start, Last Sample
Moved bool // travelled more than TouchSlop
Ended bool
LongFired bool
// contains filtered or unexported fields
}Track records one finger from down to up and classifies it. It is pure (no Context): feed Begin / Move / End with timestamps.
func (*Track) Begin
func (t *Track) Begin(s Sample)Begin starts the track at s.
func (*Track) Delta
func (t *Track) Delta() geom.PointDelta is the travel from the start.
func (*Track) End
func (t *Track) End(s Sample)End finishes the track at s.
func (*Track) Held
func (t *Track) Held(now time.Time) time.DurationHeld is how long the finger has been down at now.
func (*Track) IsTap
func (t *Track) IsTap() boolIsTap reports whether an ended track was a tap: short travel and not turned into a long press.
func (*Track) Move
func (t *Track) Move(s Sample) (crossed bool)Move adds a sample; it reports whether this move crossed the slop.
func (*Track) Swipe
func (t *Track) Swipe() (Swipe, bool)Swipe classifies an ended track as a swipe: fast enough or far enough along its dominant direction.
func (*Track) Velocity
func (t *Track) Velocity() geom.PointVelocity is the release velocity (px/s) over the last 100 ms of samples; zero when the finger rested or time did not advance.