mirror of https://github.com/OrbTools/OrbBind
Massive generification work
parent
fef4d61b99
commit
0ec3f6cac7
@ -1,2 +1,2 @@
|
||||
Orbweaver Mapping utility for orbmap
|
||||
```go get github.com/Minizbot2012/orbbind```
|
||||
```go get github.com/OrbTools/orbbind```
|
@ -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
|
||||
}
|
@ -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
|
||||
}
|
@ -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 }
|
||||
}
|
@ -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
|
||||
}
|
Loading…
Reference in New Issue