teaspoon

package module
v0.0.0-...-df1c04c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 11, 2024 License: MIT Imports: 3 Imported by: 0

README

TeaSpoon

TeaSpoon is a Go package that provides interactive elements for terminal user interfaces built with Bubble Tea. It offers support for clickable, hoverable, draggable, and droppable elements. Enjoy the basic functionality or easily define your own interaction behaviours. The goal of this project is to enable effortless functionality without standing in the way of your creativity. Give it a stir!

Features

  • Click handling (single click, double click, right click)
  • Hover detection
  • Drag and drop functionality
  • Customizable event handlers
  • Employs Bubble Zone by default

Installation

go get github.com/jordanella/teaspoon

Quick Start

Here's a simple example of how to use TeaSpoon:

package main


// Assumes standard tea and zone implementation
// Zone is not required but is employed in default bounds detection
import (
    "github.com/jordanella/teaspoon"
    tea "github.com/charmbracelet/bubbletea"
	zone "github.com/lrstanley/bubblezone"
)

// Define interactive component with an *Interactable field
type Component struct {
	interaction *teaspoon.Interactable
}

// Add GetInteraction() *Interactable method to return the field
func (c Component) GetInteraction() *teaspoon.Interactable {
	return c.interaction
}

// Example main model containing our component
type MainModel struct{
    tea.Model
    component Component
}

// Initialize as few or many handlers required when creating component
mainModel := MainModel{
    component: Component{
        interaction: &teaspoon.Interactable{
            ID: zone.NewPrefix(),
            Click: &teaspoon.ClickHandler{},
            Hover: &teaspoon.HoverHandler{},
            Drop: &teaspoon.DropHandler{},
            DragEvent: &teaspoon.DragEventHandler{},
        },
    }
}

// Incorporate HandleMouseMsg and/or HandleExternalEvent functions into the Update pipeline
func (m MainModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
	switch msg := msg.(type) {
	case tea.MouseMsg:
        newComponent, cmd := m.component.interaction.HandleMouseMsg(button, msg)
        m.component = newComponent.(Component)
		return m, cmd
	}
	return m, nil
}

// Start configuring your component to render conditionally!
func (c Component) View() string {
    if c.interaction.IsHovered {
        return "Hovered state!"
    }
    return "Normal state"
}

Documentation

For detailed documentation, please see the Go Docs.

Examples

Check out the examples directory for more detailed usage examples.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ClickEvent

type ClickEvent struct {
	ID        string
	EventType ClickEventType
	MouseMsg  tea.MouseMsg
}

* Click Events

  • Click event messages to enable responses to external interactions
  • Default behaviours will broadcast if EmitMessages is set to true

type ClickEventAware

type ClickEventAware interface {
	HandleClickEvent(element Interactive, clickEvent ClickEvent) (Interactive, tea.Cmd)
	HandleDoubleClickEvent(element Interactive, clickEvent ClickEvent) (Interactive, tea.Cmd)
	HandleRightClickEvent(element Interactive, clickEvent ClickEvent) (Interactive, tea.Cmd)
}

* Click Event Aware Interface

  • Interface definition for responding to external click interactions
  • No default behaviour is defined for responding to external click events

type ClickEventType

type ClickEventType int

* Click Event Types

  • Enum for providing context to ClickEvent messages
const (
	Click ClickEventType = iota
	DoubleClick
	RightClick
)

type ClickHandler

type ClickHandler struct {
	OnClick       func(element Interactive, mouseMsg tea.MouseMsg) (Interactive, tea.Cmd)
	OnDoubleClick func(element Interactive, mouseMsg tea.MouseMsg) (Interactive, tea.Cmd)
	OnRightClick  func(element Interactive, mouseMsg tea.MouseMsg) (Interactive, tea.Cmd)

	OnClickEvent       func(element Interactive, mouseMsg tea.MouseMsg) (Interactive, tea.Cmd)
	OnDoubleClickEvent func(element Interactive, mouseMsg tea.MouseMsg) (Interactive, tea.Cmd)
	OnRightClickEvent  func(element Interactive, mouseMsg tea.MouseMsg) (Interactive, tea.Cmd)

	EmitMessages bool
}

* Click Behaviour Handler

  • Interface for handling click events and defining local and external event behaviours
  • Default emission behaviour for an event will not occur if a custom behavior is defined
  • Default behaviours do not emit click events unless EmitMessage is set to true

func (*ClickHandler) DefaultClick

func (h *ClickHandler) DefaultClick(element Interactive, mouseMsg tea.MouseMsg) (Interactive, tea.Cmd)

* Default Click Behaviour

  • Sets an element's MouseInteraction IsSelected property to true

func (*ClickHandler) DefaultDoubleClick

func (h *ClickHandler) DefaultDoubleClick(element Interactive, mouseMsg tea.MouseMsg) (Interactive, tea.Cmd)

* Default Double Click Behaviour

  • Sets an element's MouseInteraction IsSelected property to true

func (*ClickHandler) DefaultRightClick

func (h *ClickHandler) DefaultRightClick(element Interactive, mouseMsg tea.MouseMsg) (Interactive, tea.Cmd)

* Default Right Click Behaviour

  • Sets an element's MouseInteraction IsSelected property to true

func (*ClickHandler) HandleClick

func (h *ClickHandler) HandleClick(element Interactive, mouseMsg tea.MouseMsg) (Interactive, tea.Cmd)

* Left Click Handler

  • Responds to localized clicks with OnClick function or DefaultClick if it is not defined

func (*ClickHandler) HandleClickEvent

func (h *ClickHandler) HandleClickEvent(element Interactive, mouseMsg tea.MouseMsg) (Interactive, tea.Cmd)

* External Left Click Handler

  • Responds to external click events with OnClickEvent function if defined
  • No default behaviour is defined for responding to external click events

func (*ClickHandler) HandleDoubleClick

func (h *ClickHandler) HandleDoubleClick(element Interactive, mouseMsg tea.MouseMsg) (Interactive, tea.Cmd)

* Double Left Click Handler

  • Responds to localized double click events with OnDoubleClick function or DefaultDoubleClick if it is not defined

func (*ClickHandler) HandleDoubleClickEvent

func (h *ClickHandler) HandleDoubleClickEvent(element Interactive, mouseMsg tea.MouseMsg) (Interactive, tea.Cmd)

* External Double Left Click Handler

  • Responds to external double click events with OnDoubleClickEvent function if defined
  • No default behaviour is defined for responding to external double click events

func (*ClickHandler) HandleRightClick

func (h *ClickHandler) HandleRightClick(element Interactive, mouseMsg tea.MouseMsg) (Interactive, tea.Cmd)

* Right Click Handler

  • Sets an element's MouseInteraction IsSelected property to true

func (*ClickHandler) HandleRightClickEvent

func (h *ClickHandler) HandleRightClickEvent(element Interactive, mouseMsg tea.MouseMsg) (Interactive, tea.Cmd)

* External Right Click Handler

  • Responds to external right click events with OnRightClickEvent function if defined
  • No default behaviour is defined for responding to external right click events

type Clickable

type Clickable interface {
	HandleClick(element Interactive, mouseMsg tea.MouseMsg) (Interactive, tea.Cmd)
	HandleDoubleClick(element Interactive, mouseMsg tea.MouseMsg) (Interactive, tea.Cmd)
	HandleRightClick(element Interactive, mouseMsg tea.MouseMsg) (Interactive, tea.Cmd)
}

* Clickable Interface

  • Interface definition for handling localized click interactions

type DragEvent

type DragEvent struct {
	ID         string
	EventType  DragEventType
	DragType   string
	DragOrigin Point
	DragOffset Point
	MouseMsg   tea.MouseMsg
}

* Drag Events

  • Drag event messages to enable responses to external interactions
  • Default behaviours will broadcast if EmitMessages is set to true

type DragEventAware

type DragEventAware interface {
	HandleDragStartEvent(element Interactive, dragEvent DragEvent) (Interactive, tea.Cmd)
	HandleDragMoveEvent(element Interactive, dragEvent DragEvent) (Interactive, tea.Cmd)
	HandleDragEndEvent(element Interactive, dragEvent DragEvent) (Interactive, tea.Cmd)
}

* Drag Event Aware Interface

  • Interface definition for handling localized hover interactions

type DragEventType

type DragEventType int

* Drag Event Types

  • Enum for providing context to DragEvent messages
const (
	DragStart DragEventType = iota
	DragMove
	DragEnd
)

type DragHandler

type DragHandler struct {
	OnDragStart func(element Interactive, mouseMsg tea.MouseMsg) (Interactive, tea.Cmd)
	OnDragMove  func(element Interactive, mouseMsg tea.MouseMsg) (Interactive, tea.Cmd)
	OnDragEnd   func(element Interactive, mouseMsg tea.MouseMsg) (Interactive, tea.Cmd)

	OnDragStartEvent func(element Interactive, dragEvent DragEvent) (Interactive, tea.Cmd)
	OnDragMoveEvent  func(element Interactive, dragEvent DragEvent) (Interactive, tea.Cmd)
	OnDragEndEvent   func(element Interactive, dragEvent DragEvent) (Interactive, tea.Cmd)

	EmitMessages bool
}

* Drag Behaviour Handler

  • Interface for handling drag events and defining local and external event behaviours
  • Default emission behaviour for an event will not occur if a custom behavior is defined
  • Default behaviours do not emit drag events unless EmitMessage is set to true

func (*DragHandler) DefaultDragEnd

func (h *DragHandler) DefaultDragEnd(element Interactive, mouseMsg tea.MouseMsg) (Interactive, tea.Cmd)

* Default Drag End Behaviour

- Sets an element's MouseInteraction IsDragging property to false

func (*DragHandler) DefaultDragMove

func (h *DragHandler) DefaultDragMove(element Interactive, mouseMsg tea.MouseMsg) (Interactive, tea.Cmd)

* Default Drag Move Behaviour

  • Sets an element's MouseInteraction IsDragging property to true

func (*DragHandler) DefaultDragStart

func (h *DragHandler) DefaultDragStart(element Interactive, mouseMsg tea.MouseMsg) (Interactive, tea.Cmd)

* Default Drag Start Behaviour

  • Sets an element's MouseInteraction IsDragging property to true

func (*DragHandler) HandleDragEnd

func (h *DragHandler) HandleDragEnd(element Interactive, mouseMsg tea.MouseMsg, dragEvent DragEvent) (Interactive, tea.Cmd)

* Drag End Handler

  • Responds to localized drag end events with OnDragEnd function or DefaultDragEnd if undefined

func (*DragHandler) HandleDragEndEvent

func (h *DragHandler) HandleDragEndEvent(element Interactive, dragEvent DragEvent) (Interactive, tea.Cmd)

* External Drag End Handler

  • Responds to external drag end events with OnDragEndEvent function if defined
  • No default behaviour is defined for responding to external drag end events

func (*DragHandler) HandleDragMove

func (h *DragHandler) HandleDragMove(element Interactive, mouseMsg tea.MouseMsg, dragEvent DragEvent) (Interactive, tea.Cmd)

* Drag Move Handler

  • Responds to localized drag move events with OnDragMove function or DefaultDragMove if undefined

func (*DragHandler) HandleDragMoveEvent

func (h *DragHandler) HandleDragMoveEvent(element Interactive, dragEvent DragEvent) (Interactive, tea.Cmd)

* External Drag Move Handler

  • Responds to external mouse leave events with OnDragMoveEvent function if defined
  • No default behaviour is defined for responding to external drag move events

func (*DragHandler) HandleDragStart

func (h *DragHandler) HandleDragStart(element Interactive, mouseMsg tea.MouseMsg, dragEvent DragEvent) (Interactive, tea.Cmd)

* Drag Start Handler

  • Responds to localized drag start events with OnDragStart function or DefaultDragStart if undefined

func (*DragHandler) HandleDragStartEvent

func (h *DragHandler) HandleDragStartEvent(element Interactive, dragEvent DragEvent) (Interactive, tea.Cmd)

* External Drag Start Handler

  • Responds to external drag start events with OnDragStartEvent function if defined
  • No default behaviour is defined for responding to external drag start events

type Draggable

type Draggable interface {
	HandleDragStart(element Interactive, mouseMsg tea.MouseMsg) (Interactive, tea.Cmd)
	HandleDragMove(element Interactive, mouseMsg tea.MouseMsg) (Interactive, tea.Cmd)
	HandleDragEnd(element Interactive, mouseMsg tea.MouseMsg) (Interactive, tea.Cmd)
}

* Draggable Interface

  • Interface definition for handling localized drag interactions

type DropEvent

type DropEvent struct {
	ID         string
	EventType  DropEventType
	DropType   string
	Acceptable bool
	DragEvent  DragEvent
}

* Drop Events

  • Drop event messages to enable responses to external interactions
  • Default behaviours will broadcast if EmitMessages is set to true

type DropEventAware

type DropEventAware interface {
	HandleDropEnterEvent(element Interactive, dropEvent DropEvent) (Interactive, tea.Cmd)
	HandleDropHoverEvent(element Interactive, dropEvent DropEvent) (Interactive, tea.Cmd)
	HandleDropLeaveEvent(element Interactive, dropEvent DropEvent) (Interactive, tea.Cmd)
	HandleDropReleaseEvent(element Interactive, dropEvent DropEvent) (Interactive, tea.Cmd)
	HandleDropAcceptEvent(element Interactive, dropEvent DropEvent) (Interactive, tea.Cmd)
	HandleDropDenyEvent(element Interactive, dropEvent DropEvent) (Interactive, tea.Cmd)
}

* Droppable Interface

  • Interface definition for handling external drop interactions

type DropEventType

type DropEventType int

* Drop Event Types

  • Enum for providing context to DropEvent messages
const (
	DropEnter DropEventType = iota
	DropHover
	DropLeave
	DropRelease
	DropAccept
	DropDeny
)

type DropHandler

type DropHandler struct {
	OnDropEnter   func(element Interactive, dragEvent DragEvent) (Interactive, tea.Cmd)
	OnDropHover   func(element Interactive, dragEvent DragEvent) (Interactive, tea.Cmd)
	OnDropLeave   func(element Interactive, dragEvent DragEvent) (Interactive, tea.Cmd)
	OnDropRelease func(element Interactive, dragEvent DragEvent) (Interactive, tea.Cmd)
	OnDropAccept  func(element Interactive, dragEvent DragEvent) (Interactive, tea.Cmd)
	OnDropDeny    func(element Interactive, dragEvent DragEvent) (Interactive, tea.Cmd)
	IsAcceptable  func(element Interactive, dragEvent DragEvent) bool

	OnDropEnterEvent   func(element Interactive, dropEvent DropEvent) (Interactive, tea.Cmd)
	OnDropHoverEvent   func(element Interactive, dropEvent DropEvent) (Interactive, tea.Cmd)
	OnDropLeaveEvent   func(element Interactive, dropEvent DropEvent) (Interactive, tea.Cmd)
	OnDropReleaseEvent func(element Interactive, dropEvent DropEvent) (Interactive, tea.Cmd)
	OnDropAcceptEvent  func(element Interactive, dropEvent DropEvent) (Interactive, tea.Cmd)
	OnDropDenyEvent    func(element Interactive, dropEvent DropEvent) (Interactive, tea.Cmd)

	AcceptedDropTypes []string
	EmitMessages      bool
}

* Drop Behaviour Handler

  • Interface for handling drop events and defining local and external event behaviours
  • Default emission behaviour for an event will not occur if a custom behavior is defined
  • Default behaviours do not emit hover events unless EmitMessage is set to true

func (*DropHandler) DefaultDropAccept

func (h *DropHandler) DefaultDropAccept(element Interactive, dragEvent DragEvent) (Interactive, tea.Cmd)

* Default Drop Accept

  • Sets an element's MouseInteraction IsBelowDrop property to false and IsValidDrop to false

func (*DropHandler) DefaultDropAcceptEvent

func (h *DropHandler) DefaultDropAcceptEvent(element Interactive, dropEvent DropEvent) (Interactive, tea.Cmd)

* Default Drop Accept

  • Sets an element's MouseInteraction IsAboveDrop property to false and IsValidDrop to false

func (*DropHandler) DefaultDropDeny

func (h *DropHandler) DefaultDropDeny(element Interactive, dragEvent DragEvent) (Interactive, tea.Cmd)

* Default Drop Deny

  • Sets an element's MouseInteraction IsBelowDrop property to false and IsValidDrop to false

func (*DropHandler) DefaultDropDenyEvent

func (h *DropHandler) DefaultDropDenyEvent(element Interactive, dropEvent DropEvent) (Interactive, tea.Cmd)

* Default Drop Deny

  • Sets an element's MouseInteraction IsAboveDrop property to false and IsValidDrop to false

func (*DropHandler) DefaultDropEnter

func (h *DropHandler) DefaultDropEnter(element Interactive, dragEvent DragEvent) (Interactive, tea.Cmd)

* Default Drop Enter

  • Sets an element's MouseInteraction IsBelowDrop property to true and IsValidDrop is determined

func (*DropHandler) DefaultDropEnterEvent

func (h *DropHandler) DefaultDropEnterEvent(element Interactive, dropEvent DropEvent) (Interactive, tea.Cmd)

* Default External Drop Enter

  • Sets an element's MouseInteraction IsAboveDrop property to true and IsValidDrop appropriately

func (*DropHandler) DefaultDropHover

func (h *DropHandler) DefaultDropHover(element Interactive, dragEvent DragEvent) (Interactive, tea.Cmd)

* Default Drop Hover

  • Sets an element's MouseInteraction IsBelowDrop property to true and IsValidDrop is determined

func (*DropHandler) DefaultDropHoverEvent

func (h *DropHandler) DefaultDropHoverEvent(element Interactive, dropEvent DropEvent) (Interactive, tea.Cmd)

* Default External Drop Hover

  • Sets an element's MouseInteraction IsAboveDrop property to true and IsValidDrop appropriately

func (*DropHandler) DefaultDropLeave

func (h *DropHandler) DefaultDropLeave(element Interactive, dragEvent DragEvent) (Interactive, tea.Cmd)

* Default Drop Leave

  • Sets an element's MouseInteraction IsBelowDrop property to false and IsValidDrop to false

func (*DropHandler) DefaultDropLeaveEvent

func (h *DropHandler) DefaultDropLeaveEvent(element Interactive, dropEvent DropEvent) (Interactive, tea.Cmd)

* Default External Drop Leave

  • Sets an element's MouseInteraction IsAboveDrop property to false and IsValidDrop appropriately

func (*DropHandler) DefaultDropRelease

func (h *DropHandler) DefaultDropRelease(element Interactive, dragEvent DragEvent) (Interactive, tea.Cmd)

* Default Drop Release

  • The element's MouseInteraction IsValidDrop is determined
  • Calls relevant accept or deny drop handler method

func (*DropHandler) DefaultDropReleaseEvent

func (h *DropHandler) DefaultDropReleaseEvent(element Interactive, dropEvent DropEvent) (Interactive, tea.Cmd)

* Default Drop Release

  • Sets an element's MouseInteraction IsAboveDrop property to false and IsValidDrop to false

func (*DropHandler) DefaultIsAcceptable

func (h *DropHandler) DefaultIsAcceptable(element Interactive, dragEvent DragEvent) bool

* Default Acceptable Drop Assessment

  • Returns true if the DragType is found within the accepted drop types list

func (*DropHandler) HandleDropAccept

func (h *DropHandler) HandleDropAccept(element Interactive, dragEvent DragEvent) (Interactive, tea.Cmd)

* Drop Accept Handler

  • Responds to localized drop accept events with OnDropAccept function or DefaultDropAccept if undefined

func (*DropHandler) HandleDropAcceptEvent

func (h *DropHandler) HandleDropAcceptEvent(element Interactive, dropEvent DropEvent) (Interactive, tea.Cmd)

* External Drop Accept Handler

  • Responds to external drop accept events with OnDropAcceptEvent function if defined

func (*DropHandler) HandleDropDeny

func (h *DropHandler) HandleDropDeny(element Interactive, dragEvent DragEvent) (Interactive, tea.Cmd)

* Drop Deny Handler

  • Responds to localized drop deny events with OnDropDeny function or DefaultDropDeny if undefined

func (*DropHandler) HandleDropDenyEvent

func (h *DropHandler) HandleDropDenyEvent(element Interactive, dropEvent DropEvent) (Interactive, tea.Cmd)

* External Drop Deny Handler

  • Responds to external drop deny events with OnDropDenyEvent function if defined

func (*DropHandler) HandleDropEnter

func (h *DropHandler) HandleDropEnter(element Interactive, dragEvent DragEvent) (Interactive, tea.Cmd)

* Drop Enter Handler

  • Responds to localized drop enter events with OnDropEnter function or DefaultDropEnter if undefined

func (*DropHandler) HandleDropEnterEvent

func (h *DropHandler) HandleDropEnterEvent(element Interactive, dropEvent DropEvent) (Interactive, tea.Cmd)

* External Drop Enter Handler

  • Responds to external drop enter events with OnDropEnterEvent function if defined

func (*DropHandler) HandleDropHover

func (h *DropHandler) HandleDropHover(element Interactive, dragEvent DragEvent) (Interactive, tea.Cmd)

* Drop Hover Handler

  • Responds to localized drop hover events with OnDropHover function or DefaultDropHover if undefined

func (*DropHandler) HandleDropHoverEvent

func (h *DropHandler) HandleDropHoverEvent(element Interactive, dropEvent DropEvent) (Interactive, tea.Cmd)

* External Drop Hover Handler

  • Responds to external drop hover events with OnDropHoverEvent function if defined

func (*DropHandler) HandleDropLeave

func (h *DropHandler) HandleDropLeave(element Interactive, dragEvent DragEvent) (Interactive, tea.Cmd)

* Drop Leave Handler

  • Responds to localized drop leave events with OnDropLeave function or DefaultDropLeave if undefined

func (*DropHandler) HandleDropLeaveEvent

func (h *DropHandler) HandleDropLeaveEvent(element Interactive, dropEvent DropEvent) (Interactive, tea.Cmd)

* External Drop Leave Handler

  • Responds to external drop leave events with OnDropLeaveEvent function if defined

func (*DropHandler) HandleDropRelease

func (h *DropHandler) HandleDropRelease(element Interactive, dragEvent DragEvent) (Interactive, tea.Cmd)

* Drop Release Handler

  • Responds to localized drop release events with OnDropRelease function or DefaultDropRelease if undefined

func (*DropHandler) HandleDropReleaseEvent

func (h *DropHandler) HandleDropReleaseEvent(element Interactive, dropEvent DropEvent) (Interactive, tea.Cmd)

* External Drop Release Handler

  • Responds to external drop release events with OnDropReleaseEvent function if defined

func (*DropHandler) HandleIsAcceptable

func (h *DropHandler) HandleIsAcceptable(element Interactive, dragEvent DragEvent) bool

* Acceptable Drop Assessment Handler

  • Responds to acceptable drop assessments with IsAcceptable function or DefaultIsAcceptable if undefined

type Droppable

type Droppable interface {
	HandleIsAcceptable(element Interactive, dragEvent DragEvent) bool

	HandleDropEnter(element Interactive, dragEvent DragEvent) (Interactive, tea.Cmd)
	HandleDropHover(element Interactive, dragEvent DragEvent) (Interactive, tea.Cmd)
	HandleDropLeave(element Interactive, dragEvent DragEvent) (Interactive, tea.Cmd)
	HandleDropRelease(element Interactive, dragEvent DragEvent) (Interactive, tea.Cmd)
	HandleDropAccept(element Interactive, dragEvent DragEvent) (Interactive, tea.Cmd)
	HandleDropDeny(element Interactive, dragEvent DragEvent) (Interactive, tea.Cmd)
}

* Droppable Interface

  • Interface definition for handling localized drop interactions

type HoverEvent

type HoverEvent struct {
	ID        string
	EventType HoverEventType
	MouseMsg  tea.MouseMsg
}

* Hover Events

  • Hover event messages to enable responses to external interactions
  • Default behaviours will broadcast if EmitMessages is set to true

type HoverEventAware

type HoverEventAware interface {
	HandleMouseEnterEvent(element Interactive, hoverEvent HoverEvent) (Interactive, tea.Cmd)
	HandleMouseHoverEvent(element Interactive, hoverEvent HoverEvent) (Interactive, tea.Cmd)
	HandleMouseLeaveEvent(element Interactive, hoverEvent HoverEvent) (Interactive, tea.Cmd)
}

* Hover Event Aware Interface

  • Interface definition for handling localized hover interactions

type HoverEventType

type HoverEventType int

* Hover Event Types

  • Enum for providing context to HoverEvent messages
const (
	MouseEnter HoverEventType = iota
	MouseHover
	MouseLeave
)

type HoverHandler

type HoverHandler struct {
	OnMouseEnter func(element Interactive, mouseMsg tea.MouseMsg) (Interactive, tea.Cmd)
	OnMouseHover func(element Interactive, mouseMsg tea.MouseMsg) (Interactive, tea.Cmd)
	OnMouseLeave func(element Interactive, mouseMsg tea.MouseMsg) (Interactive, tea.Cmd)

	OnMouseEnterEvent func(element Interactive, hoverEvent HoverEvent) (Interactive, tea.Cmd)
	OnMouseHoverEvent func(element Interactive, hoverEvent HoverEvent) (Interactive, tea.Cmd)
	OnMouseLeaveEvent func(element Interactive, hoverEvent HoverEvent) (Interactive, tea.Cmd)

	EmitMessages bool
}

* Hover Behaviour Handler

  • Interface for handling hover events and defining local and external event behaviours
  • Default emission behaviour for an event will not occur if a custom behavior is defined
  • Default behaviours do not emit hover events unless EmitMessage is set to true

func (*HoverHandler) DefaultMouseEnter

func (h *HoverHandler) DefaultMouseEnter(element Interactive, mouseMsg tea.MouseMsg) (Interactive, tea.Cmd)

* Default Mouse Enter Behaviour

  • Sets an element's MouseInteraction IsHovered property to true

func (*HoverHandler) DefaultMouseHover

func (h *HoverHandler) DefaultMouseHover(element Interactive, mouseMsg tea.MouseMsg) (Interactive, tea.Cmd)

* Default Mouse Enter Behaviour

  • Sets an element's MouseInteraction IsHovered property to true

func (*HoverHandler) DefaultMouseLeave

func (h *HoverHandler) DefaultMouseLeave(element Interactive, mouseMsg tea.MouseMsg) (Interactive, tea.Cmd)

* Default Mouse Leave Behaviour

  • Sets an element's MouseInteraction IsHovered property to false

func (*HoverHandler) HandleMouseEnter

func (h *HoverHandler) HandleMouseEnter(element Interactive, mouseMsg tea.MouseMsg) (Interactive, tea.Cmd)

* Mouse Enter Handler

  • Responds to localized mouse enter events with OnMouseEnter function or DefaultMouseEnter if undefined

func (*HoverHandler) HandleMouseEnterEvent

func (h *HoverHandler) HandleMouseEnterEvent(element Interactive, hoverEvent HoverEvent) (Interactive, tea.Cmd)

* External Mouse Enter Handler

  • Responds to external mouse enter events with OnMouseEnterEvent function if defined
  • No default behaviour is defined for responding to external mouse enter events

func (*HoverHandler) HandleMouseHover

func (h *HoverHandler) HandleMouseHover(element Interactive, mouseMsg tea.MouseMsg) (Interactive, tea.Cmd)

* Mouse Enter Handler

  • Responds to localized mouse hover events with OnMouseHover function or DefaultMouseHover if undefined

func (*HoverHandler) HandleMouseHoverEvent

func (h *HoverHandler) HandleMouseHoverEvent(element Interactive, hoverEvent HoverEvent) (Interactive, tea.Cmd)

* External Mouse Hover Handler

  • Responds to external mouse hover events with OnMouseHoverEvent function if defined
  • No default behaviour is defined for responding to external mouse hover events

func (*HoverHandler) HandleMouseLeave

func (h *HoverHandler) HandleMouseLeave(element Interactive, mouseMsg tea.MouseMsg) (Interactive, tea.Cmd)

* Mouse Leave Handler

  • Responds to localized mouse leaving events with OnMouseLeave function or DefaultMouseLeave if undefined

func (*HoverHandler) HandleMouseLeaveEvent

func (h *HoverHandler) HandleMouseLeaveEvent(element Interactive, hoverEvent HoverEvent) (Interactive, tea.Cmd)

* External Mouse Leave Handler

  • Responds to external mouse leave events with OnMouseLeaveEvent function if defined
  • No default behaviour is defined for responding to external mouse leave events

type Hoverable

type Hoverable interface {
	HandleMouseEnter(element Interactive, mouseMsg tea.MouseMsg) (Interactive, tea.Cmd)
	HandleMouseHover(element Interactive, mouseMsg tea.MouseMsg) (Interactive, tea.Cmd)
	HandleMouseLeave(element Interactive, mouseMsg tea.MouseMsg) (Interactive, tea.Cmd)
}

* Hoverable Interface

  • Interface definition for handling localized hover interactions

type Interactable

type Interactable struct {
	ID string

	LastClickTime        time.Time
	DoubleClickThreshold time.Duration
	ClickCount           int
	IsSelected           bool
	IsHovered            bool
	IsDragging           bool
	DragOrigin           struct{ X, Y int }
	DragOffset           struct{ X, Y int }
	IsValidDrop          bool
	IsAboveDrop          bool
	IsBelowDrop          bool

	Click Clickable
	Hover Hoverable
	Drag  Draggable
	Drop  Droppable

	ClickEvent ClickEventAware
	HoverEvent HoverEventAware
	DragEvent  DragEventAware
	DropEvent  DropEventAware

	IsInside        func(element Interactive, mouseMsg tea.Msg) bool
	LocalHandler    func(element Interactive, msg tea.Msg) (Interactive, tea.Cmd)
	ExternalHandler func(element Interactive, msg tea.Msg) (Interactive, tea.Cmd)
}

* Mouse Interaction

  • Defines and handles mouse interaction of and between elements.

func (*Interactable) DefaultExternalHandler

func (i *Interactable) DefaultExternalHandler(element Interactive, msg tea.Msg) (Interactive, tea.Cmd)

* External Event Handling

  • Interprets external event messages to direct the appropriate interaction handlers

func (Interactable) DefaultIsInside

func (i Interactable) DefaultIsInside(element Interactive, mouseMsg tea.MouseMsg) bool

func (*Interactable) DefaultLocalHandler

func (i *Interactable) DefaultLocalHandler(element Interactive, mouseMsg tea.MouseMsg) (Interactive, tea.Cmd)

* Default Local Handler

  • Default implementation of interpretting mouse messages to direct the appropriate interaction handlers

func (*Interactable) HandleExternalEvent

func (i *Interactable) HandleExternalEvent(element Interactive, mouseMsg tea.MouseMsg) (Interactive, tea.Cmd)

* External Event Handling

  • Responds to external event messages with ExternalHandler function or DefaultExternalHandler if it is not defined

func (*Interactable) HandleMouseMsg

func (i *Interactable) HandleMouseMsg(element Interactive, mouseMsg tea.MouseMsg) (Interactive, tea.Cmd)

* Mouse Message Handling

  • Responds to mouse messages with LocalHandler function or DefaultLocalHandler if it is not defined

type Interactive

type Interactive interface {
	GetInteraction() *Interactable
}

* Interactive Interface

  • Interface definition for defining an element as interactive

type Point

type Point struct {
	X, Y int
}

* Point Type

  • Helper struct for easily defining a coordinate pair

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL