2021-09-07 17:36:50 +03:00
|
|
|
package rui
|
|
|
|
|
|
|
|
import "strings"
|
|
|
|
|
2024-09-12 14:05:11 +03:00
|
|
|
// 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-09-18 13:50:06 +03:00
|
|
|
//
|
|
|
|
// 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.
|
2024-09-18 13:50:06 +03:00
|
|
|
//
|
|
|
|
// 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) {
|
2022-01-15 01:20:04 +03:00
|
|
|
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
|
2022-08-31 22:17:46 +03:00
|
|
|
// 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) {
|
2024-11-18 17:20:25 +03:00
|
|
|
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
|
2022-08-31 22:17:46 +03:00
|
|
|
// 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) {
|
2024-11-18 17:20:25 +03:00
|
|
|
return getNoArgEventListeners[View](view, subviewID, LostFocusEvent)
|
2021-09-07 17:36:50 +03:00
|
|
|
}
|