mobile

package
v0.5.58 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2026 License: MIT Imports: 8 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package mobile is the reusable phone shell: one widget that gives a scene the platform navigation, a large title or app bar, a bottom bar or rail, a FAB, a snackbar and safe-area layout.

It is deliberately a widget, not a layout helper, so QML and Go callers get the same thing:

Window {
  MobileShell {
    id: shell
    title: "Portfolio"
    style: "auto"
    MobilePage { title: "Portfolio"; label: "Home"; icon: "grid"
      ScrollView { ... }
    }
  }
}

The shell lays the active page out between the header and the navigation bar, applies the platform's safe-area insets, and switches pages when a destination is chosen. The application supplies pages and behaviour; it never positions the shell.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Preset

func Preset(style Style, dark bool) string

Preset returns the matching theme preset name.

Types

type Action

type Action struct {
	ID      string
	Icon    string
	Tooltip string
}

Action is one app-bar or large-title action. The large title shows at most three; the Android app bar can show all of them.

type Options

type Options struct {
	Style    Style
	Title    string
	Subtitle string
	Actions  []Action
	FAB      bool
	Avatar   string
}

New builds a shell with common options filled in.

type Page

type Page struct {
	meui.BaseContainer
	Title    string
	Subtitle string
	Label    string
	Icon     string

	OnShow func()
}

Page is one destination. Its content is the QML/Go child.

func NewPage

func NewPage(title, label, icon string) *Page

NewPage builds an empty page. Label falls back to Title and Icon to "grid" when the destination list is built.

func (*Page) AddChild

func (p *Page) AddChild(child meui.Widget)

AddChild adds the page's content. A page normally owns one scroll view.

func (*Page) Paint

func (p *Page) Paint(canvas *graphics.Canvas, rect graphics.Rect)

Paint draws the page background; the content paints over it.

func (*Page) PanelAt

func (p *Page) PanelAt(x, y float32) meui.Widget

PanelAt routes a tap to the page content.

func (*Page) SetBoundProperty

func (p *Page) SetBoundProperty(name string, value interface{})

SetBoundProperty implements the QML binding hook.

func (*Page) SetVisible

func (p *Page) SetVisible(visible bool) *Page

SetVisible propagates visibility to the content: QML often declares the scroll view with visible:false, and the shell owns page visibility.

func (*Page) ValidateLayout

func (p *Page) ValidateLayout()

ValidateLayout makes the content fill the page.

type Shell

type Shell struct {
	meui.BaseContainer

	// OnAction fires for an app-bar/large-title action.
	OnAction func(string)
	// OnAvatar fires when the large-title avatar is tapped.
	OnAvatar func()
	// OnPageChanged fires after a destination changes.
	OnPageChanged func(int)
	// OnLayout is called after every reflow, with the page viewport in page-local
	// coordinates. Put inner card frames here.
	OnLayout func(graphics.Rect)
	// OnFAB fires when the floating button is tapped.
	OnFAB func()
	// OnBack runs before the shell's own back behaviour. Return true when the
	// app handled the gesture; returning false lets the shell pop a page and,
	// at the first page, lets the platform close the window.
	OnBack func() bool
	// contains filtered or unexported fields
}

Shell is the mobile scaffold. See the package comment for the QML shape.

func New

func New(opts Options) *Shell

func NewShell

func NewShell() *Shell

NewShell builds an empty shell. QML calls this; Go callers normally use New.

func (*Shell) AddChild

func (s *Shell) AddChild(child meui.Widget)

AddChild adds a MobilePage (or any other widget). Non-page children are tracked but not made destinations.

func (*Shell) Back

func (s *Shell) Back() bool

Back moves to the previous destination and reports whether it did. Bind wires the window's back gesture to it when the root supports SetOnBack.

func (*Shell) Bind

func (s *Shell) Bind(w platform.Window, root *meui.Window)

Bind attaches the shell to its platform window and its root. The root is the content window used for modals; the platform window supplies resize, insets and size. Call it after App.AddWindow.

func (*Shell) CompactWidth added in v0.2.1

func (s *Shell) CompactWidth() float32

CompactWidth reports the threshold.

func (*Shell) ContentRect

func (s *Shell) ContentRect() graphics.Rect

ContentRect returns the page viewport in page-local coordinates.

func (*Shell) Current

func (s *Shell) Current() int

Current reports the active destination.

func (*Shell) FABVisible

func (s *Shell) FABVisible() bool

FABVisible reports whether the floating button is shown.

func (*Shell) Insets

func (s *Shell) Insets() platform.Insets

Insets returns the current safe-area insets.

func (*Shell) KeyboardAvoidance

func (s *Shell) KeyboardAvoidance() bool

KeyboardAvoidance reports the setting.

func (*Shell) KeyboardInset

func (s *Shell) KeyboardInset() float32

KeyboardInset reports the keyboard height used by the last layout.

func (*Shell) PageCount

func (s *Shell) PageCount() int

PageCount reports the number of destinations.

func (*Shell) Pages

func (s *Shell) Pages() []*Page

Pages returns the destinations in declaration order.

func (*Shell) Paint

func (s *Shell) Paint(canvas *graphics.Canvas, rect graphics.Rect)

Paint draws the shell background, the page, the chrome and the overlays.

func (*Shell) PanelAt

func (s *Shell) PanelAt(x, y float32) meui.Widget

PanelAt routes to the chrome first, then the active page.

func (*Shell) Relayout

func (s *Shell) Relayout()

Relayout reflows and asks for a paint.

func (*Shell) RevealFocused

func (s *Shell) RevealFocused() bool

RevealFocused scrolls the nearest ScrollPane ancestor of the focused widget so the widget is inside the visible height above the keyboard. It returns true when the scroll moved.

func (*Shell) SafeArea added in v0.2.1

func (s *Shell) SafeArea() bool

SafeArea reports the setting.

func (*Shell) SetActions

func (s *Shell) SetActions(actions []Action) *Shell

SetActions replaces the header actions.

func (*Shell) SetAvatar

func (s *Shell) SetAvatar(text string, onClick func()) *Shell

SetAvatar shows the large-title avatar. An empty text hides it.

func (*Shell) SetBoundProperty

func (s *Shell) SetBoundProperty(name string, value interface{})

SetBoundProperty implements the QML binding hook.

func (*Shell) SetCompactWidth added in v0.2.1

func (s *Shell) SetCompactWidth(width float32) *Shell

SetCompactWidth changes the width below which the bottom bar is used instead of the rail. The default is 700. Mobile hosts whose window units are physical pixels can raise it; a 1080px phone with density 2.75 is 393dp.

func (*Shell) SetFABLabel

func (s *Shell) SetFABLabel(label string) *Shell

SetFABLabel sets the floating button's glyph.

func (*Shell) SetFABVisible

func (s *Shell) SetFABVisible(on bool) *Shell

SetFABVisible shows or hides the floating action button.

func (*Shell) SetInsets

func (s *Shell) SetInsets(in platform.Insets) *Shell

SetInsets sets the safe-area insets. Bind does this automatically.

func (*Shell) SetKeyboardAvoidance

func (s *Shell) SetKeyboardAvoidance(on bool) *Shell

SetKeyboardAvoidance controls whether the shell reserves the IME height. It is on by default: the navigation bar is lifted above the keyboard and the page viewport ends above it. Turn it off when the page intentionally paints behind the keyboard.

func (*Shell) SetRoot

func (s *Shell) SetRoot(root *meui.Window)

SetRoot attaches the modal root without a platform window. Shot harnesses use it before showing an overlay; Bind also sets it.

func (*Shell) SetSafeArea added in v0.2.1

func (s *Shell) SetSafeArea(on bool) *Shell

SetSafeArea controls whether the shell subtracts the platform's top/right/ bottom/left insets. It is on by default for headless layouts. Bind turns it off automatically when the content root is already the safe-area rectangle, which is what the Android adapter paints; applying the insets twice is what made a 1080px phone look like a double-inset tablet.

func (*Shell) SetStyle

func (s *Shell) SetStyle(style Style) *Shell

SetStyle sets the shell idiom. Normally called by QML before the first layout.

func (*Shell) SetSubtitle

func (s *Shell) SetSubtitle(subtitle string) *Shell

SetSubtitle sets the fallback subtitle.

func (*Shell) SetTitle

func (s *Shell) SetTitle(title string) *Shell

SetTitle sets the fallback title used when a page has none.

func (*Shell) ShowActionSheet

func (s *Shell) ShowActionSheet(header, message string, items []widgets.ActionSheetItem, onChoose func(string)) *widgets.ActionSheet

ShowActionSheet opens an action sheet and reports choices through onChoose.

func (*Shell) ShowAlert

func (s *Shell) ShowAlert(title, message string, actions []widgets.DialogAction, onAction func(string)) *widgets.AlertDialog

ShowAlert opens the adaptive alert dialog.

func (*Shell) ShowPage

func (s *Shell) ShowPage(i int)

ShowPage makes a destination active and notifies the window.

func (*Shell) ShowSearch

func (s *Shell) ShowSearch(placeholder string, results []widgets.SearchViewResult, onChoose func(string)) *widgets.SearchView

ShowSearch opens a full-screen search view.

func (*Shell) ShowSheet

func (s *Shell) ShowSheet(title, body string) *widgets.BottomSheet

ShowSheet opens a bottom sheet with a wrapped body. It returns the widget so a caller can set OnDismissed.

func (*Shell) Snackbar

func (s *Shell) Snackbar() *widgets.Snackbar

Snackbar exposes the message strip.

func (*Shell) Style

func (s *Shell) Style() Style

Style reports the resolved idiom.

func (*Shell) Toast

func (s *Shell) Toast(text string)

Toast shows a snackbar message.

func (*Shell) ValidateLayout

func (s *Shell) ValidateLayout()

ValidateLayout places the chrome, the pages and the overlays. It is called by the window after every resize and by Relayout.

type Style

type Style int

Style selects the shell idiom. The theme preset is chosen separately (see Preset) because colors are resolved when QML is parsed.

const (
	Auto Style = iota
	Android
	IOS
)

func ParseStyle

func ParseStyle(s string) Style

ParseStyle reads the QML string form.

func (Style) Resolve

func (s Style) Resolve() Style

Resolve turns Auto into the host platform's idiom.

func (Style) String

func (s Style) String() string

Jump to

Keyboard shortcuts

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