fixes #16 - invalid title display if text is longer than control width

This commit is contained in:
Vladimir Markelov 2015-09-23 16:09:01 -07:00
parent 221249dc32
commit 64334b127f
2 changed files with 17 additions and 3 deletions

View File

@ -47,6 +47,7 @@ func NewCheckBox(parent Window, id WinId, x, y, width, height int, title string,
c.visible = true
c.tabStop = true
c.id = id
c.align = props.Alignment
c.minW, c.minH = 3, 1

View File

@ -359,10 +359,23 @@ func (d *view) DrawAlignedText(x, y, w int, text string, fg, bg Color, align Ali
}
length := xs.Len(text)
if length < w {
d.DrawText(x+int((w-length)/2), y, w, text, fg, bg)
if align == AlignCenter {
d.DrawText(x+int((w-length)/2), y, w, text, fg, bg)
} else if align == AlignLeft {
d.DrawText(x, y, w, text, fg, bg)
} else {
d.DrawText(x+w-length, y, length, text, fg, bg)
}
} else {
dx := int((length - w) / 2)
str := xs.Slice(text, dx, w)
str := ""
if align == AlignCenter {
dx := int((length - w) / 2)
str = xs.Slice(text, dx, dx+w)
} else if align == AlignLeft {
str = xs.Slice(text, 0, w)
} else {
str = xs.Slice(text, length-w, -1)
}
d.DrawText(x, y, w, str, fg, bg)
}
}