more settings dialog work
This commit is contained in:
@@ -2,6 +2,8 @@ package dialogs
|
||||
|
||||
import (
|
||||
"supersonic/backend"
|
||||
"supersonic/ui/widgets"
|
||||
"unicode"
|
||||
|
||||
"fyne.io/fyne/v2"
|
||||
"fyne.io/fyne/v2/container"
|
||||
@@ -30,10 +32,21 @@ func NewSettingsDialog(config *backend.Config) *SettingsDialog {
|
||||
|
||||
replayGainSelect := widget.NewSelect([]string{"None", "Album", "Track"}, nil)
|
||||
|
||||
percentEntry := widgets.NewTextRestrictedEntry(func(text string, r rune) bool {
|
||||
return unicode.IsDigit(r) && len(text) < 2
|
||||
})
|
||||
percentEntry.SetMinCharWidth(2)
|
||||
|
||||
tabs := container.NewAppTabs(
|
||||
container.NewTabItem("General", container.NewVBox(
|
||||
widget.NewRichText(&widget.TextSegment{Text: "Scrobbling", Style: boldStyle}),
|
||||
widget.NewCheckWithData("Send playback statistics to server", binding.BindBool(&config.Scrobbling.Enabled)))),
|
||||
widget.NewCheckWithData("Send playback statistics to server", binding.BindBool(&config.Scrobbling.Enabled)),
|
||||
container.NewHBox(
|
||||
widget.NewLabel("Scrobble when"),
|
||||
percentEntry,
|
||||
widget.NewLabel("percent of track is played"),
|
||||
),
|
||||
)),
|
||||
container.NewTabItem("Playback", container.NewVBox(
|
||||
widget.NewRichText(&widget.TextSegment{Text: "ReplayGain", Style: boldStyle}),
|
||||
container.New(layout.NewFormLayout(),
|
||||
@@ -41,7 +54,8 @@ func NewSettingsDialog(config *backend.Config) *SettingsDialog {
|
||||
widget.NewLabel("Prevent clipping"), widget.NewCheckWithData("", binding.BindBool(&config.ReplayGain.PreventClipping)),
|
||||
),
|
||||
widget.NewSeparator(),
|
||||
widget.NewCheckWithData("Audio exclusive mode", binding.BindBool(&config.LocalPlayback.AudioExclusive)))),
|
||||
widget.NewCheckWithData("Audio exclusive mode", binding.BindBool(&config.LocalPlayback.AudioExclusive)),
|
||||
)),
|
||||
)
|
||||
s.content = container.NewVBox(tabs, widget.NewSeparator(),
|
||||
container.NewHBox(layout.NewSpacer(), widget.NewButton("Close", func() {
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
package widgets
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"fyne.io/fyne/v2"
|
||||
"fyne.io/fyne/v2/theme"
|
||||
"fyne.io/fyne/v2/widget"
|
||||
)
|
||||
|
||||
type TextRestrictedEntry struct {
|
||||
widget.Entry
|
||||
|
||||
charAllowed func(string, rune) bool
|
||||
|
||||
minWidth float32
|
||||
}
|
||||
|
||||
func NewTextRestrictedEntry(charAllowed func(curText string, r rune) bool) *TextRestrictedEntry {
|
||||
e := &TextRestrictedEntry{charAllowed: charAllowed}
|
||||
e.ExtendBaseWidget(e)
|
||||
return e
|
||||
}
|
||||
|
||||
func (e *TextRestrictedEntry) TypedRune(r rune) {
|
||||
if e.charAllowed == nil || e.charAllowed(e.Text, r) {
|
||||
e.Entry.TypedRune(r)
|
||||
}
|
||||
}
|
||||
|
||||
func (e *TextRestrictedEntry) SetMinCharWidth(numChars int) {
|
||||
e.minWidth = theme.Padding()*2 + fyne.MeasureText(strings.Repeat("W", numChars),
|
||||
fyne.CurrentApp().Settings().Theme().Size(theme.SizeNameText), e.TextStyle).Width
|
||||
}
|
||||
|
||||
func (e *TextRestrictedEntry) MinSize() fyne.Size {
|
||||
if e.minWidth < 0.001 {
|
||||
return e.Entry.MinSize()
|
||||
}
|
||||
return fyne.NewSize(e.minWidth, e.Entry.MinSize().Height)
|
||||
}
|
||||
Reference in New Issue
Block a user