sampler-fork/widgets/component.go

58 lines
779 B
Go
Raw Normal View History

2019-02-01 05:07:25 +00:00
package widgets
2019-01-31 00:02:38 +00:00
import (
. "github.com/sqshq/termui"
)
2019-01-31 01:41:51 +00:00
type Component struct {
Drawable Drawable
2019-02-11 02:51:55 +00:00
Title string
2019-01-31 00:02:38 +00:00
Position Position
Size Size
Type ComponentType
2019-01-31 00:02:38 +00:00
}
2019-02-11 02:51:55 +00:00
type ComponentType rune
const (
2019-02-11 02:51:55 +00:00
TypeRunChart ComponentType = 0
TypeBarChart ComponentType = 1
)
2019-01-31 00:02:38 +00:00
type Position struct {
X int `yaml:"x"`
Y int `yaml:"y"`
}
type Size struct {
X int `yaml:"x"`
Y int `yaml:"y"`
}
func (c *Component) Move(x, y int) {
c.Position.X += x
c.Position.Y += y
c.normalize()
2019-01-31 00:02:38 +00:00
}
func (c *Component) Resize(x, y int) {
c.Size.X += x
c.Size.Y += y
c.normalize()
}
func (c *Component) normalize() {
if c.Size.X < 0 {
c.Size.X = 0
}
if c.Size.Y < 0 {
c.Size.Y = 0
}
if c.Position.X < 0 {
c.Position.X = 0
}
if c.Position.Y < 0 {
c.Position.Y = 0
}
2019-01-31 00:02:38 +00:00
}