Skip to content

Giorouter is a package to handle multiple routes in Gioui easily. It provides a simple API to navigate through your app (Push, Pop, CanPop)

Notifications You must be signed in to change notification settings

bpingris/giorouter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Giorouter

Giorouter is package meant to simplify routing in a Gioui app.

It provides a simple API to use:

  • Push(route string)
  • Pop()
  • CanPop() bool `

Usage

type Home struct {
    Router *giorouter.Router
    click *widget.Clickable
}

func (h *Home) Layout(gtx layout.Context, th *material.Theme) {
    if h.click.Clicked() {
        h.Router.Push("about")
    }
    // Draw your page...
}

type About struct {
    Router *giorouter.Router
}

func (a *About) Layout(gtx layout.Context, th *material.Theme) {
    if a.click.Clicked() {
        a.Router.Pop()
    }
    // Draw your page...
}

func main() {
    th := material.NewTheme(gofont.Collection())
    router := giorouter.NewRouter(th)
    home := Home{Router: router}
    about := About{Router: router}

    router.SetRoutes(giorouter.Routes{
        "home": &home,
        "about": &about,
   }, "home")

    go func() {
        w := app.NewWindow()
        var ops op.Ops

        for {
            select {
            case e := <-w.Events():
                switch e := e.(type) {
                case system.FrameEvent:
                    gtx := layout.NewContext(&ops, e)
                    router.Layout(gtx) // Draw the current page
                    e.Frame(gtx.Ops)
                case system.DestroyEvent:
                    os.Exit(0)
                }
            case <-router.C:
                // Redraw the screen when the route is changing
                w.Invalidate()
           }
       }
       }()
    app.Main()
}

About

Giorouter is a package to handle multiple routes in Gioui easily. It provides a simple API to navigate through your app (Push, Pop, CanPop)

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages