| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244 |
- // auto-generated
- // **** THIS FILE IS AUTO-GENERATED, PLEASE DO NOT EDIT IT **** //
- package binding
- import (
- "sync/atomic"
- "fyne.io/fyne/v2"
- )
- const keyTypeMismatchError = "A previous preference binding exists with different type for key: "
- type prefBoundBool struct {
- base
- key string
- p fyne.Preferences
- cache atomic.Value // bool
- }
- // BindPreferenceBool returns a bindable bool value that is managed by the application preferences.
- // Changes to this value will be saved to application storage and when the app starts the previous values will be read.
- //
- // Since: 2.0
- func BindPreferenceBool(key string, p fyne.Preferences) Bool {
- binds := prefBinds.getBindings(p)
- if binds != nil {
- if listen := binds.getItem(key); listen != nil {
- if l, ok := listen.(Bool); ok {
- return l
- }
- fyne.LogError(keyTypeMismatchError+key, nil)
- }
- }
- listen := &prefBoundBool{key: key, p: p}
- binds = prefBinds.ensurePreferencesAttached(p)
- binds.setItem(key, listen)
- return listen
- }
- func (b *prefBoundBool) Get() (bool, error) {
- cache := b.p.Bool(b.key)
- b.cache.Store(cache)
- return cache, nil
- }
- func (b *prefBoundBool) Set(v bool) error {
- b.p.SetBool(b.key, v)
- b.lock.RLock()
- defer b.lock.RUnlock()
- b.trigger()
- return nil
- }
- func (b *prefBoundBool) checkForChange() {
- val := b.cache.Load()
- if val != nil {
- cache := val.(bool)
- if b.p.Bool(b.key) == cache {
- return
- }
- }
- b.trigger()
- }
- func (b *prefBoundBool) replaceProvider(p fyne.Preferences) {
- b.p = p
- }
- type prefBoundFloat struct {
- base
- key string
- p fyne.Preferences
- cache atomic.Value // float64
- }
- // BindPreferenceFloat returns a bindable float64 value that is managed by the application preferences.
- // Changes to this value will be saved to application storage and when the app starts the previous values will be read.
- //
- // Since: 2.0
- func BindPreferenceFloat(key string, p fyne.Preferences) Float {
- binds := prefBinds.getBindings(p)
- if binds != nil {
- if listen := binds.getItem(key); listen != nil {
- if l, ok := listen.(Float); ok {
- return l
- }
- fyne.LogError(keyTypeMismatchError+key, nil)
- }
- }
- listen := &prefBoundFloat{key: key, p: p}
- binds = prefBinds.ensurePreferencesAttached(p)
- binds.setItem(key, listen)
- return listen
- }
- func (b *prefBoundFloat) Get() (float64, error) {
- cache := b.p.Float(b.key)
- b.cache.Store(cache)
- return cache, nil
- }
- func (b *prefBoundFloat) Set(v float64) error {
- b.p.SetFloat(b.key, v)
- b.lock.RLock()
- defer b.lock.RUnlock()
- b.trigger()
- return nil
- }
- func (b *prefBoundFloat) checkForChange() {
- val := b.cache.Load()
- if val != nil {
- cache := val.(float64)
- if b.p.Float(b.key) == cache {
- return
- }
- }
- b.trigger()
- }
- func (b *prefBoundFloat) replaceProvider(p fyne.Preferences) {
- b.p = p
- }
- type prefBoundInt struct {
- base
- key string
- p fyne.Preferences
- cache atomic.Value // int
- }
- // BindPreferenceInt returns a bindable int value that is managed by the application preferences.
- // Changes to this value will be saved to application storage and when the app starts the previous values will be read.
- //
- // Since: 2.0
- func BindPreferenceInt(key string, p fyne.Preferences) Int {
- binds := prefBinds.getBindings(p)
- if binds != nil {
- if listen := binds.getItem(key); listen != nil {
- if l, ok := listen.(Int); ok {
- return l
- }
- fyne.LogError(keyTypeMismatchError+key, nil)
- }
- }
- listen := &prefBoundInt{key: key, p: p}
- binds = prefBinds.ensurePreferencesAttached(p)
- binds.setItem(key, listen)
- return listen
- }
- func (b *prefBoundInt) Get() (int, error) {
- cache := b.p.Int(b.key)
- b.cache.Store(cache)
- return cache, nil
- }
- func (b *prefBoundInt) Set(v int) error {
- b.p.SetInt(b.key, v)
- b.lock.RLock()
- defer b.lock.RUnlock()
- b.trigger()
- return nil
- }
- func (b *prefBoundInt) checkForChange() {
- val := b.cache.Load()
- if val != nil {
- cache := val.(int)
- if b.p.Int(b.key) == cache {
- return
- }
- }
- b.trigger()
- }
- func (b *prefBoundInt) replaceProvider(p fyne.Preferences) {
- b.p = p
- }
- type prefBoundString struct {
- base
- key string
- p fyne.Preferences
- cache atomic.Value // string
- }
- // BindPreferenceString returns a bindable string value that is managed by the application preferences.
- // Changes to this value will be saved to application storage and when the app starts the previous values will be read.
- //
- // Since: 2.0
- func BindPreferenceString(key string, p fyne.Preferences) String {
- binds := prefBinds.getBindings(p)
- if binds != nil {
- if listen := binds.getItem(key); listen != nil {
- if l, ok := listen.(String); ok {
- return l
- }
- fyne.LogError(keyTypeMismatchError+key, nil)
- }
- }
- listen := &prefBoundString{key: key, p: p}
- binds = prefBinds.ensurePreferencesAttached(p)
- binds.setItem(key, listen)
- return listen
- }
- func (b *prefBoundString) Get() (string, error) {
- cache := b.p.String(b.key)
- b.cache.Store(cache)
- return cache, nil
- }
- func (b *prefBoundString) Set(v string) error {
- b.p.SetString(b.key, v)
- b.lock.RLock()
- defer b.lock.RUnlock()
- b.trigger()
- return nil
- }
- func (b *prefBoundString) checkForChange() {
- val := b.cache.Load()
- if val != nil {
- cache := val.(string)
- if b.p.String(b.key) == cache {
- return
- }
- }
- b.trigger()
- }
- func (b *prefBoundString) replaceProvider(p fyne.Preferences) {
- b.p = p
- }
|