Documentation
¶
Overview ¶
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 稳定性").
Index ¶
- Constants
- func Badge(c *ui.Context, content string, fn func()) *ui.Box
- func ClearToast(c *ui.Context)
- func Decay(p0, v0, t float64) (p, v float64)
- func DecayTarget(p0, v0 float64) float64
- func DrawBadge(l *paint.List, th *Theme, s string, cx, cy float32)
- func Provider(c *ui.Context, o Options, fn func())
- func Rubber(d, dim float64) float64
- func RubberInverse(v, dim float64) float64
- func SafeArea(c *ui.Context, edge Edge) *ui.Box
- func SafeAreaInsets(c *ui.Context) geom.Insets
- func ShowToast(c *ui.Context, msg string, o ...ToastOptions)
- func Spring(x0, v0, omega, t float64) (x, v float64)
- func Within(c *ui.Context, id ui.ID, fn func())
- type Action
- type ActionSheetW
- type Axis
- type ButtonW
- func (w *ButtonW) A11yLabel(s string) *ButtonW
- func (w *ButtonW) Block() *ButtonW
- func (w *ButtonW) Clicked() bool
- func (w *ButtonW) Color(s string) *ButtonW
- func (w *ButtonW) Danger() *ButtonW
- func (w *ButtonW) Disabled(on bool) *ButtonW
- func (w *ButtonW) Fill(s string) *ButtonW
- func (w *ButtonW) ID() ui.ID
- func (w *ButtonW) Icon(ic *icon.Icon) *ButtonW
- func (w *ButtonW) Layout(opts ...layout.Option) *ButtonW
- func (w *ButtonW) Loading(on bool) *ButtonW
- func (w *ButtonW) Primary() *ButtonW
- func (w *ButtonW) Round() *ButtonW
- func (w *ButtonW) Size(s Size) *ButtonW
- type CellW
- func (w *CellW) Arrow() *CellW
- func (w *CellW) Changed() bool
- func (w *CellW) Clickable() *CellW
- func (w *CellW) Clicked() bool
- func (w *CellW) Desc(s string) *CellW
- func (w *CellW) Disabled(on bool) *CellW
- func (w *CellW) Extra(s string) *CellW
- func (w *CellW) ID() ui.ID
- func (w *CellW) Icon(ic *icon.Icon) *CellW
- func (w *CellW) LongPressed() bool
- func (w *CellW) Required() *CellW
- func (w *CellW) Switch(on *bool) *CellW
- type DatePrecision
- type DialogW
- func (w *DialogW) Cancelled() bool
- func (w *DialogW) CloseOnMask() *DialogW
- func (w *DialogW) Confirm(ok, cancel string) *DialogW
- func (w *DialogW) Confirmed() bool
- func (w *DialogW) Content(s string) *DialogW
- func (w *DialogW) Custom(fn func()) *DialogW
- func (w *DialogW) OKText(s string) *DialogW
- func (w *DialogW) PanelID() ui.ID
- func (w *DialogW) Show() *DialogW
- type Direction
- type Edge
- type EmptyW
- type FieldW
- func (w *FieldW) Changed() bool
- func (w *FieldW) EnterKey(k input.EnterKey) *FieldW
- func (w *FieldW) Input() *ui.InputW
- func (w *FieldW) MaxLength(n int) *FieldW
- func (w *FieldW) Password() *FieldW
- func (w *FieldW) Placeholder(s string) *FieldW
- func (w *FieldW) Submitted() bool
- func (w *FieldW) Type(k input.TextKind) *FieldW
- type FloatingBubbleW
- type FormItemW
- type FormW
- type Gesture
- type GridItem
- type GridW
- type IndexBarW
- type ListW
- type NavBarW
- func (w *NavBarW) Back(text string) *NavBarW
- func (w *NavBarW) BackClicked() bool
- func (w *NavBarW) Border(on bool) *NavBarW
- func (w *NavBarW) ID() ui.ID
- func (w *NavBarW) Right(text string) *NavBarW
- func (w *NavBarW) RightClicked() bool
- func (w *NavBarW) RightIcon(ic *icon.Icon) *NavBarW
- func (w *NavBarW) RightLabel(s string) *NavBarW
- type NoticeBarW
- type Options
- type Pan
- type PickerViewW
- type PickerW
- func (w *PickerW) Cancelled() bool
- func (w *PickerW) Cascade(opts []ui.CascaderOption, value *[]string) *PickerW
- func (w *PickerW) Columns(cols [][]ui.Option, value *[]string) *PickerW
- func (w *PickerW) Confirmed() bool
- func (w *PickerW) Date(value *time.Time, p DatePrecision, bounds ...time.Time) *PickerW
- func (w *PickerW) Show() *PickerW
- type Pinch
- type PinchRecognizer
- type PopupW
- func (w *PopupW) A11yLabel(s string) *PopupW
- func (w *PopupW) Bg(col paintColor) *PopupW
- func (w *PopupW) Body(fn func()) *PopupW
- func (w *PopupW) CloseOnMask(on bool) *PopupW
- func (w *PopupW) Closed() bool
- func (w *PopupW) Handle(on bool) *PopupW
- func (w *PopupW) Layout(opts ...layout.Option) *PopupW
- func (w *PopupW) Mask(on bool) *PopupW
- func (w *PopupW) Position(p Position) *PopupW
- func (w *PopupW) Round(on bool) *PopupW
- type Position
- type Press
- type RefreshMachine
- type RefreshStatus
- type ResultW
- type Sample
- type ScrollMode
- type ScrollViewW
- func (w *ScrollViewW) Bg(col paintColor) *ScrollViewW
- func (w *ScrollViewW) Body(fn func()) *ScrollViewW
- func (w *ScrollViewW) ContentID() ui.ID
- func (w *ScrollViewW) Failed(failed *bool) *ScrollViewW
- func (w *ScrollViewW) Finished(on bool) *ScrollViewW
- func (w *ScrollViewW) ID() ui.ID
- func (w *ScrollViewW) Infinite(loading *bool) *ScrollViewW
- func (w *ScrollViewW) Layout(opts ...layout.Option) *ScrollViewW
- func (w *ScrollViewW) LoadMore() bool
- func (w *ScrollViewW) Offset(px float32) *ScrollViewW
- func (w *ScrollViewW) Pull(refreshing *bool) *ScrollViewW
- func (w *ScrollViewW) PullTexts(pulling, release, refreshing, complete string) *ScrollViewW
- func (w *ScrollViewW) Refreshed() bool
- func (w *ScrollViewW) Rows(n int, rowH float32, row func(i int))
- func (w *ScrollViewW) ScrollOffset() float64
- func (w *ScrollViewW) ScrollTo(y float64) *ScrollViewW
- func (w *ScrollViewW) Scrolling() bool
- func (w *ScrollViewW) Status() RefreshStatus
- type Scroller
- func (s *Scroller) Active() bool
- func (s *Scroller) BeginDrag()
- func (s *Scroller) DragBy(delta float64)
- func (s *Scroller) Release(v float64, now time.Time)
- func (s *Scroller) Settle()
- func (s *Scroller) SnapTo(target float64, now time.Time)
- func (s *Scroller) Step(now time.Time) bool
- func (s *Scroller) Stop()
- type SearchBarW
- type Size
- type SkeletonW
- type StepperW
- func (w *StepperW) A11yLabel(s string) *StepperW
- func (w *StepperW) Changed() bool
- func (w *StepperW) Digits(n int) *StepperW
- func (w *StepperW) Disabled(on bool) *StepperW
- func (w *StepperW) Max(v float64) *StepperW
- func (w *StepperW) Min(v float64) *StepperW
- func (w *StepperW) Step(s float64) *StepperW
- type Style
- type Swipe
- type SwipeAction
- type SwipeCellW
- func (w *SwipeCellW) Action() (side, index int, ok bool)
- func (w *SwipeCellW) ActionKey() string
- func (w *SwipeCellW) Body(fn func()) *SwipeCellW
- func (w *SwipeCellW) Close() *SwipeCellW
- func (w *SwipeCellW) IsOpen() bool
- func (w *SwipeCellW) KeepOpen() *SwipeCellW
- func (w *SwipeCellW) Left(a ...SwipeAction) *SwipeCellW
- func (w *SwipeCellW) Open(side int) *SwipeCellW
- func (w *SwipeCellW) Right(a ...SwipeAction) *SwipeCellW
- type SwiperW
- func (w *SwiperW) Autoplay(d time.Duration) *SwiperW
- func (w *SwiperW) Changed() bool
- func (w *SwiperW) Height(px float32) *SwiperW
- func (w *SwiperW) Indicator(on bool) *SwiperW
- func (w *SwiperW) IndicatorColor(active, inactive theme.Color) *SwiperW
- func (w *SwiperW) IndicatorWhite() *SwiperW
- func (w *SwiperW) Loop() *SwiperW
- func (w *SwiperW) Radius(px float32) *SwiperW
- func (w *SwiperW) Slides(n int, slide func(i int)) *SwiperW
- type TabBarW
- type TabItem
- type TabsW
- type TagW
- type Theme
- type ToastOptions
- type ToastW
- type TouchPoint
- type Track
Constants ¶
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.
Variables ¶
This section is empty.
Functions ¶
func Badge ¶
Badge 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 Decay ¶
Decay returns the position and velocity t seconds into a fling that started at p0 with velocity v0 (px/s).
func DecayTarget ¶
DecayTarget is where a fling from p0 with velocity v0 comes to rest.
func DrawBadge ¶
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 ¶
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 ¶
Rubber maps an overshoot d (px past the edge, ≥ 0) to the displayed overshoot for a viewport of size dim.
func RubberInverse ¶
RubberInverse is the inverse of Rubber: the finger overshoot that displays as v.
func SafeArea ¶
SafeArea adds a blank of the safe-area inset of edge (Top: status bar / notch, Bottom: home indicator), filled with the box color.
func SafeAreaInsets ¶
SafeAreaInsets 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.
Types ¶
type Action ¶
type Action struct {
Key string
Text string
Description string
Danger bool
Bold bool
Disabled bool
}
Action is one entry of an ActionSheet.
type 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) *ActionSheetW
ActionSheet 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) *ActionSheetW
Cancel adds a separated cancel button ("" uses the localized "取消").
func (*ActionSheetW) Cancelled ¶
func (w *ActionSheetW) Cancelled() bool
Cancelled reports a tap on the cancel button or the mask this frame.
func (*ActionSheetW) Extra ¶
func (w *ActionSheetW) Extra(s string) *ActionSheetW
Extra 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.
type Axis ¶
type Axis uint8
Axis is the set of drag directions an area accepts.
const ( AxisNone Axis = 0 AxisHorizontal Axis = 1 << 0 AxisVertical Axis = 1 << 1 AxisBoth = AxisHorizontal | AxisVertical )
type ButtonW ¶
type ButtonW struct {
// contains filtered or unexported fields
}
ButtonW is a touch button sized for fingers.
func Button ¶
Button 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).
type 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 ¶
Cell adds a list row titled title.
ConfigProvider defaults ("mobile.Cell"): "arrow", "clickable" (bool).
func (*CellW) LongPressed ¶
LongPressed reports a long press on the row.
type DatePrecision ¶
type DatePrecision uint8
DatePrecision is the finest column of a date picker.
const ( PrecisionYear DatePrecision = iota PrecisionMonth PrecisionDay PrecisionHour PrecisionMinute )
type DialogW ¶
type DialogW struct {
// contains filtered or unexported fields
}
DialogW is a centred modal with a title, message and buttons.
func Dialog ¶
Dialog 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) CloseOnMask ¶
CloseOnMask lets a mask tap dismiss the dialog (cancel).
func (*DialogW) Confirm ¶
Confirm turns the dialog into a confirm box with OK / Cancel buttons ("" keeps the localized texts).
type Direction ¶
type Direction uint8
Direction is the dominant direction of a movement.
func DirectionOf ¶
DirectionOf returns the dominant direction of v.
func (Direction) Horizontal ¶
Horizontal reports whether d is left or right.
type EmptyW ¶
type EmptyW struct {
// contains filtered or unexported fields
}
EmptyW is an empty-state placeholder.
func Empty ¶
Empty 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 ¶
Description replaces the caption.
type FieldW ¶
type FieldW struct {
// contains filtered or unexported fields
}
FieldW is a borderless single-line text input for forms and cells.
func Field ¶
Field 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) EnterKey ¶
EnterKey labels the soft keyboard's return key (input.EnterNext, input.EnterDone, …); pressing it still reports Submitted.
func (*FieldW) Placeholder ¶
Placeholder sets the hint text.
type 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 ¶
FloatingBubble 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) *FloatingBubbleW
A11yLabel sets the accessible name of the bubble (it shows an icon only).
func (*FloatingBubbleW) Clicked ¶
func (w *FloatingBubbleW) Clicked() bool
Clicked reports a tap on the bubble.
type FormItemW ¶
type FormItemW struct {
// contains filtered or unexported fields
}
FormItemW is one labelled field of a Form.
type 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.
type 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.
type GridW ¶
type GridW struct {
// contains filtered or unexported fields
}
GridW is a grid of icon + text entries.
type 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.
type ListW ¶
type ListW struct {
// contains filtered or unexported fields
}
ListW is a group of cells with an optional header.
func List ¶
List starts a cell group titled header ("" for none); add cells in Body.
ConfigProvider defaults ("mobile.List"): "mode" ("default" or "card").
type 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 ¶
NavBar adds a navigation bar titled title.
ConfigProvider defaults ("mobile.NavBar"): "bordered" (bool).
func (*NavBarW) Back ¶
Back shows the back arrow with optional text (Ant Mobile shows the arrow only by default; Vant styles typically pass "返回").
func (*NavBarW) BackClicked ¶
BackClicked reports a tap on the back area.
func (*NavBarW) Border ¶
Border toggles the bottom hairline (Vant and shadcn default on, Ant Mobile off).
func (*NavBarW) RightClicked ¶
RightClicked reports a tap on the right action.
func (*NavBarW) RightIcon ¶
RightIcon shows an icon action at the end; name it with RightLabel unless Right gives it a text.
func (*NavBarW) RightLabel ¶
RightLabel sets the accessible name of the right action (needed for an icon-only action).
type 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) *NoticeBarW
NoticeBar 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() *NoticeBarW
Closeable shows a close button.
func (*NoticeBarW) Closed ¶
func (w *NoticeBarW) Closed() bool
Closed reports a tap on the close button this frame.
func (*NoticeBarW) Color ¶
func (w *NoticeBarW) Color(s string) *NoticeBarW
Color sets "default" (orange), "alert", "error" or "info".
func (*NoticeBarW) Scroll ¶
func (w *NoticeBarW) Scroll() *NoticeBarW
Scroll makes long text scroll (marquee; towards the start, so to the right in RTL).
type 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.
type 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.
type 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) *PickerViewW
CascadePickerView 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) *PickerViewW
DatePickerView 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 ¶
PickerView 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) *PickerViewW
A11yLabel 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) *PickerViewW
A11yLabels sets the accessible name of each wheel.
func (*PickerViewW) Changed ¶
func (w *PickerViewW) Changed() bool
Changed reports a wheel settling on a new value this frame.
func (*PickerViewW) Visible ¶
func (w *PickerViewW) Visible(n int) *PickerViewW
Visible sets how many rows each wheel shows (odd numbers centre best).
type 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 ¶
Picker 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) Cascade ¶
func (w *PickerW) Cascade(opts []ui.CascaderOption, value *[]string) *PickerW
Cascade shows linked wheels for a tree of options.
type 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.
type 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) Pinch
Update consumes the current set of touching fingers and returns the pinch state (Active false with fewer than two fingers).
type PopupW ¶
type PopupW struct {
// contains filtered or unexported fields
}
PopupW is a sliding panel over a dimmed mask.
func Popup ¶
Popup 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 ¶
A11yLabel sets the accessible name of the panel (a dialog for screen readers; name it after its content).
func (*PopupW) CloseOnMask ¶
CloseOnMask toggles closing on a mask tap (default on).
func (*PopupW) Handle ¶
Handle 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.
type Position ¶
type Position uint8
Position 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.
type 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 ¶
Touchable 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.
type 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() bool
Holding 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() bool
Release ends the drag; it reports whether a refresh starts.
func (*RefreshMachine) Start ¶
func (m *RefreshMachine) Start()
Start enters the refreshing state programmatically.
type RefreshStatus ¶
type RefreshStatus uint8
RefreshStatus 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 )
type ResultW ¶
type ResultW struct {
// contains filtered or unexported fields
}
ResultW is a full-width outcome page block.
func Result ¶
Result adds an outcome block: status "success", "error", "info", "waiting" or "warning".
func (*ResultW) Description ¶
Description adds an explanation under the title.
type ScrollMode ¶
type ScrollMode uint8
ScrollMode 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 )
type 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) *ScrollViewW
InfiniteList 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) *ScrollViewW
PullToRefresh 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) *ScrollViewW
ScrollView 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) *ScrollViewW
Bg sets the background color.
func (*ScrollViewW) Body ¶
func (w *ScrollViewW) Body(fn func()) *ScrollViewW
Body builds the scrolling content.
func (*ScrollViewW) ContentID ¶
func (w *ScrollViewW) ContentID() ui.ID
ContentID returns the ID of the moving content box.
func (*ScrollViewW) Failed ¶
func (w *ScrollViewW) Failed(failed *bool) *ScrollViewW
Failed binds a load error flag: the footer offers a retry tap.
func (*ScrollViewW) Finished ¶
func (w *ScrollViewW) Finished(on bool) *ScrollViewW
Finished marks the list complete (footer shows "no more").
func (*ScrollViewW) Infinite ¶
func (w *ScrollViewW) Infinite(loading *bool) *ScrollViewW
Infinite enables the load-more footer bound to *loading.
func (*ScrollViewW) Layout ¶
func (w *ScrollViewW) Layout(opts ...layout.Option) *ScrollViewW
Layout applies layout options to the container.
func (*ScrollViewW) LoadMore ¶
func (w *ScrollViewW) LoadMore() bool
LoadMore reports that the list asked for more rows this frame.
func (*ScrollViewW) Offset ¶
func (w *ScrollViewW) Offset(px float32) *ScrollViewW
Offset sets how close (px) to the end loading starts (default 50).
func (*ScrollViewW) Pull ¶
func (w *ScrollViewW) Pull(refreshing *bool) *ScrollViewW
Pull enables the pull-to-refresh header bound to *refreshing.
func (*ScrollViewW) PullTexts ¶
func (w *ScrollViewW) PullTexts(pulling, release, refreshing, complete string) *ScrollViewW
PullTexts overrides the header texts (pulling, can release, refreshing, complete); empty entries keep the localized defaults.
func (*ScrollViewW) Refreshed ¶
func (w *ScrollViewW) Refreshed() bool
Refreshed 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() float64
Offset returns the scroll offset (negative while pulled down).
func (*ScrollViewW) ScrollTo ¶
func (w *ScrollViewW) ScrollTo(y float64) *ScrollViewW
ScrollTo jumps to offset y (clamped).
func (*ScrollViewW) Scrolling ¶
func (w *ScrollViewW) Scrolling() bool
Scrolling reports whether the view is being dragged or still moving.
func (*ScrollViewW) Status ¶
func (w *ScrollViewW) Status() RefreshStatus
Status returns the pull-to-refresh status.
type 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) BeginDrag ¶
func (s *Scroller) BeginDrag()
BeginDrag stops any motion and starts following the finger.
func (*Scroller) DragBy ¶
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 ¶
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.
type 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) *SearchBarW
SearchBar 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() bool
Cancelled reports a tap on the cancel action.
func (*SearchBarW) Changed ¶
func (w *SearchBarW) Changed() bool
Changed reports an edit this frame.
func (*SearchBarW) Submitted ¶
func (w *SearchBarW) Submitted() bool
Submitted reports Enter (search).
type SkeletonW ¶
type SkeletonW struct {
// contains filtered or unexported fields
}
SkeletonW is a loading placeholder of grey bars.
func Skeleton ¶
Skeleton 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).
type StepperW ¶
type StepperW struct {
// contains filtered or unexported fields
}
StepperW is a − value + control.
func Stepper ¶
Stepper 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 ¶
A11yLabel sets the accessible name (inside a FormItem the label is used).
type Style ¶
type Style uint8
Style 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 )
type 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.
type 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.
type 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) *SwipeCellW
SwipeCell 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() string
ActionKey returns the Key (or Text) of the tapped action, "" if none.
func (*SwipeCellW) Body ¶
func (w *SwipeCellW) Body(fn func()) *SwipeCellW
Body builds the row content.
func (*SwipeCellW) IsOpen ¶
func (w *SwipeCellW) IsOpen() bool
IsOpen reports whether actions are (being) shown.
func (*SwipeCellW) KeepOpen ¶
func (w *SwipeCellW) KeepOpen() *SwipeCellW
KeepOpen keeps the cell open after an action tap.
func (*SwipeCellW) Left ¶
func (w *SwipeCellW) Left(a ...SwipeAction) *SwipeCellW
Left sets the actions at the start, revealed by swiping right (left in RTL).
func (*SwipeCellW) Open ¶
func (w *SwipeCellW) Open(side int) *SwipeCellW
Open opens the Right (end, side > 0) or Left (start, side < 0) actions.
func (*SwipeCellW) Right ¶
func (w *SwipeCellW) Right(a ...SwipeAction) *SwipeCellW
Right sets the actions at the end, revealed by swiping left (right in RTL).
type SwiperW ¶
type SwiperW struct {
// contains filtered or unexported fields
}
SwiperW is a swipeable carousel of slides with indicator dots.
func Swiper ¶
Swiper 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) IndicatorColor ¶
IndicatorColor 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 ¶
IndicatorWhite draws white dots (Ant Design Mobile's indicator color "white"), for slides that are images or saturated colors.
type TabBarW ¶
type TabBarW struct {
// contains filtered or unexported fields
}
TabBarW is the bottom tab bar.
func TabBar ¶
TabBar 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).
type 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.
type TabsW ¶
type TabsW struct {
// contains filtered or unexported fields
}
TabsW is a tab header with an underline and (optionally swipeable) content panes.
func Tabs ¶
Tabs 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).
type TagW ¶
type TagW struct {
// contains filtered or unexported fields
}
TagW is a small label.
func Tag ¶
Tag 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).
type 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
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 ¶
NewTheme 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).
type ToastOptions ¶
type ToastOptions struct {
Icon string // "success", "fail", "loading" or ""
Duration time.Duration // default 2 s
Position Position // default PosCenter
}
ToastOptions configure ShowToast.
type ToastW ¶
type ToastW struct {
// contains filtered or unexported fields
}
ToastW is a short centred message.
func Toast ¶
Toast 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").
type TouchPoint ¶
TouchPoint is one finger of a multi-touch frame.
type 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) IsTap ¶
IsTap reports whether an ended track was a tap: short travel and not turned into a long press.