github.com/gop9/olt@v0.0.0-20200202132135-d956aad50b08/gio/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 gioui.org/io/key
    25  
    26  	ops := new(op.Ops)
    27  	var h *Handler = ...
    28  	key.InputOp{Key: h}.Add(ops)
    29  
    30  */
    31  package event
    32  
    33  // Queue maps an event handler key to the events
    34  // available to the handler.
    35  type Queue interface {
    36  	// Events returns the available events for a
    37  	// Key.
    38  	Events(k Key) []Event
    39  }
    40  
    41  // Key is the stable identifier for an event handler.
    42  // For a handler h, the key is typically &h.
    43  type Key interface{}
    44  
    45  // Event is the marker interface for events.
    46  type Event interface {
    47  	ImplementsEvent()
    48  }