rui_orig/focusEvents.go

73 lines
2.2 KiB
Go
Raw Permalink Normal View History

2021-09-07 17:36:50 +03:00
package rui
import "strings"
// Constants which represent [View] specific focus events properties
2021-09-07 17:36:50 +03:00
const (
2021-11-04 21:13:34 +03:00
// FocusEvent is the constant for "focus-event" property tag.
//
2024-12-05 20:15:39 +03:00
// Used by View.
// Occur when the view takes input focus.
//
// General listener format:
2024-12-05 20:15:39 +03:00
// func(rui.View).
//
// where:
// view - Interface of a view which generated this event.
//
// Allowed listener formats:
2024-12-05 20:15:39 +03:00
// func().
2024-11-13 12:56:39 +03:00
FocusEvent PropertyName = "focus-event"
2021-09-07 17:36:50 +03:00
2021-11-04 21:13:34 +03:00
// LostFocusEvent is the constant for "lost-focus-event" property tag.
//
2024-12-05 20:15:39 +03:00
// Used by View.
// Occur when the View lost input focus.
//
// General listener format:
2024-12-05 20:15:39 +03:00
// func(view rui.View).
//
// where:
// view - Interface of a view which generated this event.
//
// Allowed listener formats:
2024-12-05 20:15:39 +03:00
// func()
2024-11-13 12:56:39 +03:00
LostFocusEvent PropertyName = "lost-focus-event"
2021-09-07 17:36:50 +03:00
)
func focusEventsHtml(view View, buffer *strings.Builder) {
if view.Focusable() {
2024-11-13 12:56:39 +03:00
for _, tag := range []PropertyName{FocusEvent, LostFocusEvent} {
if js, ok := eventJsFunc[tag]; ok {
2026-09-03 12:39:07 +03:00
writeStrings(buffer, js.jsEvent, `="`, js.jsFunc, `(this, event)" `)
2024-11-13 12:56:39 +03:00
}
2021-09-07 17:36:50 +03:00
}
}
}
// GetFocusListeners returns a FocusListener list. If there are no listeners then the empty list is returned
2025-06-17 21:08:16 +03:00
//
2025-06-18 14:19:57 +03:00
// Result elements can be of the following types:
// - func(rui.View),
// - func(),
// - string.
//
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.
2025-06-18 14:19:57 +03:00
func GetFocusListeners(view View, subviewID ...string) []any {
return getNoArgEventRawListeners[View](view, subviewID, FocusEvent)
2021-09-07 17:36:50 +03:00
}
// GetLostFocusListeners returns a LostFocusListener list. If there are no listeners then the empty list is returned
2025-06-17 21:08:16 +03:00
//
2025-06-18 14:19:57 +03:00
// Result elements can be of the following types:
// - func(rui.View),
// - func(),
// - string.
//
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.
2025-06-18 14:19:57 +03:00
func GetLostFocusListeners(view View, subviewID ...string) []any {
return getNoArgEventRawListeners[View](view, subviewID, LostFocusEvent)
2021-09-07 17:36:50 +03:00
}