- Fix render.go: replace broken material.Label with shaper-based text rendering (LayoutString + Shape + glyph iteration) per Gio's paintGlyph - Fix render.go: only apply clip rects at container boundaries; leaf elements have zero-size regions that were clipping all text out - Fix render.go: call r.drawElement recursively for container children so nested containers work and clips are applied correctly - Fix render.go: add drawLineText/drawLine helpers matching Gio's paintGlyph offset calculation (x + first.X, y + first.Y) - Fix element.go: Button.Draw now uses r.drawText instead of duplicate broken material.Label code; Label defaults to black when color is unset - Fix state.go: container children use relative coordinates instead of mixed screen-space/container-relative positions - Fix main.go: ConfigEvent carries raw pixel dimensions only; ScaleEvent carries scale only; layout is computed once per frame using both, eliminating the infinite Invalidate() loop
76 lines
1.5 KiB
Go
76 lines
1.5 KiB
Go
package main
|
|
|
|
import (
|
|
"log"
|
|
"os"
|
|
"sync"
|
|
|
|
"gioui.org/app"
|
|
"gioui.org/op"
|
|
"gioui.org/text"
|
|
"gioui.org/unit"
|
|
"gioui.org/font/gofont"
|
|
|
|
"pad/internal/editor"
|
|
"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(text.WithCollection(gofont.Collection()))
|
|
logic := editor.NewLogic()
|
|
renderer := ui.New(ui.Theme{FontSize: 14}, shaper, logic.State())
|
|
var mu sync.Mutex
|
|
var elems []ui.Element
|
|
go logic.Run()
|
|
go frameReceiver(w, &mu, &elems, logic.FrameChan())
|
|
|
|
for {
|
|
switch e := w.Event().(type) {
|
|
case app.DestroyEvent:
|
|
return e.Err
|
|
case app.ConfigEvent:
|
|
// ConfigEvent: raw pixel dimensions only.
|
|
logic.ConfigChan() <- editor.ConfigEvent{
|
|
PixelWidth: e.Config.Size.X,
|
|
PixelHeight: e.Config.Size.Y,
|
|
}
|
|
case app.FrameEvent:
|
|
gtx := app.NewContext(&ops, e)
|
|
newScale := gtx.Metric.PxPerDp
|
|
curScale := logic.State().Scale()
|
|
if newScale != curScale {
|
|
logic.ConfigChan() <- editor.ScaleEvent{newScale}
|
|
}
|
|
mu.Lock()
|
|
currentElems := elems
|
|
renderer.Draw(gtx, currentElems)
|
|
e.Frame(&ops)
|
|
mu.Unlock()
|
|
}
|
|
}
|
|
}
|
|
|
|
func frameReceiver(w *app.Window, mu *sync.Mutex, elems *[]ui.Element, frameChan <-chan []ui.Element) {
|
|
for {
|
|
frame := <-frameChan
|
|
mu.Lock()
|
|
*elems = frame
|
|
w.Invalidate()
|
|
mu.Unlock()
|
|
}
|
|
}
|