github.com/c-darwin/mobile@v0.0.0-20160313183840-ff625c46f7c9/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 github.com/c-darwin/mobile/app package for details on the event model. 9 package size // import "github.com/c-darwin/mobile/event/size" 10 11 import ( 12 "image" 13 14 "github.com/c-darwin/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 github.com/c-darwin/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 // Bounds returns the window's bounds in pixels, at the time this size event 40 // was sent. 41 // 42 // The top-left pixel is always (0, 0). The bottom-right pixel is given by the 43 // width and height. 44 func (e *Event) Bounds() image.Rectangle { 45 return image.Rectangle{Max: image.Point{e.WidthPx, e.HeightPx}} 46 } 47 48 // Orientation is the orientation of the device screen. 49 type Orientation int 50 51 const ( 52 // OrientationUnknown means device orientation cannot be determined. 53 // 54 // Equivalent on Android to Configuration.ORIENTATION_UNKNOWN 55 // and on iOS to: 56 // UIDeviceOrientationUnknown 57 // UIDeviceOrientationFaceUp 58 // UIDeviceOrientationFaceDown 59 OrientationUnknown Orientation = iota 60 61 // OrientationPortrait is a device oriented so it is tall and thin. 62 // 63 // Equivalent on Android to Configuration.ORIENTATION_PORTRAIT 64 // and on iOS to: 65 // UIDeviceOrientationPortrait 66 // UIDeviceOrientationPortraitUpsideDown 67 OrientationPortrait 68 69 // OrientationLandscape is a device oriented so it is short and wide. 70 // 71 // Equivalent on Android to Configuration.ORIENTATION_LANDSCAPE 72 // and on iOS to: 73 // UIDeviceOrientationLandscapeLeft 74 // UIDeviceOrientationLandscapeRight 75 OrientationLandscape 76 )