event

package
v0.0.0-...-e111b83 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2015 License: BSD-3-Clause Imports: 1 Imported by: 0

Documentation

Overview

Package event provides classes and interfaces to implement event senders and receivers.

There are also some types of events, but these only serve as examples and are not thought through.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CloseEvt

type CloseEvt struct {
	Evt
}

A CloseEvt is sent before the window is closed, so that a user may take some action before it is closed finally.

type Command

type Command struct {
	Command string
	Sender  string
}

Command represents any kind of user command, for example a button click.

func (*Command) String

func (c *Command) String() string

type ConfigEvt

type ConfigEvt struct {
	Evt
	Dx int
	Dy int
}

type DisplayRequest

type DisplayRequest struct {
	Sender string
}

DisplayRequest is an event that is sended, whenever a widget wants to be displayed on the screen. In most cases this would be to update it's representation.

func (*DisplayRequest) String

func (d *DisplayRequest) String() string

type Event

type Event interface {
	// Sender of the event. This is implemented as a string,
	// because it's great for debugging and possible network
	// implementations.
	Sender() string
}

Event is the basic interface for all events.

type Evt

type Evt struct {
	SenderId string
}

Evt is an implementation of the event interface. It's main purpose is to simplify the creation of other types of events.

func (Evt) Sender

func (evt Evt) Sender() string

type ExposeEvt

type ExposeEvt struct {
	Evt
	Dx int
	Dy int
}

An ExposeEvt is sent when the window is shown to the user (open window, resize, show after hide).

type PointerEvt

type PointerEvt struct {
	Evt
	Type  PointerEvtType
	State PointerState
	X     int
	Y     int
}

PointerEvt represents a typical pointer event. The idea is that a programmer should not worry about what kind of pointer device is being used. When thinking of pointers the mouse immediately comes to the mind of most people, but there are many other kinds of pointer devices:

  • Human finger
  • Foot mouse
  • Graphics tablet
  • Trackball
  • Roll bar mouse
  • Eye tracker
  • Remote control for smart TV
  • Electronic gun in combat simulation area.

Unfortunately there are always some clever programmers around who try to utilize mouse events for special purposes. This often messes up user experience for non mouse users. The result may be some poor pilot shooting down a jumbo jet by accident.

type PointerEvtType

type PointerEvtType int
const (
	PointerMoveEvt PointerEvtType = iota
	PointerTouchEvt
	PointerUntouchEvt
)

type PointerState

type PointerState int
const (
	PointerStateNone PointerState = iota
	PointerStateTouch
)

type Receiver

type Receiver interface {
	ListenTo(sender Sender)
	UnlistenTo(sender Sender)
	ReceiveEvent(evt interface{})
	SetEvtHandler(handler func(evt interface{}))
	SetEvtChanHandler(handler func(evtChan <-chan interface{}))
}

Receiver is the basic interface that every event receiver must satisfy.

Received events are handled by an event handler function, that gets the events directly through it's argument, or through a channel of events.

func NewReceiver

func NewReceiver() Receiver

func NewReceiverFor

func NewReceiverFor(sender Sender) Receiver

type Sender

type Sender interface {
	SendEvent(evt interface{})
	AddReceiver(receiver Receiver)
	RemoveReceiver(receiver Receiver)
}

Sender is the basic interface that every event sender must satisfy.

An event sender should be able to send events to arbritrary numbers of event receivers.

func NewSender

func NewSender() Sender

Jump to

Keyboard shortcuts

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