Add callbacks for resize and move
This commit is contained in:
parent
36d12fd547
commit
bfd94a9e26
11
baseview.go
11
baseview.go
@ -10,6 +10,9 @@ import (
|
|||||||
"github.com/nicksnyder/go-i18n/v2/i18n"
|
"github.com/nicksnyder/go-i18n/v2/i18n"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type ResizeCallbackFn func(fyne.Size)
|
||||||
|
type MoveCallbackFn func(fyne.Position)
|
||||||
|
|
||||||
// BaseView represents the base implementation of a view
|
// BaseView represents the base implementation of a view
|
||||||
// You can create new view types by composing a type around BaseView
|
// You can create new view types by composing a type around BaseView
|
||||||
type BaseView struct {
|
type BaseView struct {
|
||||||
@ -137,3 +140,11 @@ func (v *BaseView) GetBinding(bindingName string) binding.DataItem {
|
|||||||
func (v *BaseView) GetCanvasObject() fyne.CanvasObject {
|
func (v *BaseView) GetCanvasObject() fyne.CanvasObject {
|
||||||
return v.CanvasObject
|
return v.CanvasObject
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (v *BaseView) RegisterResizeCallback(cb ResizeCallbackFn) {
|
||||||
|
v.ScreenHandler.RegisterResizeCallback(cb)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v *BaseView) RegisterMoveCallback(cb MoveCallbackFn) {
|
||||||
|
v.ScreenHandler.RegisterMoveCallback(cb)
|
||||||
|
}
|
||||||
|
@ -5,6 +5,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
|
|
||||||
|
"bitbucket.org/hevanto/ui/screen"
|
||||||
"fyne.io/fyne/v2"
|
"fyne.io/fyne/v2"
|
||||||
"fyne.io/fyne/v2/data/binding"
|
"fyne.io/fyne/v2/data/binding"
|
||||||
"fyne.io/fyne/v2/dialog"
|
"fyne.io/fyne/v2/dialog"
|
||||||
@ -357,7 +358,7 @@ func (d *FormDialog) SetButtonLabels(
|
|||||||
|
|
||||||
func (d *FormDialog) Initialize() fyne.CanvasObject {
|
func (d *FormDialog) Initialize() fyne.CanvasObject {
|
||||||
if d.itemsFn == nil {
|
if d.itemsFn == nil {
|
||||||
form := d.BaseDialog.Initialize().(*fyne.Container)
|
form := d.BaseDialog.Initialize().(*screen.Screen).AsContainer()
|
||||||
d.itemsFn = func() []*widget.FormItem {
|
d.itemsFn = func() []*widget.FormItem {
|
||||||
res := make([]*widget.FormItem, 0, len(form.Objects)/2)
|
res := make([]*widget.FormItem, 0, len(form.Objects)/2)
|
||||||
for i := 0; i < len(form.Objects); i += 2 {
|
for i := 0; i < len(form.Objects); i += 2 {
|
||||||
|
@ -57,8 +57,12 @@ type ScreenHandler interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Screen struct {
|
type Screen struct {
|
||||||
|
fyne.CanvasObject
|
||||||
rootElement *Element
|
rootElement *Element
|
||||||
screenHandler ScreenHandler
|
screenHandler ScreenHandler
|
||||||
|
|
||||||
|
resizeCallbacks []func(fyne.Size)
|
||||||
|
moveCallbacks []func(fyne.Position)
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(
|
func New(
|
||||||
@ -107,13 +111,44 @@ func NewTemplate(
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *Screen) Initialize() (obj fyne.CanvasObject, err error) {
|
func (s *Screen) Initialize() (obj fyne.CanvasObject, err error) {
|
||||||
if obj, err = s.rootElement.BuildUI(s.screenHandler); err != nil {
|
if s.CanvasObject, err = s.rootElement.BuildUI(s.screenHandler); err != nil {
|
||||||
err = fmt.Errorf("failed to build screen: %w", err)
|
err = fmt.Errorf("failed to build screen: %w", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
obj = s
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Screen) Move(p fyne.Position) {
|
||||||
|
s.CanvasObject.Move(p)
|
||||||
|
for _, cb := range s.moveCallbacks {
|
||||||
|
cb(p)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Screen) Resize(sz fyne.Size) {
|
||||||
|
s.CanvasObject.Resize(sz)
|
||||||
|
for _, cb := range s.resizeCallbacks {
|
||||||
|
cb(sz)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Screen) CreateRenderer() fyne.WidgetRenderer {
|
||||||
|
return widget.NewSimpleRenderer(s.CanvasObject)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Screen) RegisterResizeCallback(cb func(fyne.Size)) {
|
||||||
|
s.resizeCallbacks = append(s.resizeCallbacks, cb)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Screen) RegisterMoveCallback(cb func(fyne.Position)) {
|
||||||
|
s.moveCallbacks = append(s.moveCallbacks, cb)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Screen) AsContainer() *fyne.Container {
|
||||||
|
return s.CanvasObject.(*fyne.Container)
|
||||||
|
}
|
||||||
|
|
||||||
type TemplateScreenHandler struct {
|
type TemplateScreenHandler struct {
|
||||||
localizer *i18n.Localizer
|
localizer *i18n.Localizer
|
||||||
elementsMap map[string]*UIElement
|
elementsMap map[string]*UIElement
|
||||||
|
@ -430,3 +430,11 @@ func (h *ScreenHandler) GetOnValidationChangedHandler(name string) screen.Valida
|
|||||||
}
|
}
|
||||||
return fn
|
return fn
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (h *ScreenHandler) RegisterResizeCallback(cb ResizeCallbackFn) {
|
||||||
|
h.screenDefinition.RegisterResizeCallback(cb)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *ScreenHandler) RegisterMoveCallback(cb MoveCallbackFn) {
|
||||||
|
h.screenDefinition.RegisterMoveCallback(cb)
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user