Skip to content

Commit 11b9960

Browse files
committed
[TASK] First Beta Release
1 parent 4eab02a commit 11b9960

File tree

19 files changed

+1154
-133
lines changed

19 files changed

+1154
-133
lines changed

CustomWidget/TappableSelect.go

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
package CustomWidget
2+
3+
import (
4+
"fyne.io/fyne/v2"
5+
"fyne.io/fyne/v2/theme"
6+
"fyne.io/fyne/v2/widget"
7+
"sync"
8+
)
9+
10+
const defaultPlaceHolder string = "(Select one)"
11+
12+
type TappableSelect struct {
13+
widget.Select
14+
popUp *widget.PopUpMenu
15+
UpdateBeforeOpenFunc func()
16+
LastTappedPointEvent *fyne.PointEvent
17+
18+
impl fyne.Widget
19+
propertyLock sync.RWMutex
20+
}
21+
22+
var _ fyne.Widget = (*TappableSelect)(nil)
23+
var _ fyne.Tappable = (*TappableSelect)(nil)
24+
25+
// NewSelect creates a new select widget with the set list of options and changes handler
26+
func NewSelect(options []string, changed func(string)) *TappableSelect {
27+
s := &TappableSelect{}
28+
s.OnChanged = changed
29+
s.Options = options
30+
s.PlaceHolder = defaultPlaceHolder
31+
32+
s.ExtendBaseWidget(s)
33+
return s
34+
}
35+
func (s *TappableSelect) super() fyne.Widget {
36+
return s
37+
}
38+
39+
func (s *TappableSelect) updateSelected(text string) {
40+
s.Selected = text
41+
42+
if s.OnChanged != nil {
43+
s.OnChanged(s.Selected)
44+
}
45+
46+
s.Refresh()
47+
}
48+
49+
func (s *TappableSelect) popUpPos() fyne.Position {
50+
buttonPos := fyne.CurrentApp().Driver().AbsolutePositionForObject(s.super())
51+
return buttonPos.Add(fyne.NewPos(0, s.Size().Height-theme.InputBorderSize()))
52+
}
53+
func (s *TappableSelect) showPopUp() {
54+
items := make([]*fyne.MenuItem, len(s.Options))
55+
for i := range s.Options {
56+
text := s.Options[i] // capture
57+
items[i] = fyne.NewMenuItem(text, func() {
58+
s.updateSelected(text)
59+
s.popUp = nil
60+
})
61+
}
62+
63+
c := fyne.CurrentApp().Driver().CanvasForObject(s.super())
64+
s.popUp = widget.NewPopUpMenu(fyne.NewMenu("", items...), c)
65+
//s.popUp.alignment = s.Alignment
66+
s.popUp.ShowAtPosition(s.popUpPos())
67+
s.popUp.Resize(fyne.NewSize(s.Size().Width, s.popUp.MinSize().Height))
68+
}
69+
70+
func (s *TappableSelect) GetPopup() *widget.PopUpMenu {
71+
return s.popUp
72+
}
73+
74+
func (s *TappableSelect) ShopPopup() {
75+
if s.Disabled() {
76+
return
77+
}
78+
79+
s.Refresh()
80+
81+
s.showPopUp()
82+
}
83+
84+
func (s *TappableSelect) Tapped(ev *fyne.PointEvent) {
85+
s.LastTappedPointEvent = ev
86+
s.UpdateBeforeOpenFunc()
87+
}

CustomWidget/TextValueSelect.go

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
package CustomWidget
2+
3+
import (
4+
"fyne.io/fyne/v2"
5+
"fyne.io/fyne/v2/widget"
6+
)
7+
8+
type TextValueSelect struct {
9+
widget.Select
10+
Name string
11+
Options []TextValueOption
12+
OnChanged func(TextValueOption) `json:"-"`
13+
}
14+
15+
type TextValueOption struct {
16+
// Text sets the text of the select.
17+
Text string
18+
// Value sets the value of the select.
19+
Value string
20+
}
21+
22+
func (s *TextValueOption) String() string {
23+
return s.Value
24+
}
25+
26+
// NewTextValueSelect Creates a new TextValue Select widget
27+
// Set defaultIndex to -1 if no default should be selected
28+
func NewTextValueSelect(name string, options []TextValueOption, changed func(TextValueOption), defaultIndex int) *TextValueSelect {
29+
s := &TextValueSelect{}
30+
s.Name = name
31+
s.OnChanged = changed
32+
s.Select.OnChanged = func(text string) {
33+
s.updateSelected(text)
34+
}
35+
s.Options = options
36+
s.PlaceHolder = defaultPlaceHolder
37+
38+
if defaultIndex > -1 && defaultIndex <= len(s.Options) {
39+
s.Selected = s.Options[defaultIndex].Text
40+
}
41+
42+
s.ExtendBaseWidget(s)
43+
return s
44+
}
45+
46+
// ClearSelected clears the current option of the select widget. After
47+
// clearing the current option, the Select widget's PlaceHolder will
48+
// be displayed.
49+
func (s *TextValueSelect) ClearSelected() {
50+
s.updateSelected("")
51+
}
52+
53+
func (s *TextValueSelect) GetName() string {
54+
return s.Name
55+
}
56+
57+
// SelectedIndex returns the index value of the currently selected item in Options list.
58+
// It will return -1 if there is no selection.
59+
func (s *TextValueSelect) SelectedIndex() int {
60+
for i, option := range s.Options {
61+
if s.Selected == option.Text {
62+
return i
63+
}
64+
}
65+
return -1 // not selected/found
66+
}
67+
68+
func (s *TextValueSelect) GetSelected() *TextValueOption {
69+
selectedIndex := s.SelectedIndex()
70+
if selectedIndex == -1 {
71+
return nil
72+
}
73+
return &s.Options[s.SelectedIndex()]
74+
}
75+
76+
// SetSelected sets the current option of the select widget
77+
func (s *TextValueSelect) SetSelected(value string) {
78+
for _, option := range s.Options {
79+
if value == option.Value {
80+
s.updateSelected(option.Text)
81+
}
82+
}
83+
}
84+
85+
// SetSelectedIndex will set the Selected option from the value in Options list at index position.
86+
func (s *TextValueSelect) SetSelectedIndex(index int) {
87+
if index < 0 || index >= len(s.Options) {
88+
return
89+
}
90+
91+
s.updateSelected(s.Options[index].Text)
92+
}
93+
94+
func (s *TextValueSelect) updateSelected(text string) {
95+
var lastSelected TextValueOption
96+
for i := 0; i < len(s.Options); i++ {
97+
if s.Options[i].Text == text {
98+
s.Selected = s.Options[i].Text
99+
lastSelected = s.Options[i]
100+
}
101+
}
102+
103+
if s.OnChanged != nil {
104+
s.OnChanged(lastSelected)
105+
}
106+
107+
s.Refresh()
108+
}
109+
110+
// Tapped is called when a pointer tapped event is captured and triggers any tap handler
111+
func (s *TextValueSelect) Tapped(tapEvent *fyne.PointEvent) {
112+
// copy options over to base widget
113+
var items []string
114+
for i := range s.Options {
115+
items = append(items, s.Options[i].Text)
116+
}
117+
s.Select.Options = items
118+
119+
s.Select.Tapped(tapEvent)
120+
121+
}

FyneApp.toml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
Website = "https://github.com/Sharrnah/whispering"
2-
3-
[Details]
4-
Icon = "app-icon.png"
5-
Name = "Whispering Tiger"
6-
ID = "tiger.whispering"
7-
Version = "1.0.0"
8-
Build = 1
1+
Website = "https://github.com/Sharrnah/whispering"
2+
3+
[Details]
4+
Icon = "app-icon.png"
5+
Name = "Whispering Tiger"
6+
ID = "tiger.whispering"
7+
Version = "1.0.0"
8+
Build = 7

Pages/Advanced.go

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
)
1212

1313
func CreateAdvancedWindow() fyne.CanvasObject {
14-
Settings.Form = Settings.BuildSettingsForm(nil).(*widget.Form)
14+
Settings.Form = Settings.BuildSettingsForm(nil, Settings.Config.SettingsFilename).(*widget.Form)
1515

1616
settingsTabContent := container.NewVScroll(Settings.Form)
1717

@@ -24,16 +24,19 @@ func CreateAdvancedWindow() fyne.CanvasObject {
2424

2525
// Log logText updater thread
2626
go func(writer io.Writer, reader io.Reader) {
27-
buffer := make([]byte, 1024)
28-
for {
29-
n, err := reader.Read(buffer) // Read from the pipe
30-
if err != nil {
31-
panic(err)
27+
if reader != nil {
28+
buffer := make([]byte, 1024)
29+
for {
30+
n, err := reader.Read(buffer) // Read from the pipe
31+
if err != nil {
32+
//panic(err)
33+
logText.AppendText(err.Error())
34+
}
35+
logText.AppendText(string(buffer[0:n]))
36+
logTabContent.ScrollToBottom()
3237
}
33-
logText.AppendText(string(buffer[0:n]))
34-
logTabContent.ScrollToBottom()
3538
}
36-
}(RuntimeBackend.WriterBackend, RuntimeBackend.ReaderBackend)
39+
}(RuntimeBackend.BackendsList[0].WriterBackend, RuntimeBackend.BackendsList[0].ReaderBackend)
3740

3841
tabs := container.NewAppTabs(
3942
container.NewTabItem("Log", logTabContent),
@@ -43,7 +46,7 @@ func CreateAdvancedWindow() fyne.CanvasObject {
4346

4447
tabs.OnSelected = func(tab *container.TabItem) {
4548
if tab.Text == "Settings" {
46-
Settings.BuildSettingsForm(nil)
49+
Settings.BuildSettingsForm(nil, Settings.Config.SettingsFilename)
4750
tab.Content.(*container.Scroll).Content = Settings.Form
4851
}
4952
}

0 commit comments

Comments
 (0)