2
0
mirror of https://github.com/OrbTools/OrbBind synced 2024-10-31 03:20:26 +00:00

Massive generification work

This commit is contained in:
Minizbot2012 2021-02-09 17:13:44 -08:00
parent 9804803369
commit a407f873c6
8 changed files with 81 additions and 149 deletions

View File

@ -1,2 +1,2 @@
Orbweaver Mapping utility for orbmap
```go get github.com/Minizbot2012/orbbind```
```go get github.com/OrbTools/orbbind```

2
go.mod
View File

@ -4,7 +4,7 @@ go 1.15
require (
fyne.io/fyne v1.4.3
github.com/OrbTools/OrbCommon v0.0.0-20210209215542-e5d03278f0d5
github.com/OrbTools/OrbCommon v0.0.0-20210209235647-67bb6503d1dd
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20201108214237-06ea97f0c265 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/srwiley/oksvg v0.0.0-20210209000435-a757b9cbd472 // indirect

14
go.sum
View File

@ -1,10 +1,16 @@
fyne.io/fyne v1.4.3 h1:356CnXCiYrrfaLGsB7qLK3c6ktzyh8WR05v/2RBu51I=
fyne.io/fyne v1.4.3/go.mod h1:8kiPBNSDmuplxs9WnKCkaWYqbcXFy0DeAzwa6PBO9Z8=
github.com/Kodeworks/golang-image-ico v0.0.0-20141118225523-73f0f4cfade9/go.mod h1:7uhhqiBaR4CpN0k9rMjOtjpcfGd6DG2m04zQxKnWQ0I=
github.com/OrbTools/OrbCommon v0.0.0-20210209212230-c28d897d2760 h1:2eOcDeOxaRpMd0OIt3jsSl7EjPSzu8FYsGOqM+ilOgE=
github.com/OrbTools/OrbCommon v0.0.0-20210209212230-c28d897d2760/go.mod h1:ErdpS2Y/8Ik89IDNsH+yaOWo/XcKzf4riEBfPG3xK+o=
github.com/OrbTools/OrbCommon v0.0.0-20210209215542-e5d03278f0d5 h1:W48w6MC69gxrqfR2xPUjaPyB7SWOAP6szppMvIKwauI=
github.com/OrbTools/OrbCommon v0.0.0-20210209215542-e5d03278f0d5/go.mod h1:ErdpS2Y/8Ik89IDNsH+yaOWo/XcKzf4riEBfPG3xK+o=
github.com/OrbTools/OrbCommon v0.0.0-20210209224029-73cec4826e73 h1:9bKK432OLKXWfkG4cVZA+LNp8U+jVmc132tuwCU4bQI=
github.com/OrbTools/OrbCommon v0.0.0-20210209224029-73cec4826e73/go.mod h1:ErdpS2Y/8Ik89IDNsH+yaOWo/XcKzf4riEBfPG3xK+o=
github.com/OrbTools/OrbCommon v0.0.0-20210209233138-8623fe5b8a96 h1:YyCVdiz5Yk1dyE7tdV6XATIC3aGHPiPowYrNd5I92cA=
github.com/OrbTools/OrbCommon v0.0.0-20210209233138-8623fe5b8a96/go.mod h1:ErdpS2Y/8Ik89IDNsH+yaOWo/XcKzf4riEBfPG3xK+o=
github.com/OrbTools/OrbCommon v0.0.0-20210209234440-f9da0895ed81 h1:nrS6Fl/cAhYdCk8SAceFGDt1yE/wrErTu+uUo2PQYYU=
github.com/OrbTools/OrbCommon v0.0.0-20210209234440-f9da0895ed81/go.mod h1:ErdpS2Y/8Ik89IDNsH+yaOWo/XcKzf4riEBfPG3xK+o=
github.com/OrbTools/OrbCommon v0.0.0-20210209235147-bc7589e327b4 h1:5OgIJHZvLkZR9v27cas4KrJy19TGQSowXoi09OAiFoE=
github.com/OrbTools/OrbCommon v0.0.0-20210209235147-bc7589e327b4/go.mod h1:ErdpS2Y/8Ik89IDNsH+yaOWo/XcKzf4riEBfPG3xK+o=
github.com/OrbTools/OrbCommon v0.0.0-20210209235647-67bb6503d1dd h1:G9vKM/+GnnbkE3l08LdAahlhhJa4gUk4Qa/dCBJqLCg=
github.com/OrbTools/OrbCommon v0.0.0-20210209235647-67bb6503d1dd/go.mod h1:ErdpS2Y/8Ik89IDNsH+yaOWo/XcKzf4riEBfPG3xK+o=
github.com/akavel/rsrc v0.8.0/go.mod h1:uLoCtb9J+EyAqh+26kdrTgmzRBFPGOolLWKpdxkKq+c=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=

View File

@ -1,13 +1,12 @@
package main
import (
"reflect"
"fyne.io/fyne"
"fyne.io/fyne/app"
"fyne.io/fyne/dialog"
"fyne.io/fyne/widget"
"github.com/OrbTools/OrbBind/ui/baseui"
"github.com/OrbTools/OrbBind/ui/mainpage"
"github.com/OrbTools/OrbBind/ui/sidepage"
"github.com/OrbTools/OrbBind/ui/mui"
"github.com/OrbTools/OrbCommon/devices/orbweaver"
)
@ -17,10 +16,11 @@ func main() {
window.SetMaster()
omap := new(orbweaver.PKM)
pages := make(map[string]baseui.PageWithBindings)
pages["main"] = mainpage.NewMainPage(window, omap)
pages["side"] = sidepage.NewSidePage(window, omap)
tabs := widget.NewTabContainer(pages["main"].Create(), pages["side"].Create())
//pages := make(map[string]baseui.PageWithBindings)
//pages["main"] = mainpage.NewMainPage(window, omap)
//pages["side"] = sidepage.NewSidePage(window, omap)
tabs, setter := mui.Generate(orbweaver.GUI, window, reflect.ValueOf(omap))
//tabs := widget.NewTabContainer(pages["main"].Create(), pages["side"].Create())
tabs.Resize(fyne.NewSize(640, 480))
main := tabs
window.Resize(fyne.NewSize(640, 500))
@ -41,9 +41,9 @@ func main() {
return
}
if reader != nil {
omap = orbweaver.LoadPKMKeymap(reader)
pages["main"].SetBindings(omap)
pages["side"].SetBindings(omap)
setter(reflect.ValueOf(orbweaver.LoadPKMKeymap(reader)))
// pages["main"].SetBindings(omap)
// pages["side"].SetBindings(omap)
}
}, window)
})))

View File

@ -1,23 +0,0 @@
package baseui
import (
"fyne.io/fyne"
"fyne.io/fyne/widget"
"github.com/OrbTools/OrbCommon/devices/orbweaver"
)
//BasicPage creates a very basic Page
type BasicPage interface {
Create() *widget.TabItem
}
//PageWithBindings defines a page with bindings
type PageWithBindings interface {
BasicPage
SetBindings(*orbweaver.PKM)
}
//DialogPage is a dialog popup
type DialogPage interface {
Create() *fyne.CanvasObject
}

View File

@ -1,58 +0,0 @@
package mainpage
import (
"strconv"
"fyne.io/fyne"
"fyne.io/fyne/dialog"
"fyne.io/fyne/layout"
"fyne.io/fyne/widget"
"github.com/OrbTools/OrbBind/ui/bind"
"github.com/OrbTools/OrbCommon/devices/orbweaver"
)
//Page is a basic page
type Page struct {
binds *orbweaver.PKM
dev map[string]fyne.CanvasObject
parent fyne.Window
}
func (mp *Page) createButtons() {
for i := 0; i < 4; i++ {
for j := 0; j < 5; j++ {
id := (j + i*5 + 1)
mp.dev["B"+strconv.Itoa(id)] = widget.NewButton(strconv.Itoa(id), func() {
popup := bind.NewBindPage(id, mp.parent, mp.binds.MIP[id-1])
dialog.ShowCustomConfirm("Binding", "Set", "Cancel", popup.Create(string(id)), func(b bool) {
if b {
mp.binds.MIP[popup.Bind.Bindid-1] = popup.Bind.Bound
}
}, mp.parent)
})
mp.dev["V"].(*fyne.Container).AddObject(mp.dev["B"+strconv.Itoa(id)])
}
}
}
//SetBindings Sets the binding Map
func (mp *Page) SetBindings(o *orbweaver.PKM) {
mp.binds = o
}
//Create Creates the main binding page
func (mp *Page) Create() *widget.TabItem {
mp.dev = make(map[string]fyne.CanvasObject)
layout := layout.NewGridLayout(5)
mp.dev["V"] = fyne.NewContainerWithLayout(layout)
mp.createButtons()
return widget.NewTabItem("Main Bindings", mp.dev["V"])
}
//NewMainPage Creates a new main page
func NewMainPage(parent fyne.Window, pkm *orbweaver.PKM) *Page {
mp := new(Page)
mp.binds = pkm
mp.parent = parent
return mp
}

58
ui/mui/generator.go Normal file
View File

@ -0,0 +1,58 @@
package mui
import (
"math"
"reflect"
"fyne.io/fyne"
"fyne.io/fyne/dialog"
"fyne.io/fyne/layout"
"fyne.io/fyne/widget"
"github.com/OrbTools/OrbBind/ui/bind"
"github.com/OrbTools/OrbCommon/gui"
)
//Generate creates a GUI from definition
func Generate(ui *gui.GUI, window fyne.Window, KBS reflect.Value) (*widget.TabContainer, func(reflect.Value)) {
keybind := KBS
tui := widget.NewTabContainer()
for _, page := range ui.Pages[:] {
var cont *fyne.Container
pg := page
switch page.Type {
case gui.PGrid:
{
cont = fyne.NewContainer()
cont.Layout = layout.NewGridLayout(int(math.Ceil(math.Sqrt(float64(len(page.Keys))))))
}
default:
{
cont = fyne.NewContainer()
cont.Layout = layout.NewGridLayout(int(math.Ceil(math.Sqrt(float64(len(page.Keys))))))
}
}
for _, key := range page.Keys[:] {
ky := key
btn := widget.NewButton(ky.KeyName, func() {
bp := bind.NewBindPage(ky.KeyID, window, uint16(keybind.Elem().FieldByName(pg.Hive).Index(ky.KeyID).Uint()))
cont := bp.Create(ky.KeyName)
ok := func(ok bool) {
kb := keybind.Elem()
if ok {
field := kb.FieldByName(pg.Hive)
if field.Kind() == reflect.Array {
field.Index(ky.KeyID).SetUint(uint64(bp.Bind.Bound))
println(field.Index(ky.KeyID).Uint())
println(ky.KeyID)
}
}
}
dialog.ShowCustomConfirm("Bind", "Save", "Cancel", cont, ok, window)
})
cont.AddObject(btn)
}
ti := widget.NewTabItem(page.Name, cont)
tui.Append(ti)
}
return tui, func(v reflect.Value) { keybind = v }
}

View File

@ -1,51 +0,0 @@
package sidepage
import (
"strconv"
"fyne.io/fyne"
"fyne.io/fyne/dialog"
"fyne.io/fyne/layout"
"fyne.io/fyne/widget"
"github.com/OrbTools/OrbBind/ui/bind"
"github.com/OrbTools/OrbCommon/devices/orbweaver"
)
//Page Overweave side button configs
type Page struct {
binds *orbweaver.PKM
dev map[string]fyne.CanvasObject
parent fyne.Window
}
//SetBindings Loads bindings from SIP
func (p *Page) SetBindings(o *orbweaver.PKM) {
p.binds = o
}
//Create Creates the page
func (p *Page) Create() *widget.TabItem {
p.dev = make(map[string]fyne.CanvasObject)
strs := []string{"Upper Button", "Dpad Up", "Dpad Right", "Dpad Down", "Dpad Left", "Lower Button"}
for j := 0; j < 6; j++ {
id := j + 1
p.dev["B"+strconv.Itoa(id)] = widget.NewButton(strs[j], func() {
popup := bind.NewBindPage(id, p.parent, p.binds.SIP[id-1])
dialog.ShowCustomConfirm("Binding", "Set", "Cancel", popup.Create(string(id)), func(b bool) {
if b {
p.binds.SIP[popup.Bind.Bindid-1] = popup.Bind.Bound
}
}, p.parent)
})
}
cont := fyne.NewContainerWithLayout(layout.NewBorderLayout(p.dev["B2"], p.dev["B4"], p.dev["B5"], p.dev["B3"]), p.dev["B2"], p.dev["B4"], p.dev["B5"], p.dev["B3"], widget.NewVBox(p.dev["B1"], p.dev["B6"]))
return widget.NewTabItem("Side Config", cont)
}
//NewSidePage Creates a new side configuration page
func NewSidePage(parent fyne.Window, pkm *orbweaver.PKM) *Page {
p := new(Page)
p.binds = pkm
p.parent = parent
return p
}