...

Source file src/github.com/gdamore/tcell/v2/views/panel.go

Documentation: github.com/gdamore/tcell/v2/views

     1  // Copyright 2015 The Tops'l Authors
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use file except in compliance with the License.
     5  // You may obtain a copy of the license at
     6  //
     7  //    http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package views
    16  
    17  // Panel is a modified Layout that includes a primary content pane,
    18  // prefixed with an optional title, and an optional menubar, and then
    19  // suffixed by an optional status.
    20  //
    21  // Only the content pane is resizable.  The panel will be formatted
    22  // like this:
    23  //
    24  //	+----------
    25  //	| title
    26  //	| menu
    27  //	| content....
    28  //	| <padding>
    29  //	| status
    30  //	+----------
    31  //
    32  // Each of these components may be any valid widget; their names are
    33  // only meant to be indicative of conventional use, not prescriptive.
    34  type Panel struct {
    35  	title   Widget
    36  	menu    Widget
    37  	content Widget
    38  	status  Widget
    39  	inited  bool
    40  	BoxLayout
    41  }
    42  
    43  // Draw draws the Panel.
    44  func (p *Panel) Draw() {
    45  	p.BoxLayout.SetOrientation(Vertical)
    46  	p.BoxLayout.Draw()
    47  }
    48  
    49  // SetTitle sets the Widget to display in the title area.
    50  func (p *Panel) SetTitle(w Widget) {
    51  	if p.title != nil {
    52  		p.RemoveWidget(p.title)
    53  	}
    54  	p.InsertWidget(0, w, 0.0)
    55  	p.title = w
    56  }
    57  
    58  // SetMenu sets the Widget to display in the menu area, which is
    59  // just below the title.
    60  func (p *Panel) SetMenu(w Widget) {
    61  	index := 0
    62  	if p.title != nil {
    63  		index++
    64  	}
    65  	if p.menu != nil {
    66  		p.RemoveWidget(p.menu)
    67  	}
    68  	p.InsertWidget(index, w, 0.0)
    69  	p.menu = w
    70  }
    71  
    72  // SetContent sets the Widget to display in the content area.
    73  func (p *Panel) SetContent(w Widget) {
    74  	index := 0
    75  	if p.title != nil {
    76  		index++
    77  	}
    78  	if p.menu != nil {
    79  		index++
    80  	}
    81  	if p.content != nil {
    82  		p.RemoveWidget(p.content)
    83  	}
    84  	p.InsertWidget(index, w, 1.0)
    85  	p.content = w
    86  }
    87  
    88  // SetStatus sets the Widget to display in the status area, which is at
    89  // the bottom of the panel.
    90  func (p *Panel) SetStatus(w Widget) {
    91  	index := 0
    92  	if p.title != nil {
    93  		index++
    94  	}
    95  	if p.menu != nil {
    96  		index++
    97  	}
    98  	if p.content != nil {
    99  		index++
   100  	}
   101  	if p.status != nil {
   102  		p.RemoveWidget(p.status)
   103  	}
   104  	p.InsertWidget(index, w, 0.0)
   105  	p.status = w
   106  }
   107  
   108  // NewPanel creates a new Panel.  A zero valued panel can be created too.
   109  func NewPanel() *Panel {
   110  	return &Panel{}
   111  }
   112  

View as plain text