rui_orig/scrollEvent.go

114 lines
3.9 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
// ScrollEvent is the constant for "scroll-event" property tag.
//
2024-12-05 20:15:39 +03:00
// Used by View.
// Is fired when the content of the view is scrolled.
//
// General listener format:
2024-12-05 20:15:39 +03:00
//
// func(view rui.View, frame rui.Frame)
//
// where:
2024-12-05 20:15:39 +03:00
// - view - Interface of a view which generated this event,
// - frame - New offset and size of the view's visible area.
//
// Allowed listener formats:
2024-12-05 20:15:39 +03:00
//
// func(frame rui.Frame)
// func(view rui.View)
// func()
2024-11-13 12:56:39 +03:00
const ScrollEvent PropertyName = "scroll-event"
2021-09-07 17:36:50 +03:00
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
2025-06-17 21:08:16 +03:00
for _, listener := range getOneArgEventListeners[View, Frame](view, nil, ScrollEvent) {
listener.Run(self, view.scroll)
2021-09-07 17:36:50 +03:00
}
}
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 ...
2025-06-17 21:08:16 +03:00
//
// The second argument (subviewID) specifies the path to the child element whose value needs to be returned.
// If it is not specified then a value from the first argument (view) is returned.
func GetViewScroll(view View, subviewID ...string) Frame {
2024-11-24 16:43:31 +03:00
view = getSubview(view, subviewID)
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
2025-06-17 21:08:16 +03:00
//
// Result elements can be of the following types:
// - func(rui.View, rui.Frame),
// - func(rui.View),
// - func(rui.Frame),
// - func(),
// - string.
//
// The second argument (subviewID) specifies the path to the child element whose value needs to be returned.
// If it is not specified then a value from the first argument (view) is returned.
func GetScrollListeners(view View, subviewID ...string) []any {
return getOneArgEventRawListeners[View, Frame](view, subviewID, ScrollEvent)
2021-09-07 17:36:50 +03:00
}
// ScrollTo scrolls the view's content to the given position.
2025-06-17 21:08:16 +03:00
//
// The second argument (subviewID) specifies the path to the child element whose value needs to be returned.
// If it is not specified then a value from the first argument (view) is returned.
2021-09-07 17:36:50 +03:00
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.
2025-06-17 21:08:16 +03:00
//
// The second argument (subviewID) specifies the path to the child element whose value needs to be returned.
// If it is not specified then a value from the first argument (view) is returned.
func ScrollViewToStart(view View, subviewID ...string) {
2024-11-24 16:43:31 +03:00
if view = getSubview(view, subviewID); 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.
2025-06-17 21:08:16 +03:00
//
// The second argument (subviewID) specifies the path to the child element whose value needs to be returned.
// If it is not specified then a value from the first argument (view) is returned.
func ScrollViewToEnd(view View, subviewID ...string) {
2024-11-24 16:43:31 +03:00
if view = getSubview(view, subviewID); view != nil {
2022-11-02 20:10:19 +03:00
view.Session().callFunc("scrollToEnd", view.htmlID())
2021-09-07 17:36:50 +03:00
}
}
2026-04-16 17:50:53 +03:00
// ScrollIntoViewIfNeeded scrolls the current view into the visible area of the browser window if it's not already within the visible area of the browser window.
// If the element is already within the visible area of the browser window, then no scrolling takes place.
//
// The second argument (subviewID) specifies the path to the child element whose value needs to be returned.
// If it is not specified then a value from the first argument (view) is returned.
func ScrollIntoViewIfNeeded(view View, subviewID ...string) {
if view = getSubview(view, subviewID); view != nil {
view.Session().callFunc("scrollIntoViewIfNeeded", view.htmlID())
}
}