Received: from git.sr.ht (unknown [173.195.146.142]) by mail-b.sr.ht (Postfix) with ESMTPSA id 4FB47FF0AA for <~eliasnaur/gio-patches@lists.sr.ht>; Thu, 26 Nov 2020 18:25:39 +0000 (UTC) From: ~egonelbre Date: Thu, 26 Nov 2020 20:24:07 +0200 Subject: [PATCH giouiorg] include/files/architecture: bump gio Message-ID: <160641513899.19758.5209540724775822986-0@git.sr.ht> X-Mailer: git.sr.ht Reply-to: ~egonelbre To: ~eliasnaur/gio-patches@lists.sr.ht Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 From: Egon Elbre There have been significant changes to the API, update to the latest version. Signed-off-by: Egon Elbre --- go.mod | 2 +- go.sum | 2 + include/files/architecture/button.go | 29 ++++++++------- include/files/architecture/colorbox.go | 18 +++++---- include/files/architecture/draw.go | 43 +++++++++++++++------- include/files/architecture/layout.go | 2 +- include/files/architecture/split-visual.go | 2 +- 7 files changed, 59 insertions(+), 39 deletions(-) diff --git a/go.mod b/go.mod index f70b974..d98b624 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module gioui.org/website go 1.14 =20 require ( - gioui.org v0.0.0-20200809161702-a063febed977 + gioui.org v0.0.0-20201126101740-9b54892cc4e3 gioui.org/cmd v0.0.0-20200622185735-5bd0ecea5e43 gioui.org/example v0.0.0-20200809161702-a063febed977 github.com/gomarkdown/markdown v0.0.0-20190912180731-281270bc6d83 diff --git a/go.sum b/go.sum index 079ccec..fa3400b 100644 --- a/go.sum +++ b/go.sum @@ -4,6 +4,8 @@ gioui.org v0.0.0-20200622101735-5368743478e0/go.mod h1:jiUwif= N9cRl/zmco43aAqh0aV gioui.org v0.0.0-20200726090130-3b95e2918359/go.mod h1:jiUwifN9cRl/zmco43aAq= h0aV+s9GbhG13KcD+gEpkU=3D gioui.org v0.0.0-20200809161702-a063febed977 h1:uE7dUtCS7ig7ny1gaZPz8Y7S6q4x= 4HjjTnvvKE5AEI8=3D gioui.org v0.0.0-20200809161702-a063febed977/go.mod h1:jiUwifN9cRl/zmco43aAq= h0aV+s9GbhG13KcD+gEpkU=3D +gioui.org v0.0.0-20201126101740-9b54892cc4e3 h1:il7mOn2cEYfnu0oV+mgqZCtNAB3P= Ttpuohx14ZA2bM8=3D +gioui.org v0.0.0-20201126101740-9b54892cc4e3/go.mod h1:Y+uS7hHMvku1Q+ooaoq6f= YD5B2LGoT8JtFgvmYmRzTw=3D gioui.org/cmd v0.0.0-20200622185735-5bd0ecea5e43 h1:Wj8OoCIw06dNSSSPAAipnmcG= 7dbFn+7Et9IY37e1HBU=3D gioui.org/cmd v0.0.0-20200622185735-5bd0ecea5e43/go.mod h1:KrsGUGWoPetiRyuDm= Od/GTNCBFi2u4UbESTFXZ5YqXY=3D gioui.org/example v0.0.0-20200809161702-a063febed977 h1:89Tr+NjHVQXQOXMipo2p= 25AROFyAg/Icscg6v3+ByMY=3D diff --git a/include/files/architecture/button.go b/include/files/architectur= e/button.go index b9b5a40..41abe54 100644 --- a/include/files/architecture/button.go +++ b/include/files/architecture/button.go @@ -6,11 +6,11 @@ import ( "image" "image/color" =20 - "gioui.org/f32" "gioui.org/io/event" "gioui.org/io/pointer" "gioui.org/layout" "gioui.org/op" + "gioui.org/op/clip" "gioui.org/op/paint" ) =20 @@ -20,8 +20,7 @@ var pressed =3D false =20 func doButton(ops *op.Ops, q event.Queue) { // Make sure we don=EF=BF=BD=EF=BF=BD=EF=BF=BDt pollute the graphics contex= t. - stack :=3D op.Push(ops) - defer stack.Pop() + defer op.Push(ops).Pop() =20 // Process events that arrived between the last frame and this one. for _, ev :=3D range q.Events(tag) { @@ -43,14 +42,15 @@ func doButton(ops *op.Ops, q event.Queue) { Types: pointer.Press | pointer.Release, }.Add(ops) =20 - var c color.RGBA + clip.Rect{Max: image.Pt(100, 100)}.Add(ops) + var c color.NRGBA if pressed { - c =3D color.RGBA{R: 0xFF, A: 0xFF} + c =3D color.NRGBA{R: 0xFF, A: 0xFF} } else { - c =3D color.RGBA{G: 0xFF, A: 0xFF} + c =3D color.NRGBA{G: 0xFF, A: 0xFF} } paint.ColorOp{Color: c}.Add(ops) - paint.PaintOp{Rect: f32.Rect(0, 0, 100, 100)}.Add(ops) + paint.PaintOp{}.Add(ops) } =20 // END LOWLEVEL OMIT @@ -67,17 +67,18 @@ type ButtonVisual struct { } =20 func (b *ButtonVisual) Layout(gtx layout.Context) layout.Dimensions { - col :=3D color.RGBA{R: 0x80, A: 0xFF} + col :=3D color.NRGBA{R: 0x80, A: 0xFF} if b.pressed { - col =3D color.RGBA{G: 0x80, A: 0xFF} + col =3D color.NRGBA{G: 0x80, A: 0xFF} } return drawSquare(gtx.Ops, col) } =20 -func drawSquare(ops *op.Ops, color color.RGBA) layout.Dimensions { - square :=3D f32.Rect(0, 0, 100, 100) +func drawSquare(ops *op.Ops, color color.NRGBA) layout.Dimensions { + defer op.Push(ops).Pop() + clip.Rect{Max: image.Pt(100, 100)}.Add(ops) paint.ColorOp{Color: color}.Add(ops) - paint.PaintOp{Rect: square}.Add(ops) + paint.PaintOp{}.Add(ops) return layout.Dimensions{Size: image.Pt(100, 100)} } =20 @@ -118,9 +119,9 @@ func (b *Button) Layout(gtx layout.Context) layout.Dimens= ions { }.Add(gtx.Ops) =20 // Draw the button. - col :=3D color.RGBA{R: 0x80, A: 0xFF} + col :=3D color.NRGBA{R: 0x80, A: 0xFF} if b.pressed { - col =3D color.RGBA{G: 0x80, A: 0xFF} + col =3D color.NRGBA{G: 0x80, A: 0xFF} } return drawSquare(gtx.Ops, col) } diff --git a/include/files/architecture/colorbox.go b/include/files/architect= ure/colorbox.go index 8111c7e..5f3de36 100644 --- a/include/files/architecture/colorbox.go +++ b/include/files/architecture/colorbox.go @@ -6,8 +6,9 @@ import ( "image" "image/color" =20 - "gioui.org/f32" "gioui.org/layout" + "gioui.org/op" + "gioui.org/op/clip" "gioui.org/op/paint" ) =20 @@ -15,17 +16,18 @@ import ( =20 // Test colors. var ( - background =3D color.RGBA{R: 0xC0, G: 0xC0, B: 0xC0, A: 0xFF} - red =3D color.RGBA{R: 0xC0, G: 0x40, B: 0x40, A: 0xFF} - green =3D color.RGBA{R: 0x40, G: 0xC0, B: 0x40, A: 0xFF} - blue =3D color.RGBA{R: 0x40, G: 0x40, B: 0xC0, A: 0xFF} + background =3D color.NRGBA{R: 0xC0, G: 0xC0, B: 0xC0, A: 0xFF} + red =3D color.NRGBA{R: 0xC0, G: 0x40, B: 0x40, A: 0xFF} + green =3D color.NRGBA{R: 0x40, G: 0xC0, B: 0x40, A: 0xFF} + blue =3D color.NRGBA{R: 0x40, G: 0x40, B: 0xC0, A: 0xFF} ) =20 // ColorBox creates a widget with the specified dimensions and color. -func ColorBox(gtx layout.Context, size image.Point, color color.RGBA) layout= .Dimensions { - bounds :=3D f32.Rect(0, 0, float32(size.X), float32(size.Y)) +func ColorBox(gtx layout.Context, size image.Point, color color.NRGBA) layou= t.Dimensions { + defer op.Push(gtx.Ops).Pop() + clip.Rect{Max: size}.Add(gtx.Ops) paint.ColorOp{Color: color}.Add(gtx.Ops) - paint.PaintOp{Rect: bounds}.Add(gtx.Ops) + paint.PaintOp{}.Add(gtx.Ops) return layout.Dimensions{Size: size} } =20 diff --git a/include/files/architecture/draw.go b/include/files/architecture/= draw.go index d7c0ce6..a724073 100644 --- a/include/files/architecture/draw.go +++ b/include/files/architecture/draw.go @@ -18,7 +18,7 @@ import ( =20 // START OPERATIONS OMIT func addColorOperation(ops *op.Ops) { - red :=3D color.RGBA{R: 0xFF, A: 0xFF} + red :=3D color.NRGBA{R: 0xFF, A: 0xFF} paint.ColorOp{Color: red}.Add(ops) } =20 @@ -26,8 +26,9 @@ func addColorOperation(ops *op.Ops) { =20 // START DRAWING OMIT func drawRedRect(ops *op.Ops) { - paint.ColorOp{Color: color.RGBA{R: 0x80, A: 0xFF}}.Add(ops) - paint.PaintOp{Rect: f32.Rect(0, 0, 100, 100)}.Add(ops) + clip.Rect{Max: image.Pt(100, 100)}.Add(ops) + paint.ColorOp{Color: color.NRGBA{R: 0x80, A: 0xFF}}.Add(ops) + paint.PaintOp{}.Add(ops) } =20 // END DRAWING OMIT @@ -58,7 +59,7 @@ func redTriangle(ops *op.Ops) { path.Quad(f32.Pt(0, 90), f32.Pt(50, 100)) path.Line(f32.Pt(-100, 0)) path.Line(f32.Pt(50, -100)) - path.End().Add(ops) + path.Outline().Add(ops) drawRedRect(ops) } =20 @@ -79,12 +80,18 @@ func redButtonBackgroundStack(ops *op.Ops) { // START DRAWORDER OMIT func drawOverlappingRectangles(ops *op.Ops) { // Draw a red rectangle. - paint.ColorOp{Color: color.RGBA{R: 0x80, A: 0xFF}}.Add(ops) - paint.PaintOp{Rect: f32.Rect(0, 0, 100, 50)}.Add(ops) + stack :=3D op.Push(ops) + clip.Rect{Max: image.Pt(100, 50)}.Add(ops) + paint.ColorOp{Color: color.NRGBA{R: 0x80, A: 0xFF}}.Add(ops) + paint.PaintOp{}.Add(ops) + stack.Pop() =20 // Draw a green rectangle. - paint.ColorOp{Color: color.RGBA{G: 0x80, A: 0xFF}}.Add(ops) - paint.PaintOp{Rect: f32.Rect(0, 0, 50, 100)}.Add(ops) + stack =3D op.Push(ops) + clip.Rect{Max: image.Pt(50, 100)}.Add(ops) + paint.ColorOp{Color: color.NRGBA{G: 0x80, A: 0xFF}}.Add(ops) + paint.PaintOp{}.Add(ops) + stack.Pop() } =20 // END DRAWORDER OMIT @@ -126,9 +133,12 @@ func drawProgressBar(ops *op.Ops, now time.Time) { progress =3D 1 } =20 - paint.ColorOp{Color: color.RGBA{G: 0x80, A: 0xFF}}.Add(ops) + defer op.Push(ops).Pop() width :=3D 200 * float32(progress) - paint.PaintOp{Rect: f32.Rect(0, 0, width, 20)}.Add(ops) + clip.Rect{Max: image.Pt(int(width), 20)}.Add(ops) + paint.ColorOp{Color: color.NRGBA{R: 0x80, A: 0xFF}}.Add(ops) + paint.ColorOp{Color: color.NRGBA{G: 0x80, A: 0xFF}}.Add(ops) + paint.PaintOp{}.Add(ops) } =20 // END ANIMATION OMIT @@ -138,8 +148,12 @@ func drawWithCache(ops *op.Ops) { // Save the operations in an independent ops value (the cache). cache :=3D new(op.Ops) macro :=3D op.Record(cache) - paint.ColorOp{Color: color.RGBA{G: 0x80, A: 0xFF}}.Add(cache) - paint.PaintOp{Rect: f32.Rect(0, 0, 100, 100)}.Add(cache) + + stack :=3D op.Push(cache) + clip.Rect{Max: image.Pt(100, 100)}.Add(cache) + paint.ColorOp{Color: color.NRGBA{G: 0x80, A: 0xFF}}.Add(cache) + paint.PaintOp{}.Add(cache) + stack.Pop() call :=3D macro.Stop() =20 // Draw the operations from the cache. @@ -166,7 +180,7 @@ func drawImageInternal(ops *op.Ops) { var err error exampleImage, err =3D createExampleImage() if err !=3D nil { - exampleImage =3D image.NewUniform(color.RGBA{R: 0xFF, A: 0xFF}) + exampleImage =3D image.NewUniform(color.NRGBA{R: 0xFF, A: 0xFF}) } } drawImage(ops, exampleImage) @@ -176,7 +190,8 @@ func drawImageInternal(ops *op.Ops) { func drawImage(ops *op.Ops, img image.Image) { imageOp :=3D paint.NewImageOp(img) imageOp.Add(ops) - paint.PaintOp{Rect: f32.Rect(0, 0, 100, 100)}.Add(ops) + op.Affine(f32.Affine2D{}.Scale(f32.Pt(0, 0), f32.Pt(4, 4))) + paint.PaintOp{}.Add(ops) } =20 // END IMAGE OMIT diff --git a/include/files/architecture/layout.go b/include/files/architectur= e/layout.go index ef3424a..0a27a32 100644 --- a/include/files/architecture/layout.go +++ b/include/files/architecture/layout.go @@ -44,7 +44,7 @@ var list =3D layout.List{} =20 func listing(gtx layout.Context) layout.Dimensions { return list.Layout(gtx, 100, func(gtx layout.Context, i int) layout.Dimensi= ons { - col :=3D color.RGBA{R: byte(i * 20), G: 0x20, B: 0x20, A: 0xFF} + col :=3D color.NRGBA{R: byte(i * 20), G: 0x20, B: 0x20, A: 0xFF} return ColorBox(gtx, image.Pt(20, 100), col) }) } diff --git a/include/files/architecture/split-visual.go b/include/files/archi= tecture/split-visual.go index b7f88e9..4ca7086 100644 --- a/include/files/architecture/split-visual.go +++ b/include/files/architecture/split-visual.go @@ -19,7 +19,7 @@ func exampleSplitVisual(gtx layout.Context, th *material.Th= eme) layout.Dimension }) } =20 -func FillWithLabel(gtx layout.Context, th *material.Theme, text string, back= groundColor color.RGBA) layout.Dimensions { +func FillWithLabel(gtx layout.Context, th *material.Theme, text string, back= groundColor color.NRGBA) layout.Dimensions { ColorBox(gtx, gtx.Constraints.Max, backgroundColor) return layout.Center.Layout(gtx, material.H3(th, text).Layout) } --=20 2.26.2