Skip to content

Playing with extended container support #5441

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

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
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
4 changes: 4 additions & 0 deletions container.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package fyne

import "fyne.io/fyne/v2/internal/types"

// Declare conformity to [CanvasObject]
var _ CanvasObject = (*Container)(nil)

// Container is a [CanvasObject] that contains a collection of child objects.
// The layout of the children is set by the specified Layout.
type Container struct {
types.ContainerRoot

size Size // The current size of the Container
position Position // The current position of the Container
Hidden bool // Is this Container hidden
Expand Down
15 changes: 15 additions & 0 deletions internal/types/container.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package types

type container interface {
fyneTypeContainer()
}

type ContainerRoot struct {
}

func (c *ContainerRoot) fyneTypeContainer() {}

func IsContainer(o any) bool { // any to avoid loop if using fyne.CanvasObject
_, ok := o.(container)
return ok
}
21 changes: 21 additions & 0 deletions internal/types/container_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package types_test

import (
"testing"

"github.com/stretchr/testify/assert"

"fyne.io/fyne/v2"
container2 "fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/internal/types"
)

func TestIsContainer(t *testing.T) {
assert.True(t, types.IsContainer(&fyne.Container{}))
assert.True(t, types.IsContainer(container2.NewWithoutLayout()))
assert.True(t, types.IsContainer(&extendedContainer{}))
}

type extendedContainer struct {
fyne.Container
}
Loading