forked from google/gxui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdirection.go
47 lines (40 loc) · 1.02 KB
/
direction.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package gxui
import "fmt"
type Direction int
const (
TopToBottom Direction = iota
LeftToRight
BottomToTop
RightToLeft
)
func (d Direction) LeftToRight() bool { return d == LeftToRight }
func (d Direction) RightToLeft() bool { return d == RightToLeft }
func (d Direction) TopToBottom() bool { return d == TopToBottom }
func (d Direction) BottomToTop() bool { return d == BottomToTop }
func (d Direction) Flip() Direction {
switch d {
case TopToBottom:
return BottomToTop
case LeftToRight:
return RightToLeft
case BottomToTop:
return TopToBottom
case RightToLeft:
return LeftToRight
default:
panic(fmt.Errorf("Unknown direction %d", d))
}
}
func (d Direction) Orientation() Orientation {
switch d {
case TopToBottom, BottomToTop:
return Vertical
case LeftToRight, RightToLeft:
return Horizontal
default:
panic(fmt.Errorf("Unknown direction %d", d))
}
}