diff options
author | Jeffrey Wilcke <jeffrey@ethereum.org> | 2016-02-17 20:46:30 +0800 |
---|---|---|
committer | Jeffrey Wilcke <jeffrey@ethereum.org> | 2016-02-17 20:46:30 +0800 |
commit | aa36a6ae4f24f07e2c470a21c93ff37ad5861982 (patch) | |
tree | dba654e20554d28383c1f3bb8164fa9f5849d1bd /Godeps/_workspace/src/github.com/gizak/termui/pos.go | |
parent | 4f28c5b69d652e12adf8a88f526f459a492e159e (diff) | |
parent | 6ba7bbbe29029c8bf2bf75f8ebcbd3847eafa401 (diff) | |
download | go-tangerine-aa36a6ae4f24f07e2c470a21c93ff37ad5861982.tar go-tangerine-aa36a6ae4f24f07e2c470a21c93ff37ad5861982.tar.gz go-tangerine-aa36a6ae4f24f07e2c470a21c93ff37ad5861982.tar.bz2 go-tangerine-aa36a6ae4f24f07e2c470a21c93ff37ad5861982.tar.lz go-tangerine-aa36a6ae4f24f07e2c470a21c93ff37ad5861982.tar.xz go-tangerine-aa36a6ae4f24f07e2c470a21c93ff37ad5861982.tar.zst go-tangerine-aa36a6ae4f24f07e2c470a21c93ff37ad5861982.zip |
Merge pull request #2206 from fjl/update-deps
Godeps: update all dependencies
Diffstat (limited to 'Godeps/_workspace/src/github.com/gizak/termui/pos.go')
-rw-r--r-- | Godeps/_workspace/src/github.com/gizak/termui/pos.go | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/Godeps/_workspace/src/github.com/gizak/termui/pos.go b/Godeps/_workspace/src/github.com/gizak/termui/pos.go new file mode 100644 index 000000000..2046dce5a --- /dev/null +++ b/Godeps/_workspace/src/github.com/gizak/termui/pos.go @@ -0,0 +1,78 @@ +// Copyright 2016 Zack Guo <gizak@icloud.com>. All rights reserved. +// Use of this source code is governed by a MIT license that can +// be found in the LICENSE file. + +package termui + +import "image" + +// Align is the position of the gauge's label. +type Align uint + +// All supported positions. +const ( + AlignNone Align = 0 + AlignLeft Align = 1 << iota + AlignRight + AlignBottom + AlignTop + AlignCenterVertical + AlignCenterHorizontal + AlignCenter = AlignCenterVertical | AlignCenterHorizontal +) + +func AlignArea(parent, child image.Rectangle, a Align) image.Rectangle { + w, h := child.Dx(), child.Dy() + + // parent center + pcx, pcy := parent.Min.X+parent.Dx()/2, parent.Min.Y+parent.Dy()/2 + // child center + ccx, ccy := child.Min.X+child.Dx()/2, child.Min.Y+child.Dy()/2 + + if a&AlignLeft == AlignLeft { + child.Min.X = parent.Min.X + child.Max.X = child.Min.X + w + } + + if a&AlignRight == AlignRight { + child.Max.X = parent.Max.X + child.Min.X = child.Max.X - w + } + + if a&AlignBottom == AlignBottom { + child.Max.Y = parent.Max.Y + child.Min.Y = child.Max.Y - h + } + + if a&AlignTop == AlignRight { + child.Min.Y = parent.Min.Y + child.Max.Y = child.Min.Y + h + } + + if a&AlignCenterHorizontal == AlignCenterHorizontal { + child.Min.X += pcx - ccx + child.Max.X = child.Min.X + w + } + + if a&AlignCenterVertical == AlignCenterVertical { + child.Min.Y += pcy - ccy + child.Max.Y = child.Min.Y + h + } + + return child +} + +func MoveArea(a image.Rectangle, dx, dy int) image.Rectangle { + a.Min.X += dx + a.Max.X += dx + a.Min.Y += dy + a.Max.Y += dy + return a +} + +var termWidth int +var termHeight int + +func TermRect() image.Rectangle { + return image.Rect(0, 0, termWidth, termHeight) +} |