package main import ( "log" "os" "gioui.org/app" "gioui.org/op" "gioui.org/text" "gioui.org/unit" "pad/internal/ui" ) func main() { go func() { w := new(app.Window) w.Option(app.Title("Pad")) w.Option(app.Size(unit.Dp(390), unit.Dp(844))) if err := run(w); err != nil { log.Fatal(err) } os.Exit(0) }() app.Main() } func run(w *app.Window) error { var ops op.Ops shaper := text.NewShaper() renderer := ui.New(ui.Theme{FontSize: 14}, shaper) // Channel for window configuration events (resize, orientation) configChan := make(chan ui.ConfigEvent) // Initial screen size screenWidth := unit.Dp(390) screenHeight := unit.Dp(844) // Compute initial elements elems := ui.EditorLayout(screenWidth, screenHeight) for { switch e := w.Event().(type) { case app.DestroyEvent: return e.Err case app.ConfigEvent: // Send config event to logic goroutine (here, the main goroutine) configChan <- ui.ConfigEvent{ Width: unit.Dp(e.Config.Size.X), Height: unit.Dp(e.Config.Size.Y), } case app.FrameEvent: // Process any pending config events select { case cfg := <-configChan: // Update screen size and recompute layout screenWidth = cfg.Width screenHeight = cfg.Height elems = ui.EditorLayout(screenWidth, screenHeight) default: // No config event, use existing elements } gtx := app.NewContext(&ops, e) renderer.Draw(gtx, elems) e.Frame(&ops) } } }