min dimension limit

This commit is contained in:
sqshq 2019-03-02 16:38:36 -05:00
parent def20b5d59
commit ce08f19c53
2 changed files with 9 additions and 10 deletions

View File

@ -5,10 +5,6 @@ import (
ui "github.com/sqshq/termui" ui "github.com/sqshq/termui"
) )
const (
minDimension = 1
)
type Component struct { type Component struct {
Type config.ComponentType Type config.ComponentType
Drawable ui.Drawable Drawable ui.Drawable
@ -31,12 +27,6 @@ func (c *Component) Resize(x, y int) {
} }
func (c *Component) normalize() { func (c *Component) normalize() {
if c.Size.X < minDimension {
c.Size.X = minDimension
}
if c.Size.Y < minDimension {
c.Size.Y = minDimension
}
if c.Position.X < 0 { if c.Position.X < 0 {
c.Position.X = 0 c.Position.X = 0
} }

View File

@ -33,6 +33,7 @@ const (
const ( const (
columnsCount = 80 columnsCount = 80
rowsCount = 40 rowsCount = 40
minDimension = 3
statusbarHeight = 1 statusbarHeight = 1
) )
@ -253,6 +254,14 @@ func (l *Layout) Draw(buffer *ui.Buffer) {
x2 := x1 + math.Floor(float64(component.Size.X))*columnWidth x2 := x1 + math.Floor(float64(component.Size.X))*columnWidth
y2 := y1 + math.Floor(float64(component.Size.Y))*rowHeight y2 := y1 + math.Floor(float64(component.Size.Y))*rowHeight
if x2-x1 < minDimension {
x2 = x1 + minDimension
}
if y2-y1 < minDimension {
y2 = y1 + minDimension
}
component.Drawable.SetRect(int(x1), int(y1), int(x2), int(y2)) component.Drawable.SetRect(int(x1), int(y1), int(x2), int(y2))
component.Drawable.Draw(buffer) component.Drawable.Draw(buffer)
} }