• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

fyne-io / fyne / 12875576469

20 Jan 2025 08:59PM UTC coverage: 59.035% (+0.004%) from 59.031%
12875576469

push

github

web-flow
Merge pull request #5408 from Jacalz/binding-cleanup-generic

145 of 163 new or added lines in 3 files covered. (88.96%)

31 existing lines in 3 files now uncovered.

24776 of 41968 relevant lines covered (59.04%)

679.18 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

92.86
/data/binding/preference.go
1
package binding
2

3
import "fyne.io/fyne/v2"
4

5
const keyTypeMismatchError = "A previous preference binding exists with different type for key: "
6

7
type prefBoundBool struct {
8
        prefBoundBase[bool]
9
}
10

11
// BindPreferenceBool returns a bindable bool value that is managed by the application preferences.
12
// Changes to this value will be saved to application storage and when the app starts the previous values will be read.
13
//
14
// Since: 2.0
15
func BindPreferenceBool(key string, p fyne.Preferences) Bool {
1✔
16
        if found, ok := lookupExistingBinding[bool](key, p); ok {
1✔
NEW
17
                return found
×
UNCOV
18
        }
×
19

20
        listen := &prefBoundBool{}
1✔
21
        listen.setKey(key)
1✔
22
        listen.replaceProvider(p)
1✔
23
        binds := prefBinds.ensurePreferencesAttached(p)
1✔
24
        binds.Store(key, listen)
1✔
25
        return listen
1✔
26
}
27

28
func (b *prefBoundBool) replaceProvider(p fyne.Preferences) {
5✔
29
        b.get = p.Bool
5✔
30
        b.set = p.SetBool
5✔
31
}
5✔
32

33
type prefBoundFloat struct {
34
        prefBoundBase[float64]
35
}
36

37
// BindPreferenceFloat returns a bindable float64 value that is managed by the application preferences.
38
// Changes to this value will be saved to application storage and when the app starts the previous values will be read.
39
//
40
// Since: 2.0
41
func BindPreferenceFloat(key string, p fyne.Preferences) Float {
1✔
42
        if found, ok := lookupExistingBinding[float64](key, p); ok {
1✔
NEW
43
                return found
×
UNCOV
44
        }
×
45

46
        listen := &prefBoundFloat{}
1✔
47
        listen.setKey(key)
1✔
48
        listen.replaceProvider(p)
1✔
49
        binds := prefBinds.ensurePreferencesAttached(p)
1✔
50
        binds.Store(key, listen)
1✔
51
        return listen
1✔
52
}
53

54
func (b *prefBoundFloat) replaceProvider(p fyne.Preferences) {
4✔
55
        b.get = p.Float
4✔
56
        b.set = p.SetFloat
4✔
57
}
4✔
58

59
type prefBoundInt struct {
60
        prefBoundBase[int]
61
}
62

63
// BindPreferenceInt returns a bindable int value that is managed by the application preferences.
64
// Changes to this value will be saved to application storage and when the app starts the previous values will be read.
65
//
66
// Since: 2.0
67
func BindPreferenceInt(key string, p fyne.Preferences) Int {
101✔
68
        if found, ok := lookupExistingBinding[int](key, p); ok {
200✔
69
                return found
99✔
70
        }
99✔
71

72
        listen := &prefBoundInt{}
2✔
73
        listen.setKey(key)
2✔
74
        listen.replaceProvider(p)
2✔
75
        binds := prefBinds.ensurePreferencesAttached(p)
2✔
76
        binds.Store(key, listen)
2✔
77
        return listen
2✔
78
}
79

80
func (b *prefBoundInt) replaceProvider(p fyne.Preferences) {
9✔
81
        b.get = p.Int
9✔
82
        b.set = p.SetInt
9✔
83
}
9✔
84

85
type prefBoundString struct {
86
        prefBoundBase[string]
87
}
88

89
// BindPreferenceString returns a bindable string value that is managed by the application preferences.
90
// Changes to this value will be saved to application storage and when the app starts the previous values will be read.
91
//
92
// Since: 2.0
93
func BindPreferenceString(key string, p fyne.Preferences) String {
5✔
94
        if found, ok := lookupExistingBinding[string](key, p); ok {
8✔
95
                return found
3✔
96
        }
3✔
97

98
        listen := &prefBoundString{}
2✔
99
        listen.setKey(key)
2✔
100
        listen.replaceProvider(p)
2✔
101
        binds := prefBinds.ensurePreferencesAttached(p)
2✔
102
        binds.Store(key, listen)
2✔
103
        return listen
2✔
104
}
105

106
func (b *prefBoundString) replaceProvider(p fyne.Preferences) {
3✔
107
        b.get = p.String
3✔
108
        b.set = p.SetString
3✔
109
}
3✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc