From ce08f19c53d02810397f86569f7ed27cae074c86 Mon Sep 17 00:00:00 2001 From: sqshq Date: Sat, 2 Mar 2019 16:38:36 -0500 Subject: [PATCH] min dimension limit --- component/component.go | 10 ---------- component/layout.go | 9 +++++++++ 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/component/component.go b/component/component.go index f8e5ea0..f3d6b33 100644 --- a/component/component.go +++ b/component/component.go @@ -5,10 +5,6 @@ import ( ui "github.com/sqshq/termui" ) -const ( - minDimension = 1 -) - type Component struct { Type config.ComponentType Drawable ui.Drawable @@ -31,12 +27,6 @@ func (c *Component) Resize(x, y int) { } 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 { c.Position.X = 0 } diff --git a/component/layout.go b/component/layout.go index d22b94c..b2e3322 100644 --- a/component/layout.go +++ b/component/layout.go @@ -33,6 +33,7 @@ const ( const ( columnsCount = 80 rowsCount = 40 + minDimension = 3 statusbarHeight = 1 ) @@ -253,6 +254,14 @@ func (l *Layout) Draw(buffer *ui.Buffer) { x2 := x1 + math.Floor(float64(component.Size.X))*columnWidth 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.Draw(buffer) }