event/config: add Orientation

There are several variations on orientation. iOS expposes a little
more orientation information through its basic enum than Android
does, but the more powerful Android API gives you degrees around a
circle, which while strictly more powerful, doesn't tell you easily
where the status bar is.

What I'm thinking with this is the primary use of an orientation
concept is to decide whether or not to lay out a UI for a wide screen.
This gives you that.

Later I hope the sensor API will give far more information about the
physical orientation of the device.

Change-Id: I00ff598853c7ed618cde266729d8d05e1a02a601
Reviewed-on: https://go-review.googlesource.com/13361
Reviewed-by: Nigel Tao <nigeltao@golang.org>
This commit is contained in:
David Crawshaw 2015-08-07 10:08:04 -04:00
parent fa69a4e270
commit 51384a9898
1 changed files with 33 additions and 0 deletions

View File

@ -30,6 +30,9 @@ type Event struct {
// tablets, so apps should be written to expect various non-integer
// PixelsPerPt values. In general, work in geom.Pt.
PixelsPerPt float32
// Orientation is the orientation of the device screen.
Orientation Orientation
}
// Bounds returns the window's bounds in pixels, at the time this configuration
@ -40,3 +43,33 @@ type Event struct {
func (e *Event) Bounds() image.Rectangle {
return image.Rectangle{Max: image.Point{e.WidthPx, e.HeightPx}}
}
// Orientation is the orientation of the device screen.
type Orientation int
const (
// OrientationUnknown means device orientation cannot be determined.
//
// Equivalent on Android to Configuration.ORIENTATION_UNKNOWN
// and on iOS to:
// UIDeviceOrientationUnknown
// UIDeviceOrientationFaceUp
// UIDeviceOrientationFaceDown
OrientationUnknown Orientation = iota
// OrientationPortrait is a device oriented so it is tall and thin.
//
// Equivalent on Android to Configuration.ORIENTATION_PORTRAIT
// and on iOS to:
// UIDeviceOrientationPortrait
// UIDeviceOrientationPortraitUpsideDown
OrientationPortrait
// OrientationLandscape is a device oriented so it is short and wide.
//
// Equivalent on Android to Configuration.ORIENTATION_LANDSCAPE
// and on iOS to:
// UIDeviceOrientationLandscapeLeft
// UIDeviceOrientationLandscapeRight
OrientationLandscape
)