github.com/gop9/olt@v0.0.0-20200202132135-d956aad50b08/gio/io/system/system.go (about)

     1  // SPDX-License-Identifier: Unlicense OR MIT
     2  
     3  // Package system contains events usually handled at the top-level
     4  // program level.
     5  package system
     6  
     7  import (
     8  	"image"
     9  	"time"
    10  
    11  	"github.com/gop9/olt/gio/op"
    12  	"github.com/gop9/olt/gio/unit"
    13  )
    14  
    15  // A FrameEvent asks for a new frame in the form of a list of
    16  // operations.
    17  type FrameEvent struct {
    18  	Config Config
    19  	// Size is the dimensions of the window.
    20  	Size image.Point
    21  	// Insets is the insets to apply.
    22  	Insets Insets
    23  	// Frame replaces the window's frame with the new
    24  	// frame.
    25  	Frame func(frame *op.Ops)
    26  	// Whether this draw is system generated and needs a complete
    27  	// frame before proceeding.
    28  	sync bool
    29  }
    30  
    31  // Config defines the essential properties of
    32  // the environment.
    33  type Config interface {
    34  	// Now returns the current animation time.
    35  	Now() time.Time
    36  
    37  	unit.Converter
    38  }
    39  
    40  // DestroyEvent is the last event sent through
    41  // a window event channel.
    42  type DestroyEvent struct {
    43  	// Err is nil for normal window closures. If a
    44  	// window is prematurely closed, Err is the cause.
    45  	Err error
    46  }
    47  
    48  // Insets is the space taken up by
    49  // system decoration such as translucent
    50  // system bars and software keyboards.
    51  type Insets struct {
    52  	Top, Bottom, Left, Right unit.Value
    53  }
    54  
    55  // A StageEvent is generated whenever the stage of a
    56  // Window changes.
    57  type StageEvent struct {
    58  	Stage Stage
    59  }
    60  
    61  // CommandEvent is a system event.
    62  type CommandEvent struct {
    63  	Type CommandType
    64  	// Suppress the default action of the command.
    65  	Cancel bool
    66  }
    67  
    68  // Stage of a Window.
    69  type Stage uint8
    70  
    71  // CommandType is the type of a CommandEvent.
    72  type CommandType uint8
    73  
    74  const (
    75  	// StagePaused is the Stage for inactive Windows.
    76  	// Inactive Windows don't receive FrameEvents.
    77  	StagePaused Stage = iota
    78  	// StateRunning is for active Windows.
    79  	StageRunning
    80  )
    81  
    82  const (
    83  	// CommandBack is the command for a back action
    84  	// such as the Android back button.
    85  	CommandBack CommandType = iota
    86  )
    87  
    88  func (l Stage) String() string {
    89  	switch l {
    90  	case StagePaused:
    91  		return "StagePaused"
    92  	case StageRunning:
    93  		return "StageRunning"
    94  	default:
    95  		panic("unexpected Stage value")
    96  	}
    97  }
    98  
    99  func (_ FrameEvent) ImplementsEvent()    {}
   100  func (_ StageEvent) ImplementsEvent()    {}
   101  func (_ *CommandEvent) ImplementsEvent() {}
   102  func (_ DestroyEvent) ImplementsEvent()  {}