Skip to content

Commit

Permalink
Add ability to change view visibility
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander I.Grafov committed Jan 24, 2016
1 parent 825abbc commit dfc721a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
3 changes: 3 additions & 0 deletions gui.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,9 @@ func (g *Gui) Flush() error {
return err
}
for _, v := range g.views {
if !v.visible {
continue
}
if v.Frame {
if err := g.drawFrame(v); err != nil {
return err
Expand Down
22 changes: 22 additions & 0 deletions view.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type View struct {
readCache string

tainted bool // marks if the viewBuffer must be updated
visible bool // set panel visibility (by default it visible)
viewLines []viewLine // internal representation of the view's buffer

// BgColor and FgColor allow to configure the background and foreground
Expand Down Expand Up @@ -76,6 +77,7 @@ func newView(name string, x0, y0, x1, y1 int) *View {
y1: y1,
Frame: true,
tainted: true,
visible: true,
}
return v
}
Expand Down Expand Up @@ -202,6 +204,9 @@ func (v *View) Rewind() {

// draw re-draws the view's contents.
func (v *View) draw() error {
if !v.visible {
return nil
}
maxX, maxY := v.Size()

if v.Wrap {
Expand Down Expand Up @@ -520,3 +525,20 @@ func (v *View) Reset() {
func (v *View) LinesCount() int {
return len(v.lines)
}

// Hide view.
func (v *View) Hide() {
v.visible = false
return
}

// Unhide view.
func (v *View) Unhide() {
v.visible = true
return
}

// Visible shows visibility of a view.
func (v *View) Visible() bool {
return v.visible
}

0 comments on commit dfc721a

Please sign in to comment.