mirror of
https://github.com/br0xen/termbox-util.git
synced 2024-11-22 21:43:14 +00:00
Truncate title if it is too long
This commit is contained in:
parent
4b7d3032c8
commit
a018159e66
@ -123,13 +123,15 @@ func (i *InputModal) Draw() {
|
|||||||
if i.is_visible {
|
if i.is_visible {
|
||||||
// First blank out the area we'll be putting the modal
|
// First blank out the area we'll be putting the modal
|
||||||
FillWithChar(' ', i.x, i.y, i.x+i.width, i.y+i.height, i.fg, i.bg)
|
FillWithChar(' ', i.x, i.y, i.x+i.width, i.y+i.height, i.fg, i.bg)
|
||||||
// Now draw the border
|
|
||||||
DrawBorder(i.x, i.y, i.x+i.width, i.y+i.height, i.fg, i.bg)
|
|
||||||
|
|
||||||
next_y := i.y + 1
|
next_y := i.y + 1
|
||||||
// The title
|
// The title
|
||||||
if i.title != "" {
|
if i.title != "" {
|
||||||
|
if len(i.title) > i.width {
|
||||||
|
diff := i.width - len(i.title)
|
||||||
|
DrawStringAtPoint(i.title[:len(i.title)+diff-1], i.x+1, next_y, i.fg, i.bg)
|
||||||
|
} else {
|
||||||
DrawStringAtPoint(i.title, i.x+1, next_y, i.fg, i.bg)
|
DrawStringAtPoint(i.title, i.x+1, next_y, i.fg, i.bg)
|
||||||
|
}
|
||||||
next_y += 1
|
next_y += 1
|
||||||
FillWithChar('-', i.x+1, next_y, i.x+i.width-1, next_y, i.fg, i.bg)
|
FillWithChar('-', i.x+1, next_y, i.x+i.width-1, next_y, i.fg, i.bg)
|
||||||
next_y += 1
|
next_y += 1
|
||||||
@ -146,5 +148,7 @@ func (i *InputModal) Draw() {
|
|||||||
help_x := (i.x + i.width - len(help_string)) - 1
|
help_x := (i.x + i.width - len(help_string)) - 1
|
||||||
DrawStringAtPoint(help_string, help_x, next_y, i.fg, i.bg)
|
DrawStringAtPoint(help_string, help_x, next_y, i.fg, i.bg)
|
||||||
}
|
}
|
||||||
|
// Now draw the border
|
||||||
|
DrawBorder(i.x, i.y, i.x+i.width, i.y+i.height, i.fg, i.bg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user