Documentation ¶
Overview ¶
Package router helps manage the content of Gio windows by routing between multiple content "pages".
Index ¶
- type C
- type D
- type Mountable
- type Page
- type Router
- func (r *Router) Add(name string, p Page)
- func (r *Router) Current() Page
- func (r *Router) GetName(p Page) string
- func (r *Router) Jump(ii int)
- func (r *Router) Layout(gtx C) D
- func (r *Router) Navigated() (name string, p Page)
- func (r *Router) Pop() string
- func (r *Router) Push(page string)
- func (r *Router) Update(data any) bool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type D ¶
type D = layout.Dimensions
type Mountable ¶
type Mountable interface { Page // Mount will be invoked by the router whenever a page is navigated to. // This method is invoked synchronously with the window event loop, and // should not perform blocking I/O or other long-running tasks. Mount() // Unmount will be invoked by the router whenever a page is navigated // away from. // This method is invoked synchronously with the window event loop, and // should not perform blocking I/O or other long-running tasks. Unmount() }
Mountable is an optional interface that pages can implement in order to be notified when they are navigated to and from.
type Page ¶
type Page interface { // Update data for the page. The page can type switch and // respond to data that it cares about. This method should // return true if the page recognizes // the data and changes its state in response. // // Data is passed to every page such that all pages see // all updates. Update(data any) bool // Layout lays the frame out, as per `layout.Widget`. // // This builds the ops buffer and needs read access to // page data and read-write access to the pages state. Layout(gtx C) D }
Page implements an independent UI context. Pages maintain their own state, and implement methods that allow them to be orchestrated by the UI.
type Router ¶
type Router struct { // Pages is a map of string identifiers to page values. // For a page to be available to the router, it must appear in this // map. Pages map[string]Page // History is a stack of visited pages, useful for many navigation // concerns. History []Page // contains filtered or unexported fields }
Router implements page navigation primitives, such as a stack of history.
Pages are displayed in a mutally exlusive way, that is, only one page can be "active" at a time.
Each `Push` to the router pushes that page to the history, and each `Pop` does the inverse.
Pushes are specified by the string identifer of the page, according to the `Pages` map.
Router implements the Page interface, and can be used anywhere a page can be.
func (*Router) Add ¶
Add page to the pages collection to make it available to the UI. Does not affect history.
func (*Router) GetName ¶
GetName of the page as stored in the router, if any. Uses pointer comparison to identify the page.
func (*Router) Navigated ¶
Navigated returns the latest navigation event and clears it. This allows the parent to respond to navigation changes.
func (*Router) Pop ¶
Pop the page history to navigate backwards, returning the string identifier of the popped page. If history only contains a single entry we noop.