github.com/Seikaijyu/gio@v0.0.1/io/event/event.go (about)

     1  // SPDX-License-Identifier: Unlicense OR MIT
     2  
     3  /*
     4  Package event contains the types for event handling.
     5  
     6  The Queue interface is the protocol for receiving external events.
     7  
     8  For example:
     9  
    10  	var queue event.Queue = ...
    11  
    12  	for _, e := range queue.Events(h) {
    13  		switch e.(type) {
    14  			...
    15  		}
    16  	}
    17  
    18  In general, handlers must be declared before events become
    19  available. Other packages such as pointer and key provide
    20  the means for declaring handlers for specific event types.
    21  
    22  The following example declares a handler ready for key input:
    23  
    24  	import github.com/Seikaijyu/gio/io/key
    25  
    26  	ops := new(op.Ops)
    27  	var h *Handler = ...
    28  	key.InputOp{Tag: h, Filter: ...}.Add(ops)
    29  */
    30  package event
    31  
    32  // Queue maps an event handler key to the events
    33  // available to the handler.
    34  type Queue interface {
    35  	// Events returns the available events for an
    36  	// event handler tag.
    37  	Events(t Tag) []Event
    38  }
    39  
    40  // Tag is the stable identifier for an event handler.
    41  // For a handler h, the tag is typically &h.
    42  type Tag interface{}
    43  
    44  // Event is the marker interface for events.
    45  type Event interface {
    46  	ImplementsEvent()
    47  }