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

fyne-io / fyne / 13156141055

05 Feb 2025 11:14AM UTC coverage: 62.563% (-0.06%) from 62.619%
13156141055

Pull #5496

github

dweymouth
address code style comments
Pull Request #5496: Make table scrolling and resizing more efficient

38 of 38 new or added lines in 1 file covered. (100.0%)

266 existing lines in 11 files now uncovered.

24755 of 39568 relevant lines covered (62.56%)

841.09 hits per line

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

81.42
/data/binding/convert.go
1
// auto-generated
2
// **** THIS FILE IS AUTO-GENERATED, PLEASE DO NOT EDIT IT **** //
3

4
package binding
5

6
import (
7
        "fmt"
8

9
        "fyne.io/fyne/v2"
10
)
11

12
func internalFloatToInt(val float64) (int, error) {
13
        return int(val), nil
14
}
15

1✔
16
func internalIntToFloat(val int) (float64, error) {
1✔
17
        return float64(val), nil
1✔
18
}
19

20
type stringFromBool struct {
21
        base
22

23
        format string
24

1✔
25
        from Bool
1✔
26
}
1✔
27

28
// BoolToString creates a binding that connects a Bool data item to a String.
29
// Changes to the Bool will be pushed to the String and setting the string will parse and set the
30
// Bool if the parse was successful.
31
//
32
// Since: 2.0
33
func BoolToString(v Bool) String {
1✔
34
        str := &stringFromBool{from: v}
1✔
35
        v.AddListener(str)
1✔
36
        return str
37
}
38

39
// BoolToStringWithFormat creates a binding that connects a Bool data item to a String and is
40
// presented using the specified format. Changes to the Bool will be pushed to the String and setting
41
// the string will parse and set the Bool if the string matches the format and its parse was successful.
42
//
1✔
43
// Since: 2.0
1✔
44
func BoolToStringWithFormat(v Bool, format string) String {
1✔
45
        if format == "%t" { // Same as not using custom formatting.
46
                return BoolToString(v)
47
        }
48

49
        str := &stringFromBool{from: v, format: format}
1✔
50
        v.AddListener(str)
1✔
51
        return str
1✔
52
}
1✔
53

1✔
54
func (s *stringFromBool) Get() (string, error) {
55
        val, err := s.from.Get()
56
        if err != nil {
57
                return "", err
58
        }
1✔
59

1✔
60
        if s.format != "" {
1✔
61
                return fmt.Sprintf(s.format, val), nil
1✔
62
        }
1✔
63

64
        return formatBool(val), nil
65
}
66

67
func (s *stringFromBool) Set(str string) error {
68
        var val bool
69
        if s.format != "" {
1✔
70
                safe := stripFormatPrecision(s.format)
1✔
71
                n, err := fmt.Sscanf(str, safe+" ", &val) // " " denotes match to end of string
1✔
72
                if err != nil {
73
                        return err
74
                }
75
                if n != 1 {
76
                        return errParseFailed
77
                }
78
        } else {
1✔
79
                new, err := parseBool(str)
1✔
80
                if err != nil {
1✔
81
                        return err
82
                }
83
                val = new
84
        }
85

86
        old, err := s.from.Get()
87
        if err != nil {
1✔
88
                return err
1✔
89
        }
1✔
90
        if val == old {
91
                return nil
92
        }
93
        if err = s.from.Set(val); err != nil {
94
                return err
95
        }
96

1✔
97
        queueItem(s.DataChanged)
1✔
98
        return nil
1✔
99
}
1✔
100

1✔
101
func (s *stringFromBool) DataChanged() {
102
        s.trigger()
103
}
104

105
type stringFromFloat struct {
106
        base
107

108
        format string
1✔
109

1✔
UNCOV
110
        from Float
×
UNCOV
111
}
×
112

113
// FloatToString creates a binding that connects a Float data item to a String.
1✔
114
// Changes to the Float will be pushed to the String and setting the string will parse and set the
1✔
115
// Float if the parse was successful.
1✔
116
//
117
// Since: 2.0
118
func FloatToString(v Float) String {
119
        str := &stringFromFloat{from: v}
120
        v.AddListener(str)
121
        return str
122
}
123

1✔
124
// FloatToStringWithFormat creates a binding that connects a Float data item to a String and is
1✔
125
// presented using the specified format. Changes to the Float will be pushed to the String and setting
1✔
126
// the string will parse and set the Float if the string matches the format and its parse was successful.
1✔
127
//
1✔
128
// Since: 2.0
129
func FloatToStringWithFormat(v Float, format string) String {
130
        if format == "%f" { // Same as not using custom formatting.
131
                return FloatToString(v)
132
        }
133

134
        str := &stringFromFloat{from: v, format: format}
135
        v.AddListener(str)
1✔
136
        return str
1✔
UNCOV
137
}
×
UNCOV
138

×
139
func (s *stringFromFloat) Get() (string, error) {
140
        val, err := s.from.Get()
1✔
141
        if err != nil {
1✔
142
                return "", err
1✔
143
        }
144

145
        if s.format != "" {
146
                return fmt.Sprintf(s.format, val), nil
147
        }
148

149
        return formatFloat(val), nil
150
}
1✔
151

1✔
152
func (s *stringFromFloat) Set(str string) error {
1✔
153
        var val float64
1✔
154
        if s.format != "" {
1✔
155
                safe := stripFormatPrecision(s.format)
156
                n, err := fmt.Sscanf(str, safe+" ", &val) // " " denotes match to end of string
157
                if err != nil {
158
                        return err
159
                }
160
                if n != 1 {
161
                        return errParseFailed
162
                }
1✔
163
        } else {
1✔
UNCOV
164
                new, err := parseFloat(str)
×
UNCOV
165
                if err != nil {
×
166
                        return err
167
                }
1✔
168
                val = new
1✔
169
        }
1✔
170

171
        old, err := s.from.Get()
172
        if err != nil {
173
                return err
174
        }
175
        if val == old {
176
                return nil
177
        }
1✔
178
        if err = s.from.Set(val); err != nil {
1✔
179
                return err
1✔
180
        }
1✔
181

1✔
182
        queueItem(s.DataChanged)
183
        return nil
7✔
184
}
7✔
185

7✔
186
func (s *stringFromFloat) DataChanged() {
7✔
187
        s.trigger()
7✔
188
}
189

3✔
190
type intToFloat struct {
6✔
191
        base
192
        from Int
193
}
3✔
194

3✔
195
// IntToFloat creates a binding that connects an Int data item to a Float.
6✔
196
//
3✔
197
// Since: 2.5
3✔
198
func IntToFloat(val Int) Float {
199
        v := &intToFloat{from: val}
3✔
200
        val.AddListener(v)
201
        return v
202
}
3✔
203

6✔
204
func (s *intToFloat) Get() (float64, error) {
205
        val, err := s.from.Get()
206
        if err != nil {
207
                return 0.0, err
208
        }
209
        return internalIntToFloat(val)
210
}
211

212
func (s *intToFloat) Set(val float64) error {
213
        i, err := internalFloatToInt(val)
214
        if err != nil {
215
                return err
216
        }
217
        old, err := s.from.Get()
218
        if i == old {
14✔
219
                return nil
14✔
220
        }
14✔
UNCOV
221
        if err != nil {
×
222
                return err
×
223
        }
224
        if err = s.from.Set(i); err != nil {
20✔
225
                return err
6✔
226
        }
6✔
227

228
        queueItem(s.DataChanged)
8✔
229
        return nil
230
}
231

13✔
232
func (s *intToFloat) DataChanged() {
13✔
233
        s.trigger()
19✔
234
}
6✔
235

6✔
236
type intFromFloat struct {
9✔
237
        base
3✔
238
        from Float
3✔
239
}
3✔
UNCOV
240

×
UNCOV
241
// FloatToInt creates a binding that connects a Float data item to an Int.
×
242
//
7✔
243
// Since: 2.5
7✔
244
func FloatToInt(v Float) Int {
10✔
245
        i := &intFromFloat{from: v}
3✔
246
        v.AddListener(i)
3✔
247
        return i
4✔
248
}
249

250
func (s *intFromFloat) Get() (int, error) {
7✔
251
        val, err := s.from.Get()
7✔
UNCOV
252
        if err != nil {
×
253
                return 0, err
×
254
        }
8✔
255
        return internalFloatToInt(val)
1✔
256
}
1✔
257

6✔
UNCOV
258
func (s *intFromFloat) Set(v int) error {
×
UNCOV
259
        val, err := internalIntToFloat(v)
×
260
        if err != nil {
261
                return err
6✔
262
        }
6✔
263

264
        old, err := s.from.Get()
265
        if err != nil {
26✔
266
                return err
26✔
267
        }
26✔
268
        if val == old {
269
                return nil
270
        }
271
        if err = s.from.Set(val); err != nil {
272
                return err
273
        }
274

275
        queueItem(s.DataChanged)
276
        return nil
277
}
278

279
func (s *intFromFloat) DataChanged() {
20✔
280
        s.trigger()
20✔
281
}
24✔
282

4✔
283
type stringFromInt struct {
4✔
284
        base
285

16✔
286
        format string
25✔
287

9✔
288
        from Int
12✔
289
}
3✔
290

3✔
291
// IntToString creates a binding that connects a Int data item to a String.
6✔
UNCOV
292
// Changes to the Int will be pushed to the String and setting the string will parse and set the
×
UNCOV
293
// Int if the parse was successful.
×
294
//
7✔
295
// Since: 2.0
7✔
296
func IntToString(v Int) String {
10✔
297
        str := &stringFromInt{from: v}
3✔
298
        v.AddListener(str)
3✔
299
        return str
4✔
300
}
301

302
// IntToStringWithFormat creates a binding that connects a Int data item to a String and is
10✔
303
// presented using the specified format. Changes to the Int will be pushed to the String and setting
304
// the string will parse and set the Int if the string matches the format and its parse was successful.
305
//
7✔
306
// Since: 2.0
7✔
307
func IntToStringWithFormat(v Int, format string) String {
10✔
308
        if format == "%d" { // Same as not using custom formatting.
3✔
309
                return IntToString(v)
7✔
310
        }
4✔
311

4✔
UNCOV
312
        str := &stringFromInt{from: v, format: format}
×
UNCOV
313
        v.AddListener(str)
×
314
        return str
4✔
315
}
316

317
func (s *stringFromInt) Get() (string, error) {
7✔
318
        val, err := s.from.Get()
7✔
UNCOV
319
        if err != nil {
×
320
                return "", err
×
321
        }
322

7✔
323
        if s.format != "" {
7✔
UNCOV
324
                return fmt.Sprintf(s.format, val), nil
×
UNCOV
325
        }
×
326

327
        return formatInt(val), nil
7✔
328
}
7✔
329

330
func (s *stringFromInt) Set(str string) error {
331
        var val int
34✔
332
        if s.format != "" {
34✔
333
                safe := stripFormatPrecision(s.format)
34✔
334
                n, err := fmt.Sscanf(str, safe+" ", &val) // " " denotes match to end of string
335
                if err != nil {
336
                        return err
337
                }
338
                if n != 1 {
339
                        return errParseFailed
340
                }
341
        } else {
342
                new, err := parseInt(str)
343
                if err != nil {
344
                        return err
2✔
345
                }
2✔
346
                val = new
2✔
UNCOV
347
        }
×
UNCOV
348

×
349
        old, err := s.from.Get()
2✔
350
        if err != nil {
351
                return err
352
        }
1✔
353
        if val == old {
1✔
354
                return nil
1✔
355
        }
×
UNCOV
356
        if err = s.from.Set(val); err != nil {
×
357
                return err
358
        }
1✔
359

1✔
UNCOV
360
        queueItem(s.DataChanged)
×
UNCOV
361
        return nil
×
362
}
1✔
UNCOV
363

×
UNCOV
364
func (s *stringFromInt) DataChanged() {
×
365
        s.trigger()
1✔
366
}
1✔
UNCOV
367

×
UNCOV
368
type stringFromURI struct {
×
369
        base
370

1✔
371
        from URI
1✔
372
}
373

374
// URIToString creates a binding that connects a URI data item to a String.
4✔
375
// Changes to the URI will be pushed to the String and setting the string will parse and set the
4✔
376
// URI if the parse was successful.
4✔
377
//
378
// Since: 2.1
379
func URIToString(v URI) String {
380
        str := &stringFromURI{from: v}
381
        v.AddListener(str)
382
        return str
383
}
384

385
func (s *stringFromURI) Get() (string, error) {
386
        val, err := s.from.Get()
2✔
387
        if err != nil {
2✔
388
                return "", err
2✔
389
        }
×
UNCOV
390

×
391
        return uriToString(val)
2✔
392
}
393

394
func (s *stringFromURI) Set(str string) error {
1✔
395
        val, err := uriFromString(str)
1✔
396
        if err != nil {
1✔
397
                return err
×
398
        }
×
399

1✔
400
        old, err := s.from.Get()
1✔
UNCOV
401
        if err != nil {
×
402
                return err
×
403
        }
1✔
UNCOV
404
        if val == old {
×
405
                return nil
×
406
        }
1✔
407
        if err = s.from.Set(val); err != nil {
1✔
408
                return err
×
409
        }
×
410

411
        queueItem(s.DataChanged)
1✔
412
        return nil
1✔
413
}
414

415
func (s *stringFromURI) DataChanged() {
4✔
416
        s.trigger()
4✔
417
}
4✔
418

419
type stringToBool struct {
420
        base
421

422
        format string
423

424
        from String
425
}
426

427
// StringToBool creates a binding that connects a String data item to a Bool.
428
// Changes to the String will be parsed and pushed to the Bool if the parse was successful, and setting
429
// the Bool update the String binding.
430
//
431
// Since: 2.0
432
func StringToBool(str String) Bool {
433
        v := &stringToBool{from: str}
434
        str.AddListener(v)
435
        return v
436
}
437

438
// StringToBoolWithFormat creates a binding that connects a String data item to a Bool and is
439
// presented using the specified format. Changes to the Bool will be parsed and if the format matches and
440
// the parse is successful it will be pushed to the String. Setting the Bool will push a formatted value
441
// into the String.
442
//
443
// Since: 2.0
444
func StringToBoolWithFormat(str String, format string) Bool {
445
        if format == "%t" { // Same as not using custom format.
446
                return StringToBool(str)
447
        }
448

449
        v := &stringToBool{from: str, format: format}
450
        str.AddListener(v)
451
        return v
452
}
453

454
func (s *stringToBool) Get() (bool, error) {
455
        str, err := s.from.Get()
456
        if str == "" || err != nil {
457
                return false, err
458
        }
459

460
        var val bool
461
        if s.format != "" {
462
                n, err := fmt.Sscanf(str, s.format+" ", &val) // " " denotes match to end of string
463
                if err != nil {
464
                        return false, err
465
                }
466
                if n != 1 {
467
                        return false, errParseFailed
468
                }
469
        } else {
470
                new, err := parseBool(str)
471
                if err != nil {
472
                        return false, err
473
                }
474
                val = new
475
        }
476

477
        return val, nil
478
}
479

480
func (s *stringToBool) Set(val bool) error {
481
        var str string
482
        if s.format != "" {
483
                str = fmt.Sprintf(s.format, val)
484
        } else {
485
                str = formatBool(val)
486
        }
487

488
        old, err := s.from.Get()
489
        if str == old {
490
                return err
491
        }
492

493
        if err = s.from.Set(str); err != nil {
494
                return err
495
        }
496

497
        queueItem(s.DataChanged)
498
        return nil
499
}
500

501
func (s *stringToBool) DataChanged() {
502
        s.trigger()
503
}
504

505
type stringToFloat struct {
506
        base
507

508
        format string
509

510
        from String
511
}
512

513
// StringToFloat creates a binding that connects a String data item to a Float.
514
// Changes to the String will be parsed and pushed to the Float if the parse was successful, and setting
515
// the Float update the String binding.
516
//
517
// Since: 2.0
518
func StringToFloat(str String) Float {
519
        v := &stringToFloat{from: str}
520
        str.AddListener(v)
521
        return v
522
}
523

524
// StringToFloatWithFormat creates a binding that connects a String data item to a Float and is
525
// presented using the specified format. Changes to the Float will be parsed and if the format matches and
526
// the parse is successful it will be pushed to the String. Setting the Float will push a formatted value
527
// into the String.
528
//
529
// Since: 2.0
530
func StringToFloatWithFormat(str String, format string) Float {
531
        if format == "%f" { // Same as not using custom format.
532
                return StringToFloat(str)
533
        }
534

535
        v := &stringToFloat{from: str, format: format}
536
        str.AddListener(v)
537
        return v
538
}
539

540
func (s *stringToFloat) Get() (float64, error) {
541
        str, err := s.from.Get()
542
        if str == "" || err != nil {
543
                return 0.0, err
544
        }
545

546
        var val float64
547
        if s.format != "" {
548
                n, err := fmt.Sscanf(str, s.format+" ", &val) // " " denotes match to end of string
549
                if err != nil {
550
                        return 0.0, err
551
                }
552
                if n != 1 {
553
                        return 0.0, errParseFailed
554
                }
555
        } else {
556
                new, err := parseFloat(str)
557
                if err != nil {
558
                        return 0.0, err
559
                }
560
                val = new
561
        }
562

563
        return val, nil
564
}
565

566
func (s *stringToFloat) Set(val float64) error {
567
        var str string
568
        if s.format != "" {
569
                str = fmt.Sprintf(s.format, val)
570
        } else {
571
                str = formatFloat(val)
572
        }
573

574
        old, err := s.from.Get()
575
        if str == old {
576
                return err
577
        }
578

579
        if err = s.from.Set(str); err != nil {
580
                return err
581
        }
582

583
        queueItem(s.DataChanged)
584
        return nil
585
}
586

587
func (s *stringToFloat) DataChanged() {
588
        s.trigger()
589
}
590

591
type stringToInt struct {
592
        base
593

594
        format string
595

596
        from String
597
}
598

599
// StringToInt creates a binding that connects a String data item to a Int.
600
// Changes to the String will be parsed and pushed to the Int if the parse was successful, and setting
601
// the Int update the String binding.
602
//
603
// Since: 2.0
604
func StringToInt(str String) Int {
605
        v := &stringToInt{from: str}
606
        str.AddListener(v)
607
        return v
608
}
609

610
// StringToIntWithFormat creates a binding that connects a String data item to a Int and is
611
// presented using the specified format. Changes to the Int will be parsed and if the format matches and
612
// the parse is successful it will be pushed to the String. Setting the Int will push a formatted value
613
// into the String.
614
//
615
// Since: 2.0
616
func StringToIntWithFormat(str String, format string) Int {
617
        if format == "%d" { // Same as not using custom format.
618
                return StringToInt(str)
619
        }
620

621
        v := &stringToInt{from: str, format: format}
622
        str.AddListener(v)
623
        return v
624
}
625

626
func (s *stringToInt) Get() (int, error) {
627
        str, err := s.from.Get()
628
        if str == "" || err != nil {
629
                return 0, err
630
        }
631

632
        var val int
633
        if s.format != "" {
634
                n, err := fmt.Sscanf(str, s.format+" ", &val) // " " denotes match to end of string
635
                if err != nil {
636
                        return 0, err
637
                }
638
                if n != 1 {
639
                        return 0, errParseFailed
640
                }
641
        } else {
642
                new, err := parseInt(str)
643
                if err != nil {
644
                        return 0, err
645
                }
646
                val = new
647
        }
648

649
        return val, nil
650
}
651

652
func (s *stringToInt) Set(val int) error {
653
        var str string
654
        if s.format != "" {
655
                str = fmt.Sprintf(s.format, val)
656
        } else {
657
                str = formatInt(val)
658
        }
659

660
        old, err := s.from.Get()
661
        if str == old {
662
                return err
663
        }
664

665
        if err = s.from.Set(str); err != nil {
666
                return err
667
        }
668

669
        queueItem(s.DataChanged)
670
        return nil
671
}
672

673
func (s *stringToInt) DataChanged() {
674
        s.trigger()
675
}
676

677
type stringToURI struct {
678
        base
679

680
        from String
681
}
682

683
// StringToURI creates a binding that connects a String data item to a URI.
684
// Changes to the String will be parsed and pushed to the URI if the parse was successful, and setting
685
// the URI update the String binding.
686
//
687
// Since: 2.1
688
func StringToURI(str String) URI {
689
        v := &stringToURI{from: str}
690
        str.AddListener(v)
691
        return v
692
}
693

694
func (s *stringToURI) Get() (fyne.URI, error) {
695
        str, err := s.from.Get()
696
        if str == "" || err != nil {
697
                return fyne.URI(nil), err
698
        }
699

700
        return uriFromString(str)
701
}
702

703
func (s *stringToURI) Set(val fyne.URI) error {
704
        str, err := uriToString(val)
705
        if err != nil {
706
                return err
707
        }
708
        old, err := s.from.Get()
709
        if str == old {
710
                return err
711
        }
712

713
        if err = s.from.Set(str); err != nil {
714
                return err
715
        }
716

717
        queueItem(s.DataChanged)
718
        return nil
719
}
720

721
func (s *stringToURI) DataChanged() {
722
        s.trigger()
723
}
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