rui_orig/resizeEvent.go

90 lines
2.4 KiB
Go
Raw Permalink Normal View History

2021-09-07 17:36:50 +03:00
package rui
2021-11-04 21:13:34 +03:00
// ResizeEvent is the constant for "resize-event" property tag.
//
// Used by `View`.
// Is fired when the view changes its size.
//
// General listener format:
// `func(view rui.View, frame rui.Frame)`.
//
// where:
// view - Interface of a view which generated this event,
// frame - New offset and size of the view's visible area.
//
// Allowed listener formats:
// `func(frame rui.Frame)`,
// `func(view rui.View)`,
// `func()`.
2024-11-13 12:56:39 +03:00
const ResizeEvent PropertyName = "resize-event"
2021-09-07 17:36:50 +03:00
func (view *viewData) onResize(self View, x, y, width, height float64) {
view.frame.Left = x
view.frame.Top = y
view.frame.Width = width
view.frame.Height = height
for _, listener := range GetResizeListeners(view) {
2021-09-07 17:36:50 +03:00
listener(self, view.frame)
}
}
func (view *viewData) onItemResize(self View, index string, x, y, width, height float64) {
2021-09-07 17:36:50 +03:00
}
2024-11-13 12:56:39 +03:00
/*
func setFrameListener(properties Properties, tag PropertyName, value any) bool {
if listeners, ok := valueToOneArgEventListeners[View, Frame](value); ok {
2024-11-13 12:56:39 +03:00
if len(listeners) == 0 {
properties.setRaw(tag, nil)
} else {
properties.setRaw(tag, listeners)
}
return true
2021-09-07 17:36:50 +03:00
}
2024-11-13 12:56:39 +03:00
notCompatibleType(tag, value)
return false
2021-09-07 17:36:50 +03:00
}
2024-11-13 12:56:39 +03:00
*/
2021-09-07 17:36:50 +03:00
func (view *viewData) setNoResizeEvent() {
view.noResizeEvent = true
}
func (view *viewData) isNoResizeEvent() bool {
return view.noResizeEvent
}
func (container *viewsContainerData) isNoResizeEvent() bool {
if container.noResizeEvent {
return true
}
if parent := container.Parent(); parent != nil {
return parent.isNoResizeEvent()
}
return false
}
func (view *viewData) Frame() Frame {
return view.frame
}
// GetViewFrame returns the size and location of view's viewport.
// If the second argument (subviewID) is not specified or it is "" then the value of the first argument (view) is returned
func GetViewFrame(view View, subviewID ...string) Frame {
if len(subviewID) > 0 && subviewID[0] != "" {
view = ViewByID(view, subviewID[0])
2021-09-07 17:36:50 +03:00
}
if view == nil {
return Frame{}
}
return view.Frame()
}
// GetResizeListeners returns the list of "resize-event" listeners. If there are no listeners then the empty list is returned
// If the second argument (subviewID) is not specified or it is "" then the listeners list of the first argument (view) is returned
func GetResizeListeners(view View, subviewID ...string) []func(View, Frame) {
return getOneArgEventListeners[View, Frame](view, subviewID, ResizeEvent)
2021-09-07 17:36:50 +03:00
}