2019-02-24 04:49:09 +00:00
|
|
|
package component
|
2019-01-31 00:02:38 +00:00
|
|
|
|
|
|
|
import (
|
2019-02-17 01:54:48 +00:00
|
|
|
"github.com/sqshq/sampler/config"
|
|
|
|
ui "github.com/sqshq/termui"
|
2019-01-31 00:02:38 +00:00
|
|
|
)
|
|
|
|
|
2019-02-26 04:36:23 +00:00
|
|
|
const (
|
2019-03-01 03:44:01 +00:00
|
|
|
minDimension = 1
|
2019-02-26 04:36:23 +00:00
|
|
|
)
|
|
|
|
|
2019-01-31 01:41:51 +00:00
|
|
|
type Component struct {
|
2019-02-24 04:42:52 +00:00
|
|
|
Type config.ComponentType
|
|
|
|
Drawable ui.Drawable
|
|
|
|
Title string
|
|
|
|
Position config.Position
|
|
|
|
Size config.Size
|
|
|
|
RefreshRateMs int
|
2019-01-31 00:02:38 +00:00
|
|
|
}
|
|
|
|
|
2019-02-11 03:26:51 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2019-02-11 03:26:51 +00:00
|
|
|
func (c *Component) Resize(x, y int) {
|
|
|
|
c.Size.X += x
|
|
|
|
c.Size.Y += y
|
|
|
|
c.normalize()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Component) normalize() {
|
2019-02-26 04:36:23 +00:00
|
|
|
if c.Size.X < minDimension {
|
|
|
|
c.Size.X = minDimension
|
2019-02-11 03:26:51 +00:00
|
|
|
}
|
2019-02-26 04:36:23 +00:00
|
|
|
if c.Size.Y < minDimension {
|
|
|
|
c.Size.Y = minDimension
|
2019-02-11 03:26:51 +00:00
|
|
|
}
|
|
|
|
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
|
|
|
}
|