| 1 |
// gomuks - A terminal Matrix client written in Go. |
| 2 |
// Copyright (C) 2020 Tulir Asokan |
| 3 |
// |
| 4 |
// This program is free software: you can redistribute it and/or modify |
| 5 |
// it under the terms of the GNU Affero General Public License as published by |
| 6 |
// the Free Software Foundation, either version 3 of the License, or |
| 7 |
// (at your option) any later version. |
| 8 |
// |
| 9 |
// This program is distributed in the hope that it will be useful, |
| 10 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
// GNU Affero General Public License for more details. |
| 13 |
// |
| 14 |
// You should have received a copy of the GNU Affero General Public License |
| 15 |
// along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 16 |
|
| 17 |
package widget |
| 18 |
|
| 19 |
import ( |
| 20 |
"go.mau.fi/mauview" |
| •21 |
"github.com/gdamore/tcell/v2" |
| 22 |
) |
| 23 |
|
| 24 |
// Border is a simple tview widget that renders a horizontal or vertical bar. |
| 25 |
// |
| 26 |
// If the width of the box is 1, the bar will be vertical. |
| 27 |
// If the height is 1, the bar will be horizontal. |
| 28 |
// If the width nor the height are 1, nothing will be rendered. |
| 29 |
type Border struct { |
| 30 |
Style tcell.Style |
| 31 |
} |
| 32 |
|
| 33 |
// NewBorder wraps a new tview Box into a new Border. |
| 34 |
func NewBorder() *Border { |
| 35 |
return &Border{ |
| 36 |
Style: tcell.StyleDefault.Foreground(mauview.Styles.BorderColor), |
| 37 |
} |
| 38 |
} |
| 39 |
|
| 40 |
func (border *Border) Draw(screen mauview.Screen) { |
| 41 |
width, height := screen.Size() |
| 42 |
if width == 1 { |
| 43 |
for borderY := 0; borderY < height; borderY++ { |
| 44 |
screen.SetContent(0, borderY, mauview.Borders.Vertical, nil, border.Style) |
| 45 |
} |
| 46 |
} else if height == 1 { |
| 47 |
for borderX := 0; borderX < width; borderX++ { |
| 48 |
screen.SetContent(borderX, 0, mauview.Borders.Horizontal, nil, border.Style) |
| 49 |
} |
| 50 |
} |
| 51 |
} |
| 52 |
|
| 53 |
func (border *Border) OnKeyEvent(event mauview.KeyEvent) bool { |
| 54 |
return false |
| 55 |
} |
| 56 |
|
| 57 |
func (border *Border) OnPasteEvent(event mauview.PasteEvent) bool { |
| 58 |
return false |
| 59 |
} |
| 60 |
|
| 61 |
func (border *Border) OnMouseEvent(event mauview.MouseEvent) bool { |
| 62 |
return false |
| 63 |
} |