~eliasnaur/gio-patches

gio-x: outlay: updated Table to work with latest versions of Gio v1 PROPOSED

~pierrec
~pierrec: 1
 outlay: updated Table to work with latest versions of Gio

 1 files changed, 104 insertions(+), 0 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~eliasnaur/gio-patches/patches/22448/mbox | git am -3
Learn more about email & git
View this thread in the archives

[PATCH gio-x] outlay: updated Table to work with latest versions of Gio Export this patch

~pierrec
From: Pierre Curto <pierre.curto@gmail.com>

Signed-off-by: pierre <pierre.curto@gmail.com>
---
 cmd/test/main.go | 104 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 104 insertions(+)
 create mode 100644 cmd/test/main.go

diff --git a/cmd/test/main.go b/cmd/test/main.go
new file mode 100644
index 0000000..93e3e63
--- /dev/null
+++ b/cmd/test/main.go
@@ -0,0 +1,104 @@
// SPDX-License-Identifier: Unlicense OR MIT

package main

// A simple Gio program. See https://gioui.org for more information.

import (
	"image"
	"image/color"
	"log"
	"os"

	"gioui.org/app"
	"gioui.org/io/system"
	"gioui.org/layout"
	"gioui.org/op"
	"gioui.org/op/clip"
	"gioui.org/op/paint"
	"gioui.org/text"
	"gioui.org/unit"
	"gioui.org/widget/material"
	"gioui.org/x/component"

	"gioui.org/font/gofont"
)

func main() {
	go func() {
		w := app.NewWindow()
		if err := loop(w); err != nil {
			log.Fatal(err)
		}
		os.Exit(0)
	}()
	app.Main()
}

type (
	C = layout.Context
	D = layout.Dimensions
)

func HorizHandle(gtx C) D {
	rect := image.Rectangle{
		Max: image.Point{
			X: gtx.Px(unit.Dp(4)),
			Y: gtx.Constraints.Max.Y,
		},
	}
	paint.FillShape(gtx.Ops, color.NRGBA{A: 200}, clip.RRect{
		Rect: layout.FRect(rect),
		SW:   float32(rect.Max.X / 2),
		NW:   float32(rect.Max.X / 2),
		SE:   float32(rect.Max.X / 2),
		NE:   float32(rect.Max.X / 2),
	}.Op(gtx.Ops))
	return D{Size: rect.Max}
}

func VertHandle(gtx C) D {
	rect := image.Rectangle{
		Max: image.Point{
			Y: gtx.Px(unit.Dp(4)),
			X: gtx.Constraints.Max.X,
		},
	}
	paint.FillShape(gtx.Ops, color.NRGBA{A: 200}, clip.RRect{
		Rect: layout.FRect(rect),
		SW:   float32(rect.Max.Y / 2),
		NW:   float32(rect.Max.Y / 2),
		SE:   float32(rect.Max.Y / 2),
		NE:   float32(rect.Max.Y / 2),
	}.Op(gtx.Ops))
	return D{Size: rect.Max}
}

func loop(w *app.Window) error {
	th := material.NewTheme(gofont.Collection())
	r := component.Resize{
		Ratio: 0.5,
	}
	rv := component.Resize{
		Axis:  layout.Vertical,
		Ratio: 0.5,
	}
	var ops op.Ops
	for {
		e := <-w.Events()
		switch e := e.(type) {
		case system.DestroyEvent:
			return e.Err
		case system.FrameEvent:
			gtx := layout.NewContext(&ops, e)
			l := material.H1(th, "Hello, Gio")
			maroon := color.NRGBA{R: 127, G: 0, B: 0, A: 255}
			l.Color = maroon
			l.Alignment = text.Middle
			r.Layout(gtx, func(gtx C) D {
				return rv.Layout(gtx, l.Layout, l.Layout, VertHandle)
			}, l.Layout, HorizHandle)
			e.Frame(gtx.Ops)
		}
	}
}
-- 
2.30.2