| 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 sizescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/event/size`/ |
| 10 | |
| 11 | import ( |
| 12 | "imagescip-go gomod github.com/golang/go/src go1.24.0 image/" |
| 13 | |
| 14 | "golang.org/x/mobile/geomscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/geom`/" |
| 15 | ) |
| 16 | |
| 17 | // Event holds the dimensions, physical resolution and orientation of the app's |
| 18 | // window. |
| 19 | type Eventscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/event/size`/Event# struct { |
| 20 | // WidthPx and HeightPx are the window's dimensions in pixels. |
| 21 | WidthPxscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/event/size`/Event#WidthPx., HeightPxscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/event/size`/Event#HeightPx. int |
| 22 | |
| 23 | // WidthPt and HeightPt are the window's physical dimensions in points |
| 24 | // (1/72 of an inch). |
| 25 | // |
| 26 | // The values are based on PixelsPerPt and are therefore approximate, as |
| 27 | // per the comment on PixelsPerPt. |
| 28 | WidthPtscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/event/size`/Event#WidthPt., HeightPtscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/event/size`/Event#HeightPt. geomscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/geom`/.Ptscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/geom`/Pt# |
| 29 | |
| 30 | // PixelsPerPt is the window's physical resolution. It is the number of |
| 31 | // pixels in a single geom.Pt, from the golang.org/x/mobile/geom package. |
| 32 | // |
| 33 | // There are a wide variety of pixel densities in existing phones and |
| 34 | // tablets, so apps should be written to expect various non-integer |
| 35 | // PixelsPerPt values. In general, work in geom.Pt. |
| 36 | // |
| 37 | // The value is approximate, in that the OS, drivers or hardware may report |
| 38 | // approximate or quantized values. An N x N pixel square should be roughly |
| 39 | // 1 square inch for N = int(PixelsPerPt * 72), although different square |
| 40 | // lengths (in pixels) might be closer to 1 inch in practice. Nonetheless, |
| 41 | // this PixelsPerPt value should be consistent with e.g. the ratio of |
| 42 | // WidthPx to WidthPt. |
| 43 | PixelsPerPtscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/event/size`/Event#PixelsPerPt. float32 |
| 44 | |
| 45 | // Orientation is the orientation of the device screen. |
| 46 | Orientationscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/event/size`/Event#Orientation. Orientationscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/event/size`/Orientation# |
| 47 | } |
| 48 | |
| 49 | // Size returns the window's size in pixels, at the time this size event was |
| 50 | // sent. |
| 51 | func (e Eventscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/event/size`/Event#) Sizescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/event/size`/Event#Size().() imagescip-go gomod github.com/golang/go/src go1.24.0 image/.Pointscip-go gomod github.com/golang/go/src go1.24.0 image/Point# { |
| 52 | return imagescip-go gomod github.com/golang/go/src go1.24.0 image/.Pointscip-go gomod github.com/golang/go/src go1.24.0 image/Point#{e.WidthPxscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/event/size`/Event#WidthPx., e.HeightPxscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/event/size`/Event#HeightPx.} |
| 53 | } |
| 54 | |
| 55 | // Bounds returns the window's bounds in pixels, at the time this size event |
| 56 | // was sent. |
| 57 | // |
| 58 | // The top-left pixel is always (0, 0). The bottom-right pixel is given by the |
| 59 | // width and height. |
| 60 | func (e Eventscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/event/size`/Event#) Boundsscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/event/size`/Event#Bounds().() imagescip-go gomod github.com/golang/go/src go1.24.0 image/.Rectanglescip-go gomod github.com/golang/go/src go1.24.0 image/Rectangle# { |
| 61 | return imagescip-go gomod github.com/golang/go/src go1.24.0 image/.Rectanglescip-go gomod github.com/golang/go/src go1.24.0 image/Rectangle#{Maxscip-go gomod github.com/golang/go/src go1.24.0 image/Rectangle#Max.: imagescip-go gomod github.com/golang/go/src go1.24.0 image/.Pointscip-go gomod github.com/golang/go/src go1.24.0 image/Point#{e.WidthPxscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/event/size`/Event#WidthPx., e.HeightPxscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/event/size`/Event#HeightPx.}} |
| 62 | } |
| 63 | |
| 64 | // Orientation is the orientation of the device screen. |
| 65 | type Orientationscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/event/size`/Orientation# int |
| 66 | |
| 67 | const ( |
| 68 | // OrientationUnknown means device orientation cannot be determined. |
| 69 | // |
| 70 | // Equivalent on Android to Configuration.ORIENTATION_UNKNOWN |
| 71 | // and on iOS to: |
| 72 | // UIDeviceOrientationUnknown |
| 73 | // UIDeviceOrientationFaceUp |
| 74 | // UIDeviceOrientationFaceDown |
| 75 | OrientationUnknownscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/event/size`/OrientationUnknown. Orientationscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/event/size`/Orientation# = iota |
| 76 | |
| 77 | // OrientationPortrait is a device oriented so it is tall and thin. |
| 78 | // |
| 79 | // Equivalent on Android to Configuration.ORIENTATION_PORTRAIT |
| 80 | // and on iOS to: |
| 81 | // UIDeviceOrientationPortrait |
| 82 | // UIDeviceOrientationPortraitUpsideDown |
| 83 | OrientationPortraitscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/event/size`/OrientationPortrait. |
| 84 | |
| 85 | // OrientationLandscape is a device oriented so it is short and wide. |
| 86 | // |
| 87 | // Equivalent on Android to Configuration.ORIENTATION_LANDSCAPE |
| 88 | // and on iOS to: |
| 89 | // UIDeviceOrientationLandscapeLeft |
| 90 | // UIDeviceOrientationLandscapeRight |
| 91 | OrientationLandscapescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/event/size`/OrientationLandscape. |
| 92 | ) |