Skip to content

Commit 76a025c

Browse files
committed
Playing with extended container support
1 parent 2127941 commit 76a025c

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

container.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
package fyne
22

3+
import "fyne.io/fyne/v2/internal/types"
4+
35
// Declare conformity to [CanvasObject]
46
var _ CanvasObject = (*Container)(nil)
57

68
// Container is a [CanvasObject] that contains a collection of child objects.
79
// The layout of the children is set by the specified Layout.
810
type Container struct {
11+
types.ContainerRoot
12+
913
size Size // The current size of the Container
1014
position Position // The current position of the Container
1115
Hidden bool // Is this Container hidden

internal/types/container.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package types
2+
3+
type container interface {
4+
fyneTypeContainer()
5+
}
6+
7+
type ContainerRoot struct {
8+
}
9+
10+
func (c *ContainerRoot) fyneTypeContainer() {}
11+
12+
func IsContainer(o any) bool { // any to avoid loop if using fyne.CanvasObject
13+
_, ok := o.(container)
14+
return ok
15+
}

internal/types/container_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package types_test
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/assert"
7+
8+
"fyne.io/fyne/v2"
9+
container2 "fyne.io/fyne/v2/container"
10+
"fyne.io/fyne/v2/internal/types"
11+
)
12+
13+
func TestIsContainer(t *testing.T) {
14+
assert.True(t, types.IsContainer(&fyne.Container{}))
15+
assert.True(t, types.IsContainer(container2.NewWithoutLayout()))
16+
assert.True(t, types.IsContainer(&extendedContainer{}))
17+
}
18+
19+
type extendedContainer struct {
20+
fyne.Container
21+
}

0 commit comments

Comments
 (0)