gomuks/ui/widget/border.go

64 lines
1.9 KiB
Go
Raw Normal View History

2018-03-15 18:45:52 +01:00
// gomuks - A terminal Matrix client written in Go.
2020-04-19 17:10:14 +02:00
// Copyright (C) 2020 Tulir Asokan
2018-03-15 18:45:52 +01:00
//
// This program is free software: you can redistribute it and/or modify
2019-01-17 13:13:25 +01:00
// it under the terms of the GNU Affero General Public License as published by
2018-03-15 18:45:52 +01:00
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2019-01-17 13:13:25 +01:00
// GNU Affero General Public License for more details.
2018-03-15 18:45:52 +01:00
//
2019-01-17 13:13:25 +01:00
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
2018-03-15 18:45:52 +01:00
2018-03-18 20:24:03 +01:00
package widget
2018-03-15 18:45:52 +01:00
import (
2022-04-15 11:53:09 +02:00
"go.mau.fi/mauview"
"go.mau.fi/tcell"
2018-03-15 18:45:52 +01:00
)
2018-03-22 22:03:36 +01:00
// Border is a simple tview widget that renders a horizontal or vertical bar.
//
// If the width of the box is 1, the bar will be vertical.
// If the height is 1, the bar will be horizontal.
// If the width nor the height are 1, nothing will be rendered.
2018-03-15 18:45:52 +01:00
type Border struct {
2019-03-25 23:37:35 +01:00
Style tcell.Style
2018-03-15 18:45:52 +01:00
}
2018-03-22 22:03:36 +01:00
// NewBorder wraps a new tview Box into a new Border.
2018-03-15 18:45:52 +01:00
func NewBorder() *Border {
2019-03-25 23:37:35 +01:00
return &Border{
Style: tcell.StyleDefault.Foreground(mauview.Styles.BorderColor),
}
2018-03-15 18:45:52 +01:00
}
2019-03-25 23:37:35 +01:00
func (border *Border) Draw(screen mauview.Screen) {
width, height := screen.Size()
2018-03-15 18:45:52 +01:00
if width == 1 {
2019-03-25 23:37:35 +01:00
for borderY := 0; borderY < height; borderY++ {
screen.SetContent(0, borderY, mauview.Borders.Vertical, nil, border.Style)
2018-03-15 18:45:52 +01:00
}
} else if height == 1 {
2019-03-25 23:37:35 +01:00
for borderX := 0; borderX < width; borderX++ {
screen.SetContent(borderX, 0, mauview.Borders.Horizontal, nil, border.Style)
2018-03-15 18:45:52 +01:00
}
}
}
2019-03-25 23:37:35 +01:00
func (border *Border) OnKeyEvent(event mauview.KeyEvent) bool {
return false
}
func (border *Border) OnPasteEvent(event mauview.PasteEvent) bool {
return false
}
func (border *Border) OnMouseEvent(event mauview.MouseEvent) bool {
return false
}