decoration.go 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. package system
  2. import (
  3. "strings"
  4. "gioui.org/internal/ops"
  5. "gioui.org/op"
  6. )
  7. // ActionAreaOp makes the current clip area available for
  8. // system gestures.
  9. //
  10. // Note: only ActionMove is supported.
  11. type ActionInputOp Action
  12. // Action is a set of window decoration actions.
  13. type Action uint
  14. const (
  15. // ActionMinimize minimizes a window.
  16. ActionMinimize Action = 1 << iota
  17. // ActionMaximize maximizes a window.
  18. ActionMaximize
  19. // ActionUnmaximize restores a maximized window.
  20. ActionUnmaximize
  21. // ActionFullscreen makes a window fullscreen.
  22. ActionFullscreen
  23. // ActionRaise requests that the platform bring this window to the top of all open windows.
  24. // Some platforms do not allow this except under certain circumstances, such as when
  25. // a window from the same application already has focus. If the platform does not
  26. // support it, this method will do nothing.
  27. ActionRaise
  28. // ActionCenter centers the window on the screen.
  29. // It is ignored in Fullscreen mode and on Wayland.
  30. ActionCenter
  31. // ActionClose closes a window.
  32. // Only applicable on macOS, Windows, X11 and Wayland.
  33. ActionClose
  34. // ActionMove moves a window directed by the user.
  35. ActionMove
  36. )
  37. func (op ActionInputOp) Add(o *op.Ops) {
  38. data := ops.Write(&o.Internal, ops.TypeActionInputLen)
  39. data[0] = byte(ops.TypeActionInput)
  40. data[1] = byte(op)
  41. }
  42. func (a Action) String() string {
  43. var buf strings.Builder
  44. for b := Action(1); a != 0; b <<= 1 {
  45. if a&b != 0 {
  46. if buf.Len() > 0 {
  47. buf.WriteByte('|')
  48. }
  49. buf.WriteString(b.string())
  50. a &^= b
  51. }
  52. }
  53. return buf.String()
  54. }
  55. func (a Action) string() string {
  56. switch a {
  57. case ActionMinimize:
  58. return "ActionMinimize"
  59. case ActionMaximize:
  60. return "ActionMaximize"
  61. case ActionUnmaximize:
  62. return "ActionUnmaximize"
  63. case ActionClose:
  64. return "ActionClose"
  65. case ActionMove:
  66. return "ActionMove"
  67. }
  68. return ""
  69. }