forked from mbk-lab/rui_orig
2
0
Fork 0
rui/scrollEvent.go

85 lines
2.7 KiB
Go
Raw Normal View History

2021-09-07 17:36:50 +03:00
package rui
2021-11-04 21:13:34 +03:00
// ScrollEvent is the constant for "scroll-event" property tag.
2022-07-27 20:31:57 +03:00
// The "scroll-event" is fired when the content of the view is scrolled.
2021-11-04 21:13:34 +03:00
// The main listener format:
//
// func(View, Frame).
//
2021-11-04 21:13:34 +03:00
// The additional listener formats:
//
// func(Frame), func(View), and func().
2021-09-07 17:36:50 +03:00
const ScrollEvent = "scroll-event"
func (view *viewData) onScroll(self View, x, y, width, height float64) {
view.scroll.Left = x
view.scroll.Top = y
view.scroll.Width = width
view.scroll.Height = height
for _, listener := range GetScrollListeners(view) {
2021-09-07 17:36:50 +03:00
listener(self, view.scroll)
}
}
func (view *viewData) Scroll() Frame {
return view.scroll
}
func (view *viewData) setScroll(x, y, width, height float64) {
view.scroll.Left = x
view.scroll.Top = y
view.scroll.Width = width
view.scroll.Height = height
}
// GetViewScroll returns ...
// If the second argument (subviewID) is not specified or it is "" then a value of the first argument (view) is returned
func GetViewScroll(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.Scroll()
}
// GetScrollListeners returns the list of "scroll-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 GetScrollListeners(view View, subviewID ...string) []func(View, Frame) {
2022-07-27 20:31:57 +03:00
return getEventListeners[View, Frame](view, subviewID, ResizeEvent)
2021-09-07 17:36:50 +03:00
}
// ScrollTo scrolls the view's content to the given position.
// If the second argument (subviewID) is "" then the first argument (view) is used
func ScrollViewTo(view View, subviewID string, x, y float64) {
if subviewID != "" {
view = ViewByID(view, subviewID)
}
if view != nil {
2022-11-02 20:10:19 +03:00
view.Session().callFunc("scrollTo", view.htmlID(), x, y)
2021-09-07 17:36:50 +03:00
}
}
// ScrollViewToEnd scrolls the view's content to the start of view.
// If the second argument (subviewID) is not specified or it is "" then the first argument (view) is used
func ScrollViewToStart(view View, subviewID ...string) {
if len(subviewID) > 0 && subviewID[0] != "" {
view = ViewByID(view, subviewID[0])
2021-09-07 17:36:50 +03:00
}
if view != nil {
2022-11-02 20:10:19 +03:00
view.Session().callFunc("scrollToStart", view.htmlID())
2021-09-07 17:36:50 +03:00
}
}
// ScrollViewToEnd scrolls the view's content to the end of view.
// If the second argument (subviewID) is not specified or it is "" then the first argument (view) is used
func ScrollViewToEnd(view View, subviewID ...string) {
if len(subviewID) > 0 && subviewID[0] != "" {
view = ViewByID(view, subviewID[0])
2021-09-07 17:36:50 +03:00
}
if view != nil {
2022-11-02 20:10:19 +03:00
view.Session().callFunc("scrollToEnd", view.htmlID())
2021-09-07 17:36:50 +03:00
}
}