github.com/Seikaijyu/gio@v0.0.1/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/Seikaijyu/gio/io/event"
    12  	"github.com/Seikaijyu/gio/op"
    13  	"github.com/Seikaijyu/gio/unit"
    14  )
    15  
    16  // A FrameEvent requests a new frame in the form of a list of
    17  // operations that describes what to display and how to handle
    18  // input.
    19  type FrameEvent struct {
    20  	// Now is the current animation. Use Now instead of time.Now to
    21  	// synchronize animation and to avoid the time.Now call overhead.
    22  	Now time.Time
    23  	// Metric converts device independent dp and sp to device pixels.
    24  	Metric unit.Metric
    25  	// Size is the dimensions of the window.
    26  	Size image.Point
    27  	// Insets represent the space occupied by system decorations and controls.
    28  	Insets Insets
    29  	// Frame completes the FrameEvent by drawing the graphical operations
    30  	// from ops into the window.
    31  	Frame func(frame *op.Ops)
    32  	// Queue supplies the events for event handlers.
    33  	Queue event.Queue
    34  }
    35  
    36  // DestroyEvent is the last event sent through
    37  // a window event channel.
    38  type DestroyEvent struct {
    39  	// Err is nil for normal window closures. If a
    40  	// window is prematurely closed, Err is the cause.
    41  	Err error
    42  }
    43  
    44  // Insets is the space taken up by
    45  // system decoration such as translucent
    46  // system bars and software keyboards.
    47  type Insets struct {
    48  	// Values are in pixels.
    49  	Top, Bottom, Left, Right unit.Dp
    50  }
    51  
    52  // A StageEvent is generated whenever the stage of a
    53  // Window changes.
    54  type StageEvent struct {
    55  	Stage Stage
    56  }
    57  
    58  // Stage of a Window.
    59  type Stage uint8
    60  
    61  const (
    62  	// StagePaused is the stage for windows that have no on-screen representation.
    63  	// Paused windows don't receive FrameEvent.
    64  	StagePaused Stage = iota
    65  	// StageInactive is the stage for windows that are visible, but not active.
    66  	// Inactive windows receive FrameEvent.
    67  	StageInactive
    68  	// StageRunning is for active and visible Windows.
    69  	// Running windows receive FrameEvent.
    70  	StageRunning
    71  )
    72  
    73  // String implements fmt.Stringer.
    74  func (l Stage) String() string {
    75  	switch l {
    76  	case StagePaused:
    77  		return "StagePaused"
    78  	case StageInactive:
    79  		return "StageInactive"
    80  	case StageRunning:
    81  		return "StageRunning"
    82  	default:
    83  		panic("unexpected Stage value")
    84  	}
    85  }
    86  
    87  func (FrameEvent) ImplementsEvent()   {}
    88  func (StageEvent) ImplementsEvent()   {}
    89  func (DestroyEvent) ImplementsEvent() {}