igoui

Log | Files | Refs

commit 9406a9ae0247abf3ca83eb037887fe0e34cf6661
parent c4e53ea58a1d280c3d2a305352cea674b2bf49a5
Author: Thomas Vigouroux <me@vigoux.eu>
Date:   Fri, 26 Apr 2024 08:03:43 +0200

fix: correctly handle notes area

Diffstat:
Mmain.go | 36++++++++++++++++++++----------------
1 file changed, 20 insertions(+), 16 deletions(-)

diff --git a/main.go b/main.go @@ -28,26 +28,29 @@ import ( ) type App struct { - Node *sgf.Node + Node *sgf.Node Editor material.EditorStyle } func (g *App) SetNode(node *sgf.Node) { - // XXX: Maybe not the right place to do that if g.Node != nil { g.Node.SetValue("C", g.Editor.Editor.Text()) } - g.Node = node val, ok := node.GetValue("C") if ok { g.Editor.Editor.SetText(val) + } else { + g.Editor.Editor.SetText("") } } +// Draws the goban in the area +// Also handles navigation of the game tree func (g *App) LayoutGoban(gtx layout.Context) layout.Dimensions { size := min(gtx.Constraints.Max.X, gtx.Constraints.Max.Y) + const padding = 2 black := color.NRGBA{A: 0xFF} white := color.NRGBA{A: 0xFF, R: 0xFF, G: 0xFF, B: 0xFF} @@ -71,6 +74,7 @@ func (g *App) LayoutGoban(gtx layout.Context) layout.Dimensions { break } + var newnode *sgf.Node switch ev.(type) { case pointer.Event: { @@ -79,10 +83,12 @@ func (g *App) LayoutGoban(gtx layout.Context) layout.Dimensions { case pointer.Press: xpos := int(e.Position.X / offset) ypos := int(e.Position.Y / offset) - newnode, err := g.Node.Play(sgf.Point(xpos, ypos)) - if err == nil { - g.SetNode(newnode) + var err error + newnode, err = g.Node.Play(sgf.Point(xpos, ypos)) + if err != nil { + newnode = nil } + newnode.MakeMainLine() } } case key.Event: @@ -92,19 +98,16 @@ func (g *App) LayoutGoban(gtx layout.Context) layout.Dimensions { if e.State == key.Press { switch e.Name { case key.NameDownArrow: - child := g.Node.MainChild() - if child != nil { - g.SetNode(child) - } + newnode = g.Node.MainChild() case key.NameUpArrow: - parent := g.Node.Parent() - if parent != nil { - g.SetNode(parent) - } + newnode = g.Node.Parent() } } } } + if newnode != nil { + g.SetNode(newnode) + } } } @@ -138,7 +141,7 @@ func (g *App) LayoutGoban(gtx layout.Context) layout.Dimensions { scolor := board.State[x][y] fx := float32(x) fy := float32(y) - rect := image.Rect(int(fx*offset), int(fy*offset), int((fx+1)*offset), int((fy+1)*offset)) + rect := image.Rect(int(fx*offset+padding/2), int(fy*offset+padding/2), int((fx+1)*offset-padding/2), int((fy+1)*offset-padding/2)) elipse := clip.Ellipse(rect) var strokecolor color.NRGBA @@ -156,7 +159,7 @@ func (g *App) LayoutGoban(gtx layout.Context) layout.Dimensions { paint.FillShape(gtx.Ops, fillcolor, elipse.Op(gtx.Ops)) paint.FillShape(gtx.Ops, strokecolor, clip.Stroke{ Path: elipse.Path(gtx.Ops), - Width: 2, + Width: padding, }.Op()) } } @@ -215,6 +218,7 @@ func run(window *app.Window) error { func main() { go func() { window := new(app.Window) + window.Option(app.MinSize(unit.Dp(1000), unit.Dp(700))) err := run(window) if err != nil { log.Fatal(err)