diff --git a/checkbox.go b/checkbox.go index 5908a98..00f989a 100644 --- a/checkbox.go +++ b/checkbox.go @@ -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 diff --git a/window.go b/window.go index 634dc49..009f3c1 100644 --- a/window.go +++ b/window.go @@ -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) } }