1
0
mirror of https://github.com/br0xen/termbox-util.git synced 2024-11-26 15:13:15 +00:00

Some improvements

This commit is contained in:
Brian Buller 2015-05-04 17:42:35 -05:00
parent cf3fa0559d
commit 6f77695994
3 changed files with 19 additions and 8 deletions

View File

@ -124,8 +124,10 @@ func (i *ConfirmModal) Draw() {
DrawStringAtPoint(i.text, i.x+1, next_y, i.fg, i.bg) DrawStringAtPoint(i.text, i.x+1, next_y, i.fg, i.bg)
next_y += 1 next_y += 1
} }
next_y += 3 next_y += 2
if i.show_help { if i.show_help {
DrawStringAtPoint("(Y/y) Confirm. (N/n) Reject.", i.x+1, next_y, i.fg, i.bg) help_string := " (Y/y) Confirm. (N/n) Reject. "
help_x := (i.x + i.width) - len(help_string) - 1
DrawStringAtPoint(help_string, help_x, next_y, i.fg, i.bg)
} }
} }

View File

@ -105,6 +105,7 @@ func (i *InputModal) HandleKeyPress(event termbox.Event) bool {
return i.input.HandleKeyPress(event) return i.input.HandleKeyPress(event)
} }
} }
func (i *InputModal) Draw() { func (i *InputModal) Draw() {
// 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)
@ -121,12 +122,14 @@ func (i *InputModal) Draw() {
} }
if i.text != "" { if i.text != "" {
DrawStringAtPoint(i.text, i.x+1, next_y, i.fg, i.bg) DrawStringAtPoint(i.text, i.x+1, next_y, i.fg, i.bg)
next_y += 1 next_y += 2
} }
i.input.SetY(next_y) i.input.SetY(next_y)
i.input.Draw() i.input.Draw()
next_y += 3 next_y += 3
if i.show_help { if i.show_help {
DrawStringAtPoint("(ENTER) to Accept. (ESC) to Cancel.", i.x+1, next_y, i.fg, i.bg) help_string := " (ENTER) to Accept. (ESC) to Cancel. "
help_x := (i.x + i.width - len(help_string)) - 1
DrawStringAtPoint(help_string, help_x, next_y, i.fg, i.bg)
} }
} }

View File

@ -33,10 +33,16 @@ func FillWithChar(r rune, x1, y1, x2, y2 int, fg termbox.Attribute, bg termbox.A
} }
func DrawBorder(x1, y1, x2, y2 int, fg termbox.Attribute, bg termbox.Attribute) { func DrawBorder(x1, y1, x2, y2 int, fg termbox.Attribute, bg termbox.Attribute) {
FillWithChar('|', x1, y1, x1, y2, fg, bg) termbox.SetCell(x1, y1, '┌', fg, bg)
FillWithChar('|', x2, y1, x2, y2, fg, bg) FillWithChar('─', x1+1, y1, x2-1, y1, fg, bg)
FillWithChar('-', x1, y1, x2, y1, fg, bg) termbox.SetCell(x2, y1, '┐', fg, bg)
FillWithChar('-', x1, y2, x2, y2, fg, bg)
FillWithChar('|', x1, y1+1, x1, y2-1, fg, bg)
FillWithChar('|', x2, y1+1, x2, y2-1, fg, bg)
termbox.SetCell(x1, y2, '└', fg, bg)
FillWithChar('─', x1+1, y2, x2-1, y2, fg, bg)
termbox.SetCell(x2, y2, '┘', fg, bg)
} }
func AlignText(txt string, width int, align TextAlignment) string { func AlignText(txt string, width int, align TextAlignment) string {