Skip to content

Commit

Permalink
Update viewer to fyne/v2
Browse files Browse the repository at this point in the history
Signed-off-by: Glenn Lewis <[email protected]>
  • Loading branch information
gmlewis committed Nov 24, 2022
1 parent bc89813 commit 7cf4248
Show file tree
Hide file tree
Showing 3 changed files with 625 additions and 14 deletions.
31 changes: 17 additions & 14 deletions gerber/viewer/viewer.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,17 @@ import (
"image/color"
"log"
"math"
"os"
"regexp"
"strconv"
"sync"

"fyne.io/fyne"
"fyne.io/fyne/app"
"fyne.io/fyne/canvas"
"fyne.io/fyne/layout"
"fyne.io/fyne/widget"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/app"
"fyne.io/fyne/v2/canvas"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/layout"
"fyne.io/fyne/v2/widget"
"github.com/fogleman/gg"
"github.com/gmlewis/go-gerber/gerber"
)
Expand Down Expand Up @@ -149,7 +151,7 @@ func Gerber(g *gerber.Gerber, allLayersOn bool) {
c.SetMinSize(fyne.Size{Width: 800, Height: 800})
vc.canvasObj = c

layers := widget.NewVBox()
layers := container.NewVBox()
addCheck := func(index int, label string) {
if index >= 0 {
check := newMyCheck(vc, label, func(v bool) {
Expand All @@ -158,10 +160,10 @@ func Gerber(g *gerber.Gerber, allLayersOn bool) {
canvas.Refresh(vc.canvasObj)
})
check.SetChecked(vc.drawLayer[index])
layers.Append(widget.NewHBox(check, layout.NewSpacer()))
layers.Add(container.NewHBox(check, layout.NewSpacer()))
}
}
scroller := widget.NewVScrollContainer(layers)
scroller := container.NewVScroll(layers)
addCheck(vc.indexDrill, "Drill")
addCheck(vc.indexTopSilkscreen, "Top Silkscreen")
addCheck(vc.indexTopSolderMask, "Top Solder Mask")
Expand All @@ -173,10 +175,11 @@ func Gerber(g *gerber.Gerber, allLayersOn bool) {
addCheck(vc.indexBottomSolderMask, "Bottom Solder Mask")
addCheck(vc.indexBottomSilkscreen, "Bottom Silkscreen")
addCheck(vc.indexOutline, "Outline")
quit := widget.NewHBox(
quit := container.NewHBox(
widget.NewLabel("Use arrow keys to pan, +/- (or =/_) to zoom, q to quit."),
layout.NewSpacer(),
widget.NewButton("Quit", func() { a.Quit() }),
// a.Quit hangs. See: https://github.com/fyne-io/fyne/issues/2314
widget.NewButton("Quit", func() { os.Exit(0) }),
)

w := a.NewWindow("Gerber viewer")
Expand Down Expand Up @@ -219,13 +222,13 @@ func (vc *viewController) OnTypedKey(event *fyne.KeyEvent) {
// log.Printf("event=%#v", *event)
switch event.Name {
case "Up":
vc.pan(0, -vc.canvasObj.Size().Height/5)
vc.pan(0, int(-vc.canvasObj.Size().Height/5))
case "Down":
vc.pan(0, vc.canvasObj.Size().Height/5)
vc.pan(0, int(vc.canvasObj.Size().Height/5))
case "Left":
vc.pan(vc.canvasObj.Size().Width/5, 0)
vc.pan(int(vc.canvasObj.Size().Width/5), 0)
case "Right":
vc.pan(-vc.canvasObj.Size().Width/5, 0)
vc.pan(int(-vc.canvasObj.Size().Width/5), 0)
case "LeftShift", "RightShift", "LeftControl", "RightControl", "LeftAlt", "RightAlt": // ignored.
case "-", "_", "+", "=": // already handled by OnTypedRune.
case "q", "Q": // TODO: Switch this to Alt-q when available.
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.15

require (
fyne.io/fyne v1.4.2
fyne.io/fyne/v2 v2.2.4 // indirect
github.com/fogleman/gg v1.3.0
github.com/gmlewis/go-fonts v0.0.7
github.com/gmlewis/go3d v0.0.1
Expand Down
Loading

0 comments on commit 7cf4248

Please sign in to comment.