package main import ( "image/color" "os" "time" "gioui.org/app" "gioui.org/widget/material" ) type GlobalState struct { Window *app.Window Theme *material.Theme state WindowState } func ticker(window *app.Window) { t := time.NewTicker(time.Second) for range t.C { window.Invalidate() } } func run(window *app.Window, initialState WindowState) error { state := GlobalState{} theme := material.NewTheme() theme.Bg = color.NRGBA{A: 0xff} state.Theme = theme state.Window = window state.state = initialState for { e := window.Event() newState := state.state.Run(&state, e) if newState.NextState != nil { state.state = newState.NextState } if newState.ExitCode != nil { os.Exit(*newState.ExitCode) } // log.Debug().Any("size", e.Size).Msg("Redrawing") // // This graphics context is used for managing the rendering state. // gtx := app.NewContext(&ops, e) // paint.FillShape(gtx.Ops, theme.Bg, clip.Rect(image.Rect(0, 0, gtx.Constraints.Max.X, gtx.Constraints.Max.Y)).Op()) // // // // // Define an large label with an appropriate text: // log.Debug().Dur("d", t.Sub(e.Now)).Time("t", t).Send() // title := material.H1(theme, e.Now.Sub(t).Round(time.Second).String()) // // // // // Change the color of the label. // maroon := color.NRGBA{R: 0xff, G: 0xff, B: 0xff, A: 255} // title.Color = maroon // // // // // Change the position of the label. // title.Alignment = text.Middle // // // Draw the label to the graphics context. // title.Layout(gtx) // // Pass the drawing operations to the GPU. // e.Frame(&ops) } }