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

60 lines
1.4 KiB
Go
Raw Normal View History

2021-05-03 19:00:08 +00:00
package bind
import (
"fyne.io/fyne/v2"
2021-05-12 02:08:10 +00:00
"fyne.io/fyne/v2/container"
2021-05-03 19:00:08 +00:00
"fyne.io/fyne/v2/layout"
"fyne.io/fyne/v2/widget"
"github.com/OrbTools/OrbBind/keys"
)
//BindingInfo Genral data to use in a channel
type BindingInfo struct {
Bindid int
Bound uint16
}
//Page Binding UI
type Page struct {
dev map[string]fyne.CanvasObject
Bind BindingInfo
window fyne.Window
}
//TypeKey event on key
func (bp *Page) TypeKey(e *fyne.KeyEvent) {
2021-05-12 02:08:10 +00:00
kp := keys.FyneToKeymap(e)
bp.Bind.Bound = kp.Evdev
bp.dev["BL"].(*widget.Label).SetText(kp.Code)
2021-05-03 19:00:08 +00:00
}
func (bp *Page) createGrid() *fyne.Container {
2021-05-12 02:08:10 +00:00
cont := container.New(layout.NewGridLayoutWithColumns(4))
cont.Add(widget.NewButton("Clear", func() {
2021-05-03 19:00:08 +00:00
bp.Bind.Bound = 0x0
2021-05-12 02:08:10 +00:00
bp.dev["BL"].(*widget.Label).SetText(keys.KeyFromEvdev(bp.Bind.Bound).Code)
2021-05-03 19:00:08 +00:00
}))
cont.Add(widget.NewButton("TAB", func() {
bp.TypeKey(&fyne.KeyEvent{Name: fyne.KeyTab})
}))
2021-05-03 19:00:08 +00:00
return cont
}
//Create the binding page popup
func (bp *Page) Create(bid string) fyne.CanvasObject {
bp.dev = make(map[string]fyne.CanvasObject)
2021-05-12 02:08:10 +00:00
bp.dev["BL"] = widget.NewLabel(keys.KeyFromEvdev(bp.Bind.Bound).Code)
2021-05-03 19:00:08 +00:00
pop := container.NewVBox(bp.dev["BL"], bp.createGrid())
bp.window.Canvas().SetOnTypedKey(bp.TypeKey)
return pop
}
//NewBindPage Create a new bind popup
func NewBindPage(bid int, w fyne.Window, def uint16) *Page {
p := new(Page)
p.window = w
p.Bind.Bindid = bid
p.Bind.Bound = def
return p
}