router

package
v0.0.0-...-f613d12 Latest Latest
Warning

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

Go to latest
Published: May 3, 2024 License: MIT, Unlicense Imports: 1 Imported by: 0

Documentation

Overview

Package router helps manage the content of Gio windows by routing between multiple content "pages".

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type C

type C = layout.Context

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

func (r *Router) Add(name string, p Page)

Add page to the pages collection to make it available to the UI. Does not affect history.

func (*Router) Current

func (r *Router) Current() Page

Current returns the tip of the page history. Nil if history is empty.

func (*Router) GetName

func (r *Router) GetName(p Page) string

GetName of the page as stored in the router, if any. Uses pointer comparison to identify the page.

func (*Router) Jump

func (r *Router) Jump(ii int)

Jump to the page at index ii.

func (*Router) Layout

func (r *Router) Layout(gtx C) D

Layout the current page.

func (*Router) Navigated

func (r *Router) Navigated() (name string, p Page)

Navigated returns the latest navigation event and clears it. This allows the parent to respond to navigation changes.

func (*Router) Pop

func (r *Router) Pop() string

Pop the page history to navigate backwards, returning the string identifier of the popped page. If history only contains a single entry we noop.

func (*Router) Push

func (r *Router) Push(page string)

Push the named page onto the history stack.

func (*Router) Update

func (r *Router) Update(data any) bool

Update broadcasts the update all available pages.

Jump to

Keyboard shortcuts

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