4 gio version bump up notes

gio version bump up notes#

When you check some repos on github that using gio, quite often they are using old versions of gio, when you want to run them with latest gio or you want to use some of their code, you may meet problem because of the gio version bump up. Here are some problems that I met and hope these could be useful for our future gio version bump up.

for w.Events() -> for { switch e := w.NextEvent().(type) { case ... } }

gofmt -w -r "system.DestroyEvent -> app.DestroyEvent" .
gofmt -w -r "system.FrameEvent -> app.FrameEvent" .
gofmt -w -r "layout.NewContext -> app.NewContext" .
gofmt -w -r "op.InvalidateOp{}.Add(gtx.Ops) -> gtx.Execute(op.InvalidateCmd{})" .
goimports -w .

more to do:

- w.Events() ... -> w.NextEvent().(type)
- pointer.Rect(...).Add() -> clip.Rect(...).Push()
- gofont.Register() -> th.Shaper = text.NewShaper(text.WithCollection(gofont.Regular()))
- gtx := layout.NewContext(w.Queue()) -> gtx := layout.NewContext(&ops, e)
- th.H6( -> return material.H6(th, 
- [unit.Value -> unit.Dp or Sp](https://github.com/gioui/gio/commit/3d374913420204ff764171e21a25cb910fccccb1)
- unit.Px -> unit.Dp
- gtx.Dimensions = layout.Dimensions{ -> return layout.Dimensions{
- f32.Rectangle -> image.Rectangle, f32.Point -> image.Point
- op.Offset(*h.pointerAt).Add(gtx.Ops) -> op.Affine(f32.Affine2D{}.Offset(*h.pointerAt)).Add(gtx.Ops)
- color.RGBA -> color.NRGBA
- clip.Rect -> clip.RRect
- NW: borderRadius[1] -> NW: 1
- func() -> func(gtx layout.Context) layout.Dimensions
- material.NewIcon -> widget.NewIcon
- th.IconButton(icon) -> material.IconButton(th, icon, "descriptString")
- gtx *layout.Context -> gtx layout.Context
- gtx.Contrains.Height.Max -> gtx.Contrains.Max.Y
- gtx.Contrains.Width.Max -> gtx.Contrains.Max.X
- pointer.InputOp{key: ...} -> pointer.InputOp{Tag: ...}
- e.Type -> e.Kind
The pointer.InputOp kinds are replaced with filters at your event handling:
	for {
	e, ok := gtx.Event(pointer.Filter{Target: pressed, Kinds: pointer.Press | pointer.Move})
	if !ok { break }
	}


gtx.Events 
	for _, gtxEvent := range gtx.Events(0) { }

pointer.InputOp{}

key.FocusOp{}

key.InputOp{}
case app.FrameEvent:
       ....
        kbpointer(e.Queue) // handle key and pointer events
        e.Frame(....)

kbpointer(e.Source)
...
// handle kb and pointer
func kbpointer(q input.Source) {
    for {
         e, ok := q.Event(
             key.Filter{},
             pointer.Filter{Target: pressed, Kinds: pointer.Press | pointer.Move | pointer.Release},
         )
         if !ok { break }
         switch e := e.(type) {
         case key.Event:
               // handle kb
         case pointer.Event:
              // handle pointer
         }
    }
}

ref:

op.InvalidateOp{}.Add(gtx.Ops) -> gtx.Execute(op.InvalidateCmd{})
https://github.com/gioui/gio/commit/c515b7804e13fdab7b0cdb96f51def5f6c966730

pointer.InputOp{} -> event.InputOp(ops, c) ), then
for _, evt := range q.Events(c) -> for _, evt := range q.Events(c, pointer.Filter{Kinds: … })
https://github.com/gioui/gio/commit/ef8171b971fb35dbcf28a706b05ab1f1e81f99f4
(update: now event.InputOp is event.Op)
(update: now q.Events changed to gtx.Event(key.Filter{}, pointer.Filter{},))

Further practices#

» Further practices