forked from fyne-io/fyne
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into themed-resource-colorize
- Loading branch information
Showing
95 changed files
with
774 additions
and
557 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package async | ||
|
||
import ( | ||
"math" | ||
"sync/atomic" | ||
|
||
"fyne.io/fyne/v2" | ||
) | ||
|
||
// Position is an atomic version of fyne.Position. | ||
// Loads and stores are guaranteed to happen using a single atomic operation. | ||
type Position struct { | ||
pos atomic.Uint64 | ||
} | ||
|
||
// Load performs an atomic load on the fyne.Position value. | ||
func (p *Position) Load() fyne.Position { | ||
return fyne.NewPos(twoFloat32FromUint64(p.pos.Load())) | ||
} | ||
|
||
// Store performs an atomic store on the fyne.Position value. | ||
func (p *Position) Store(pos fyne.Position) { | ||
p.pos.Store(uint64fromTwoFloat32(pos.X, pos.Y)) | ||
} | ||
|
||
// Size is an atomic version of fyne.Size. | ||
// Loads and stores are guaranteed to happen using a single atomic operation. | ||
type Size struct { | ||
size atomic.Uint64 | ||
} | ||
|
||
// Load performs an atomic load on the fyne.Size value. | ||
func (s *Size) Load() fyne.Size { | ||
return fyne.NewSize(twoFloat32FromUint64(s.size.Load())) | ||
} | ||
|
||
// Store performs an atomic store on the fyne.Size value. | ||
func (s *Size) Store(size fyne.Size) { | ||
s.size.Store(uint64fromTwoFloat32(size.Width, size.Height)) | ||
} | ||
|
||
func uint64fromTwoFloat32(a, b float32) uint64 { | ||
x := uint64(math.Float32bits(a)) | ||
y := uint64(math.Float32bits(b)) | ||
return (y << 32) | x | ||
} | ||
|
||
func twoFloat32FromUint64(combined uint64) (float32, float32) { | ||
x := uint32(combined) | ||
y := uint32(combined >> 32) | ||
return math.Float32frombits(x), math.Float32frombits(y) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package async_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"fyne.io/fyne/v2" | ||
"fyne.io/fyne/v2/internal/async" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
var globalSize fyne.Size | ||
|
||
func BenchmarkAtomicLoadAndStore(b *testing.B) { | ||
local := fyne.Size{} | ||
size := async.Size{} | ||
|
||
// Each loop iteration replicates how .Resize() in BaseWidget checks size changes. | ||
for i := 0; i < b.N; i++ { | ||
new := fyne.Size{Width: float32(i), Height: float32(i)} | ||
if new == size.Load() { | ||
continue | ||
} | ||
|
||
size.Store(new) | ||
} | ||
|
||
globalSize = local | ||
} | ||
|
||
func TestSize(t *testing.T) { | ||
size := async.Size{} | ||
assert.Equal(t, fyne.Size{}, size.Load()) | ||
|
||
square := fyne.NewSquareSize(100) | ||
size.Store(square) | ||
assert.Equal(t, square, size.Load()) | ||
|
||
uneven := fyne.NewSize(125, 600) | ||
size.Store(uneven) | ||
assert.Equal(t, uneven, size.Load()) | ||
|
||
floats := fyne.NewSize(-22.565, 133.333) | ||
size.Store(floats) | ||
assert.Equal(t, floats, size.Load()) | ||
} | ||
|
||
func TestPosition(t *testing.T) { | ||
pos := async.Position{} | ||
assert.Equal(t, fyne.Position{}, pos.Load()) | ||
|
||
even := fyne.NewSquareOffsetPos(100) | ||
pos.Store(even) | ||
assert.Equal(t, even, pos.Load()) | ||
|
||
uneven := fyne.NewPos(125, 600) | ||
pos.Store(uneven) | ||
assert.Equal(t, uneven, pos.Load()) | ||
|
||
floats := fyne.NewPos(-22.565, 133.333) | ||
pos.Store(floats) | ||
assert.Equal(t, floats, pos.Load()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.