Add Show() and Hide()

This commit is contained in:
Brian Buller 2015-05-05 15:47:09 -05:00
parent c5cb0ca9fe
commit c581974cc0
2 changed files with 47 additions and 23 deletions

View File

@ -14,6 +14,7 @@ type ConfirmModal struct {
is_done bool
accepted bool
value string
is_visible bool
}
func CreateConfirmModal(title string, x, y, width, height int, fg, bg termbox.Attribute) *ConfirmModal {
@ -84,6 +85,15 @@ func (i *ConfirmModal) SetDone(b bool) *ConfirmModal {
return i
}
func (i *ConfirmModal) Show() *ConfirmModal {
i.is_visible = true
return i
}
func (i *ConfirmModal) Hide() *ConfirmModal {
i.is_visible = false
return i
}
func (i *ConfirmModal) IsAccepted() bool { return i.accepted }
func (i *ConfirmModal) Clear() *ConfirmModal {

View File

@ -13,6 +13,7 @@ type InputModal struct {
cursor int
bg, fg termbox.Attribute
is_done bool
is_visible bool
}
func CreateInputModal(title string, x, y, width, height int, fg, bg termbox.Attribute) *InputModal {
@ -75,6 +76,16 @@ func (i *InputModal) SetForeground(fg termbox.Attribute) *InputModal {
i.fg = fg
return i
}
func (i *InputModal) Show() *InputModal {
i.is_visible = true
return i
}
func (i *InputModal) Hide() *InputModal {
i.is_visible = false
return i
}
func (i *InputModal) SetDone(b bool) *InputModal {
i.is_done = b
return i
@ -94,6 +105,7 @@ func (i *InputModal) Clear() *InputModal {
i.text = ""
i.input.SetValue("")
i.is_done = false
i.is_visible = false
return i
}
@ -108,6 +120,7 @@ func (i *InputModal) HandleKeyPress(event termbox.Event) bool {
}
func (i *InputModal) Draw() {
if i.is_visible {
// 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)
// Now draw the border
@ -134,3 +147,4 @@ func (i *InputModal) Draw() {
DrawStringAtPoint(help_string, help_x, next_y, i.fg, i.bg)
}
}
}