mirror of
https://github.com/VladimirMarkelov/clui.git
synced 2025-04-26 13:49:01 +08:00
closes #34 - make edit and checkbox one line height and center them vertically on resize
This commit is contained in:
parent
4caae5c840
commit
cec72537cd
20
checkbox.go
20
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
|
||||
}
|
||||
|
17
ctrlutil.go
17
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
|
||||
}
|
||||
|
20
edit.go
20
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
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user