rui_orig/focusEvents.go

62 lines
1.9 KiB
Go
Raw 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.
//
// Used by `View`.
// Occur when the view takes input focus.
//
// General listener format:
// `func(View)`.
//
// where:
// view - Interface of a view which generated this event.
//
// Allowed listener formats:
// `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.
//
// Used by `View`.
// Occur when the View lost input focus.
//
// General listener format:
// `func(view rui.View)`.
//
// where:
// view - Interface of a view which generated this event.
//
// Allowed listener formats:
// `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 {
buffer.WriteString(js.jsEvent)
buffer.WriteString(`="`)
buffer.WriteString(js.jsFunc)
buffer.WriteString(`(this, event)" `)
}
2021-09-07 17:36:50 +03:00
}
}
}
// GetFocusListeners returns a FocusListener list. If there are no listeners then the empty list is returned
// If the second argument (subviewID) is not specified or it is "" then a value from the first argument (view) is returned.
func GetFocusListeners(view View, subviewID ...string) []func(View) {
return getNoArgEventListeners[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
// If the second argument (subviewID) is not specified or it is "" then a value from the first argument (view) is returned.
func GetLostFocusListeners(view View, subviewID ...string) []func(View) {
return getNoArgEventListeners[View](view, subviewID, LostFocusEvent)
2021-09-07 17:36:50 +03:00
}