package ui type ClickHandler = func(int, int) type ScrollHandler = func(int, int) type UpdateHandler = func() error type FocusHandler = func(bool) type EventHandlers interface { IsClickable() bool Click(int, int) // IsHoverable() bool // Hover(int, int) IsScrollable() bool Scroll(int, int) IsUpdatable() bool Update() error IsFocusable() bool Focus(bool) } // TODO: cache events (in a bitmask) type EventHandlersMap map[string]any func NewEventHandlersMap() EventHandlersMap { return make(EventHandlersMap) } func (m EventHandlersMap) RegisterHandler(ev string, handler any) { // TODO: sanitize input m[ev] = handler } func (m EventHandlersMap) IsClickable() bool { _, found := m["click"] return found } func (m EventHandlersMap) Click(x, y int) { onclick := m["click"] onclick.(ClickHandler)(x, y) } func (m EventHandlersMap) IsScrollable() bool { _, found := m["update"] return found } func (m EventHandlersMap) Scroll(x, y int) { onscroll := m["scroll"] onscroll.(ScrollHandler)(x, y) } func (m EventHandlersMap) IsUpdatable() bool { _, found := m["update"] return found } func (m EventHandlersMap) Update() error { onupdate := m["update"] return onupdate.(UpdateHandler)() } func (m EventHandlersMap) IsHoverable() bool { _, found := m["hover"] return found } func (m EventHandlersMap) IsFocusable() bool { _, found := m["focus"] return found } func (m EventHandlersMap) Focus(focus bool) { onfocus := m["focus"] onfocus.(FocusHandler)(focus) }