igoui

Log | Files | Refs

commit 414d6c95c04974df0c75c1bb8283ec55f1888e95
parent 988286bee002dc6ff74378e57a626298bd8ac5ad
Author: Thomas Vigouroux <me@vigoux.eu>
Date:   Thu, 25 Apr 2024 16:37:24 +0200

feat: use flex layout for goban and rest

Diffstat:
Mmain.go | 30++++++++++++++++++++++++++----
1 file changed, 26 insertions(+), 4 deletions(-)

diff --git a/main.go b/main.go @@ -113,8 +113,24 @@ func (g *Goban) Layout(gtx layout.Context) layout.Dimensions { } } } - // paint.PaintOp{}.Add(gtx.Ops) - return layout.Dimensions{Size: gtx.Constraints.Max} + + return layout.Dimensions{Size: image.Pt(size, size)} +} + +// Test colors. +var ( + background = color.NRGBA{R: 0xC0, G: 0xC0, B: 0xC0, A: 0xFF} + red = color.NRGBA{R: 0xC0, G: 0x40, B: 0x40, A: 0xFF} + green = color.NRGBA{R: 0x40, G: 0xC0, B: 0x40, A: 0xFF} + blue = color.NRGBA{R: 0x40, G: 0x40, B: 0xC0, A: 0xFF} +) + +// ColorBox creates a widget with the specified dimensions and color. +func ColorBox(gtx layout.Context, size image.Point, color color.NRGBA) layout.Dimensions { + defer clip.Rect{Max: size}.Push(gtx.Ops).Pop() + paint.ColorOp{Color: color}.Add(gtx.Ops) + paint.PaintOp{}.Add(gtx.Ops) + return layout.Dimensions{Size: size} } func run(window *app.Window) error { @@ -133,8 +149,14 @@ func run(window *app.Window) error { // This graphics context is used for managing the rendering state. gtx := app.NewContext(&ops, e) - // goban.Layout(gtx) - layout.UniformInset(unit.Dp(30)).Layout(gtx, goban.Layout) + layout.Flex{}.Layout(gtx, + layout.Rigid(func(gtx layout.Context) layout.Dimensions { + return layout.UniformInset(unit.Dp(30)).Layout(gtx, goban.Layout) + }), + layout.Flexed(0.5, func(gtx layout.Context) layout.Dimensions { + return ColorBox(gtx, gtx.Constraints.Min, blue) + }), + ) // Pass the drawing operations to the GPU. e.Frame(gtx.Ops)