device.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. package fyne
  2. // DeviceOrientation represents the different ways that a mobile device can be held
  3. type DeviceOrientation int
  4. const (
  5. // OrientationVertical is the default vertical orientation
  6. OrientationVertical DeviceOrientation = iota
  7. // OrientationVerticalUpsideDown is the portrait orientation held upside down
  8. OrientationVerticalUpsideDown
  9. // OrientationHorizontalLeft is used to indicate a landscape orientation with the top to the left
  10. OrientationHorizontalLeft
  11. // OrientationHorizontalRight is used to indicate a landscape orientation with the top to the right
  12. OrientationHorizontalRight
  13. )
  14. // IsVertical is a helper utility that determines if a passed orientation is vertical
  15. func IsVertical(orient DeviceOrientation) bool {
  16. return orient == OrientationVertical || orient == OrientationVerticalUpsideDown
  17. }
  18. // IsHorizontal is a helper utility that determines if a passed orientation is horizontal
  19. func IsHorizontal(orient DeviceOrientation) bool {
  20. return !IsVertical(orient)
  21. }
  22. // Device provides information about the devices the code is running on
  23. type Device interface {
  24. Orientation() DeviceOrientation
  25. IsMobile() bool
  26. IsBrowser() bool
  27. HasKeyboard() bool
  28. SystemScaleForWindow(Window) float32
  29. }
  30. // CurrentDevice returns the device information for the current hardware (via the driver)
  31. func CurrentDevice() Device {
  32. return CurrentApp().Driver().Device()
  33. }