Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Data binding file structure rework #5484

Merged
merged 5 commits into from
Feb 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 0 additions & 107 deletions data/binding/convert_benchmark_test.go

This file was deleted.

102 changes: 102 additions & 0 deletions data/binding/convert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,108 @@ import (
"fyne.io/fyne/v2/storage"
)

func BenchmarkBoolToString(b *testing.B) {
for i := 0; i < b.N; i++ {
bo := NewBool()
s := BoolToString(bo)
s.Get()

bo.Set(true)
s.Get()

s.Set("trap")
bo.Get()

s.Set("false")
bo.Get()
}
}

func BenchmarkFloatToString(b *testing.B) {
for i := 0; i < b.N; i++ {
f := NewFloat()
s := FloatToString(f)
s.Get()

f.Set(0.3)
s.Get()

s.Set("wrong")
f.Get()

s.Set("5.00")
f.Get()
}
}

func BenchmarkIntToString(b *testing.B) {
for i := 0; i < b.N; i++ {
i := NewInt()
s := IntToString(i)
s.Get()

i.Set(3)
s.Get()

s.Set("wrong")
i.Get()

s.Set("5")
i.Get()
}
}

func BenchmarkStringToBool(b *testing.B) {
for i := 0; i < b.N; i++ {
s := NewString()
b := StringToBool(s)
b.Get()

s.Set("true")
b.Get()

s.Set("trap") // bug in fmt.SScanf means "wrong" parses as "false"
b.Get()

b.Set(false)
s.Get()
}
}

func BenchmarkStringToFloat(b *testing.B) {
for i := 0; i < b.N; i++ {
s := NewString()
f := StringToFloat(s)
f.Get()

s.Set("3")
f.Get()

s.Set("wrong")
f.Get()

f.Set(5)
s.Get()
}
}

func BenchmarkStringToInt(b *testing.B) {
for i := 0; i < b.N; i++ {
s := NewString()
i := StringToInt(s)
i.Get()

s.Set("3")
i.Get()

s.Set("wrong")
i.Get()

i.Set(5)
s.Get()
}
}

func TestBoolToString(t *testing.T) {
b := NewBool()
s := BoolToString(b)
Expand Down
43 changes: 0 additions & 43 deletions data/binding/listbinding.go

This file was deleted.

66 changes: 0 additions & 66 deletions data/binding/listbinding_test.go

This file was deleted.

42 changes: 42 additions & 0 deletions data/binding/bindlists.go → data/binding/lists.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ import (
"fyne.io/fyne/v2"
)

// DataList is the base interface for all bindable data lists.
//
// Since: 2.0
type DataList interface {
DataItem
GetItem(index int) (DataItem, error)
Length() int
}

// BoolList supports binding a list of bool values.
//
// Since: 2.0
Expand Down Expand Up @@ -339,3 +348,36 @@ func NewURIList() URIList {
func BindURIList(v *[]fyne.URI) ExternalURIList {
return bindList(v, compareURI)
}

type listBase struct {
base
items []DataItem
}

// GetItem returns the DataItem at the specified index.
func (b *listBase) GetItem(i int) (DataItem, error) {
b.lock.RLock()
defer b.lock.RUnlock()

if i < 0 || i >= len(b.items) {
return nil, errOutOfBounds
}

return b.items[i], nil
}

// Length returns the number of items in this data list.
func (b *listBase) Length() int {
b.lock.RLock()
defer b.lock.RUnlock()

return len(b.items)
}

func (b *listBase) appendItem(i DataItem) {
b.items = append(b.items, i)
}

func (b *listBase) deleteItem(i int) {
b.items = append(b.items[:i], b.items[i+1:]...)
}
Loading
Loading