-
Notifications
You must be signed in to change notification settings - Fork 0
/
personalize.go
71 lines (62 loc) · 1.34 KB
/
personalize.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// SPDX-FileCopyrightText: 2023 Weston Schmidt <[email protected]>
// SPDX-License-Identifier: Apache-2.0
package main
import (
"image/color"
"time"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/widget"
"github.com/lusingander/colorpicker"
"github.com/schmidtw/muggo/mug"
)
type Personal struct {
m *mug.Mug
led *color.NRGBA
name string
nameWidget *widget.Entry
ledWidget colorpicker.PickerOpenWidget
c *fyne.Container
}
func NewPersonalize(m *mug.Mug, w fyne.Window) *Personal {
p := Personal{
m: m,
nameWidget: widget.NewEntry(),
}
size := p.nameWidget.MinSize()
p.nameWidget.SetPlaceHolder("________________")
p.nameWidget.Resize(
fyne.Size{
Height: size.Height,
Width: 200,
})
p.ledWidget = colorpicker.NewColorSelectModalRect(w,
fyne.Size{
Height: size.Height,
Width: size.Height,
},
color.Black)
return &p
}
func (p *Personal) Start() {
go func() {
for {
var err error
time.Sleep(1 * time.Second)
p.name, err = p.m.Name()
if err == nil {
p.nameWidget.SetText(p.name)
p.nameWidget.Refresh()
}
p.led, err = p.m.Led()
if err == nil {
p.ledWidget.SetColor(p.led)
p.ledWidget.Refresh()
}
}
}()
}
func (p *Personal) Layout() *fyne.Container {
p.c = container.NewPadded(p.ledWidget)
return p.c
}