mirror of
https://github.com/taigrr/wtf
synced 2026-04-02 02:28:55 -07:00
Vendor dependencies using golang/dep
Output from 'dep status': PROJECT CONSTRAINT VERSION REVISION LATEST PKGS USED cloud.google.com/go v0.23.0 v0.23.0 0fd7230 v0.23.0 1 github.com/briandowns/openweathermap ^0.11.0 0.11 1b87579 0.11 1 github.com/gdamore/encoding branch master branch master b23993c b23993c 1 github.com/gdamore/tcell ^1.0.0 v1.0.0 061d51a v1.0.0 2 github.com/go-test/deep ^1.0.1 v1.0.1 6592d9c v1.0.1 1 github.com/golang/protobuf v1.1.0 v1.1.0 b4deda0 v1.1.0 1 github.com/google/go-github branch master branch master 2ae5df7 2ae5df7 1 github.com/google/go-querystring branch master branch master 53e6ce1 53e6ce1 1 github.com/jessevdk/go-flags ^1.4.0 v1.4.0 c6ca198 v1.4.0 1 github.com/lucasb-eyer/go-colorful v1.0 v1.0 345fbb3 v1.0 1 github.com/mattn/go-runewidth v0.0.2 v0.0.2 9e777a8 v0.0.2 1 github.com/olebedev/config branch master branch master 9a10d05 9a10d05 1 github.com/radovskyb/watcher ^1.0.2 v1.0.2 6145e14 v1.0.2 1 github.com/rivo/tview branch master branch master 71ecf1f 71ecf1f 1 github.com/yfronto/newrelic branch master branch master f7fa0c6 f7fa0c6 1 golang.org/x/net branch master branch master 1e49130 1e49130 2 golang.org/x/oauth2 branch master branch master 1e0a3fa 1e0a3fa 5 golang.org/x/text v0.3.0 v0.3.0 f21a4df v0.3.0 5 google.golang.org/api branch master branch master 00e3bb8 00e3bb8 4 google.golang.org/appengine v1.0.0 v1.0.0 150dc57 v1.0.0 10 gopkg.in/yaml.v2 ^2.2.1 v2.2.1 5420a8b v2.2.1 1 See https://golang.github.io/dep/docs/daily-dep.html
This commit is contained in:
180
vendor/github.com/rivo/tview/flex.go
generated
vendored
Normal file
180
vendor/github.com/rivo/tview/flex.go
generated
vendored
Normal file
@@ -0,0 +1,180 @@
|
||||
package tview
|
||||
|
||||
import (
|
||||
"github.com/gdamore/tcell"
|
||||
)
|
||||
|
||||
// Configuration values.
|
||||
const (
|
||||
FlexRow = iota
|
||||
FlexColumn
|
||||
)
|
||||
|
||||
// flexItem holds layout options for one item.
|
||||
type flexItem struct {
|
||||
Item Primitive // The item to be positioned. May be nil for an empty item.
|
||||
FixedSize int // The item's fixed size which may not be changed, 0 if it has no fixed size.
|
||||
Proportion int // The item's proportion.
|
||||
Focus bool // Whether or not this item attracts the layout's focus.
|
||||
}
|
||||
|
||||
// Flex is a basic implementation of the Flexbox layout. The contained
|
||||
// primitives are arranged horizontally or vertically. The way they are
|
||||
// distributed along that dimension depends on their layout settings, which is
|
||||
// either a fixed length or a proportional length. See AddItem() for details.
|
||||
//
|
||||
// See https://github.com/rivo/tview/wiki/Flex for an example.
|
||||
type Flex struct {
|
||||
*Box
|
||||
|
||||
// The items to be positioned.
|
||||
items []flexItem
|
||||
|
||||
// FlexRow or FlexColumn.
|
||||
direction int
|
||||
|
||||
// If set to true, Flex will use the entire screen as its available space
|
||||
// instead its box dimensions.
|
||||
fullScreen bool
|
||||
}
|
||||
|
||||
// NewFlex returns a new flexbox layout container with no primitives and its
|
||||
// direction set to FlexColumn. To add primitives to this layout, see AddItem().
|
||||
// To change the direction, see SetDirection().
|
||||
//
|
||||
// Note that Box, the superclass of Flex, will have its background color set to
|
||||
// transparent so that any nil flex items will leave their background unchanged.
|
||||
// To clear a Flex's background before any items are drawn, set it to the
|
||||
// desired color:
|
||||
//
|
||||
// flex.SetBackgroundColor(tview.Styles.PrimitiveBackgroundColor)
|
||||
func NewFlex() *Flex {
|
||||
f := &Flex{
|
||||
Box: NewBox().SetBackgroundColor(tcell.ColorDefault),
|
||||
direction: FlexColumn,
|
||||
}
|
||||
f.focus = f
|
||||
return f
|
||||
}
|
||||
|
||||
// SetDirection sets the direction in which the contained primitives are
|
||||
// distributed. This can be either FlexColumn (default) or FlexRow.
|
||||
func (f *Flex) SetDirection(direction int) *Flex {
|
||||
f.direction = direction
|
||||
return f
|
||||
}
|
||||
|
||||
// SetFullScreen sets the flag which, when true, causes the flex layout to use
|
||||
// the entire screen space instead of whatever size it is currently assigned to.
|
||||
func (f *Flex) SetFullScreen(fullScreen bool) *Flex {
|
||||
f.fullScreen = fullScreen
|
||||
return f
|
||||
}
|
||||
|
||||
// AddItem adds a new item to the container. The "fixedSize" argument is a width
|
||||
// or height that may not be changed by the layout algorithm. A value of 0 means
|
||||
// that its size is flexible and may be changed. The "proportion" argument
|
||||
// defines the relative size of the item compared to other flexible-size items.
|
||||
// For example, items with a proportion of 2 will be twice as large as items
|
||||
// with a proportion of 1. The proportion must be at least 1 if fixedSize == 0
|
||||
// (ignored otherwise).
|
||||
//
|
||||
// If "focus" is set to true, the item will receive focus when the Flex
|
||||
// primitive receives focus. If multiple items have the "focus" flag set to
|
||||
// true, the first one will receive focus.
|
||||
//
|
||||
// You can provide a nil value for the primitive. This will still consume screen
|
||||
// space but nothing will be drawn.
|
||||
func (f *Flex) AddItem(item Primitive, fixedSize, proportion int, focus bool) *Flex {
|
||||
f.items = append(f.items, flexItem{Item: item, FixedSize: fixedSize, Proportion: proportion, Focus: focus})
|
||||
return f
|
||||
}
|
||||
|
||||
// RemoveItem removes all items for the given primitive from the container,
|
||||
// keeping the order of the remaining items intact.
|
||||
func (f *Flex) RemoveItem(p Primitive) *Flex {
|
||||
for index := len(f.items) - 1; index >= 0; index-- {
|
||||
if f.items[index].Item == p {
|
||||
f.items = append(f.items[:index], f.items[index+1:]...)
|
||||
}
|
||||
}
|
||||
return f
|
||||
}
|
||||
|
||||
// Draw draws this primitive onto the screen.
|
||||
func (f *Flex) Draw(screen tcell.Screen) {
|
||||
f.Box.Draw(screen)
|
||||
|
||||
// Calculate size and position of the items.
|
||||
|
||||
// Do we use the entire screen?
|
||||
if f.fullScreen {
|
||||
width, height := screen.Size()
|
||||
f.SetRect(0, 0, width, height)
|
||||
}
|
||||
|
||||
// How much space can we distribute?
|
||||
x, y, width, height := f.GetInnerRect()
|
||||
var proportionSum int
|
||||
distSize := width
|
||||
if f.direction == FlexRow {
|
||||
distSize = height
|
||||
}
|
||||
for _, item := range f.items {
|
||||
if item.FixedSize > 0 {
|
||||
distSize -= item.FixedSize
|
||||
} else {
|
||||
proportionSum += item.Proportion
|
||||
}
|
||||
}
|
||||
|
||||
// Calculate positions and draw items.
|
||||
pos := x
|
||||
if f.direction == FlexRow {
|
||||
pos = y
|
||||
}
|
||||
for _, item := range f.items {
|
||||
size := item.FixedSize
|
||||
if size <= 0 {
|
||||
size = distSize * item.Proportion / proportionSum
|
||||
distSize -= size
|
||||
proportionSum -= item.Proportion
|
||||
}
|
||||
if item.Item != nil {
|
||||
if f.direction == FlexColumn {
|
||||
item.Item.SetRect(pos, y, size, height)
|
||||
} else {
|
||||
item.Item.SetRect(x, pos, width, size)
|
||||
}
|
||||
}
|
||||
pos += size
|
||||
|
||||
if item.Item != nil {
|
||||
if item.Item.GetFocusable().HasFocus() {
|
||||
defer item.Item.Draw(screen)
|
||||
} else {
|
||||
item.Item.Draw(screen)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Focus is called when this primitive receives focus.
|
||||
func (f *Flex) Focus(delegate func(p Primitive)) {
|
||||
for _, item := range f.items {
|
||||
if item.Item != nil && item.Focus {
|
||||
delegate(item.Item)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// HasFocus returns whether or not this primitive has focus.
|
||||
func (f *Flex) HasFocus() bool {
|
||||
for _, item := range f.items {
|
||||
if item.Item != nil && item.Item.GetFocusable().HasFocus() {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
Reference in New Issue
Block a user