github.com/graybobo/golang.org-package-offline-cache@v0.0.0-20200626051047-6608995c132f/x/mobile/event/size/size.go (about)

     1  // Copyright 2015 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  // Package size defines an event for the dimensions, physical resolution and
     6  // orientation of the app's window.
     7  //
     8  // See the golang.org/x/mobile/app package for details on the event model.
     9  package size // import "golang.org/x/mobile/event/size"
    10  
    11  import (
    12  	"image"
    13  
    14  	"golang.org/x/mobile/geom"
    15  )
    16  
    17  // Event holds the dimensions, physical resolution and orientation of the app's
    18  // window.
    19  type Event struct {
    20  	// WidthPx and HeightPx are the window's dimensions in pixels.
    21  	WidthPx, HeightPx int
    22  
    23  	// WidthPt and HeightPt are the window's dimensions in points (1/72 of an
    24  	// inch).
    25  	WidthPt, HeightPt geom.Pt
    26  
    27  	// PixelsPerPt is the window's physical resolution. It is the number of
    28  	// pixels in a single geom.Pt, from the golang.org/x/mobile/geom package.
    29  	//
    30  	// There are a wide variety of pixel densities in existing phones and
    31  	// tablets, so apps should be written to expect various non-integer
    32  	// PixelsPerPt values. In general, work in geom.Pt.
    33  	PixelsPerPt float32
    34  
    35  	// Orientation is the orientation of the device screen.
    36  	Orientation Orientation
    37  }
    38  
    39  // Size returns the window's size in pixels, at the time this size event was
    40  // sent.
    41  func (e *Event) Size() image.Point {
    42  	return image.Point{e.WidthPx, e.HeightPx}
    43  }
    44  
    45  // Bounds returns the window's bounds in pixels, at the time this size event
    46  // was sent.
    47  //
    48  // The top-left pixel is always (0, 0). The bottom-right pixel is given by the
    49  // width and height.
    50  func (e *Event) Bounds() image.Rectangle {
    51  	return image.Rectangle{Max: image.Point{e.WidthPx, e.HeightPx}}
    52  }
    53  
    54  // Orientation is the orientation of the device screen.
    55  type Orientation int
    56  
    57  const (
    58  	// OrientationUnknown means device orientation cannot be determined.
    59  	//
    60  	// Equivalent on Android to Configuration.ORIENTATION_UNKNOWN
    61  	// and on iOS to:
    62  	//	UIDeviceOrientationUnknown
    63  	//	UIDeviceOrientationFaceUp
    64  	//	UIDeviceOrientationFaceDown
    65  	OrientationUnknown Orientation = iota
    66  
    67  	// OrientationPortrait is a device oriented so it is tall and thin.
    68  	//
    69  	// Equivalent on Android to Configuration.ORIENTATION_PORTRAIT
    70  	// and on iOS to:
    71  	//	UIDeviceOrientationPortrait
    72  	//	UIDeviceOrientationPortraitUpsideDown
    73  	OrientationPortrait
    74  
    75  	// OrientationLandscape is a device oriented so it is short and wide.
    76  	//
    77  	// Equivalent on Android to Configuration.ORIENTATION_LANDSCAPE
    78  	// and on iOS to:
    79  	//	UIDeviceOrientationLandscapeLeft
    80  	//	UIDeviceOrientationLandscapeRight
    81  	OrientationLandscape
    82  )