diff --git a/checkbox.go b/checkbox.go index 04a99b9..c8dcef7 100644 --- a/checkbox.go +++ b/checkbox.go @@ -147,3 +147,23 @@ func (c *CheckBox) SetAllow3State(enable bool) { func (c *CheckBox) Allow3State() bool { return c.allow3state } + +// SetSize changes control size. Constant DoNotChange can be +// used as placeholder to indicate that the control attrubute +// should be unchanged. +// Method does nothing if new size is less than minimal size +// CheckBox height cannot be changed - it equals 1 always +func (c *CheckBox) SetSize(width, height int) { + if width != DoNotChange && (width > 1000 || width < c.minW) { + return + } + if height != DoNotChange && (height > 200 || height < c.minH) { + return + } + + if width != DoNotChange { + c.width = width + } + + c.height = 1 +} diff --git a/ctrlutil.go b/ctrlutil.go index 9a18925..2674743 100644 --- a/ctrlutil.go +++ b/ctrlutil.go @@ -83,6 +83,15 @@ func RepositionControls(dx, dy int, c Control) { pk := c.Pack() top, side, xx, yy := c.Paddings() + calcShift := func(height int, ctrl Control) int { + _, h := ctrl.Size() + if h < height { + return int((height - h) / 2) + } + + return 0 + } + currX, currY := top, side if pk == Vertical { delta := float64(yDiff) / float64(scale) @@ -105,7 +114,9 @@ func RepositionControls(dx, dy int, c Control) { } cw = width - 2*side child.SetSize(cw, ch) - child.SetPos(currX+dx, currY+dy) + + yShift := calcShift(ch, child) + child.SetPos(currX+dx, currY+dy+yShift) currY += ch + yy } } else { @@ -130,7 +141,9 @@ func RepositionControls(dx, dy int, c Control) { } ch = height - 2*top child.SetSize(cw, ch) - child.SetPos(currX+dx, currY+dy) + + yShift := calcShift(ch, child) + child.SetPos(currX+dx, currY+dy+yShift) // log.Printf("ChildH %v pos %v:%v width: %v", child.Title(), currX+dx, currY+dy, cw) currX += cw + xx } diff --git a/edit.go b/edit.go index 474cb03..505480b 100644 --- a/edit.go +++ b/edit.go @@ -313,3 +313,23 @@ func (e *EditField) SetMaxWidth(w int) { func (e *EditField) MaxWidth() int { return e.maxWidth } + +// SetSize changes control size. Constant DoNotChange can be +// used as placeholder to indicate that the control attrubute +// should be unchanged. +// Method does nothing if new size is less than minimal size +// EditField height cannot be changed - it equals 1 always +func (e *EditField) SetSize(width, height int) { + if width != DoNotChange && (width > 1000 || width < e.minW) { + return + } + if height != DoNotChange && (height > 200 || height < e.minH) { + return + } + + if width != DoNotChange { + e.width = width + } + + e.height = 1 +}