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:
|
2022-08-31 22:17:46 +03:00
|
|
|
//
|
|
|
|
// func(View, Frame).
|
|
|
|
//
|
2021-11-04 21:13:34 +03:00
|
|
|
// The additional listener formats:
|
2022-08-31 22:17:46 +03:00
|
|
|
//
|
|
|
|
// 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
|
2022-08-31 22:17:46 +03:00
|
|
|
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 ...
|
2022-08-31 22:17:46 +03:00
|
|
|
// 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
|
2022-08-31 22:17:46 +03:00
|
|
|
// 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.
|
2022-08-31 22:17:46 +03:00
|
|
|
// 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.
|
2022-08-31 22:17:46 +03:00
|
|
|
// 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
|
|
|
}
|
|
|
|
}
|