client refactor
This commit is contained in:
@@ -3,38 +3,6 @@ package client
|
||||
/*
|
||||
Fyne-friendly latest-wins coalescing for canvas.NewRaster(draw func(w,h int) image.Image).
|
||||
|
||||
How to use (integration sketch):
|
||||
|
||||
type editor struct {
|
||||
w *world.World
|
||||
drawer world.PrimitiveDrawer // wraps gg.Context over a backing *image.RGBA
|
||||
raster *canvas.Raster
|
||||
|
||||
co *client.RasterCoalescer[world.RenderParams]
|
||||
}
|
||||
|
||||
func (e *editor) initCoalescer() {
|
||||
exec := client.FyneMainThreadExecutor{} // uses fyne.CurrentApp().Driver().RunOnMain
|
||||
e.co = client.NewRasterCoalescer(exec, e.raster, func(wPx, hPx int, p world.RenderParams) image.Image {
|
||||
// your existing draw pipeline:
|
||||
// 1) ensure viewport/margins inside p are consistent with wPx/hPx if needed
|
||||
// 2) call e.w.Render(e.drawer, p)
|
||||
// 3) get image from gg.Context, crop margins, return
|
||||
_ = e.w.Render(e.drawer, p)
|
||||
return e.drawerImageCropped() // your code
|
||||
})
|
||||
}
|
||||
|
||||
// Call from input handlers (pan/zoom/etc). Can be from any goroutine.
|
||||
func (e *editor) RefreshUI(p world.RenderParams) {
|
||||
e.co.Request(p) // schedules raster.Refresh() on UI thread
|
||||
}
|
||||
|
||||
// Raster draw callback:
|
||||
func (e *editor) draw(wPx, hPx int) image.Image {
|
||||
return e.co.Draw(wPx, hPx)
|
||||
}
|
||||
|
||||
Key property:
|
||||
- draw() renders at most once per invocation (never loops).
|
||||
- if new requests arrived while drawing, we schedule exactly one extra Refresh.
|
||||
|
||||
Reference in New Issue
Block a user