Skip to content

Commit f7b84aa

Browse files
committed
Support adding 3rd party components
1 parent c3b65aa commit f7b84aa

2 files changed

Lines changed: 33 additions & 1 deletion

File tree

go.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func exportCode(pkgs, vars []string, obj fyne.CanvasObject, d Context, name stri
6767
continue
6868
}
6969

70-
if pkgs[i] != "fmt" && pkgs[i] != "net/url" && pkgs[i] != "image/color" {
70+
if pkgs[i] != "fmt" && !strings.Contains(pkgs[i], "/") {
7171
pkgs[i] = "fyne.io/fyne/v2/" + pkgs[i]
7272
}
7373

widget.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,40 @@ import (
66
"github.com/fyne-io/refyne/internal/guidefs"
77
)
88

9+
type WidgetInfo = guidefs.WidgetInfo
10+
911
// CollectionClassList returns the list of supported collection widget classes.
1012
// These can be used for passing to `CreateNew` or `EditorFor`.
1113
func CollectionClassList() []string {
1214
return guidefs.CollectionNames
1315
}
1416

17+
// RegisterCollection allows a 3rd party collection widget to be added to those recognised.
18+
// It is important that the Name field is populated with the typed name (i.e. *myPkg.MyWidget)
19+
// and your package should be returned in the list from Packages() as well.
20+
func RegisterCollection(info WidgetInfo) {
21+
guidefs.InitOnce()
22+
23+
guidefs.CollectionNames = append(guidefs.CollectionNames, info.Name)
24+
guidefs.Collections[info.Name] = info
25+
}
26+
1527
// ContainerClassList returns the list of supported container classes.
1628
// These can be used for passing to `CreateNew` or `EditorFor`.
1729
func ContainerClassList() []string {
1830
return guidefs.ContainerNames
1931
}
2032

33+
// RegisterContainer allows a 3rd party container widget to be added to those recognised.
34+
// It is important that the Name field is populated with the typed name (i.e. *myPkg.MyWidget)
35+
// and your package should be returned in the list from Packages() as well.
36+
func RegisterContainer(info WidgetInfo) {
37+
guidefs.InitOnce()
38+
39+
guidefs.ContainerNames = append(guidefs.ContainerNames, info.Name)
40+
guidefs.Containers[info.Name] = info
41+
}
42+
2143
// GraphicsClassList returns the list of supported graphics primitives classes.
2244
// These can be used for passing to `CreateNew` or `EditorFor`.
2345
func GraphicsClassList() []string {
@@ -30,6 +52,16 @@ func WidgetClassList() []string {
3052
return guidefs.WidgetNames
3153
}
3254

55+
// RegisterWidget allows a 3rd party Fyne widget to be added to those recognised.
56+
// It is important that the Name field is populated with the typed name (i.e. *myPkg.MyWidget)
57+
// and your package should be returned in the list from Packages() as well.
58+
func RegisterWidget(info WidgetInfo) {
59+
guidefs.InitOnce()
60+
61+
guidefs.WidgetNames = append(guidefs.WidgetNames, info.Name)
62+
guidefs.Widgets[info.Name] = info
63+
}
64+
3365
// DropZonesForObject returns the children of a container that can be used as drag and drop target zones
3466
func DropZonesForObject(o fyne.CanvasObject) []fyne.CanvasObject {
3567
class := guidefs.TypeName(o)

0 commit comments

Comments
 (0)