mirror of
https://github.com/rivo/tview.git
synced 2025-05-01 22:18:30 +08:00
Added style attributes to Box border. Resolves #152
This commit is contained in:
parent
bc005edd52
commit
c325864561
14
box.go
14
box.go
@ -32,6 +32,9 @@ type Box struct {
|
|||||||
// The color of the border.
|
// The color of the border.
|
||||||
borderColor tcell.Color
|
borderColor tcell.Color
|
||||||
|
|
||||||
|
// The style attributes of the border.
|
||||||
|
borderAttributes tcell.AttrMask
|
||||||
|
|
||||||
// The title. Only visible if there is a border, too.
|
// The title. Only visible if there is a border, too.
|
||||||
title string
|
title string
|
||||||
|
|
||||||
@ -193,6 +196,15 @@ func (b *Box) SetBorderColor(color tcell.Color) *Box {
|
|||||||
return b
|
return b
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetBorderAttributes sets the border's style attributes. You can combine
|
||||||
|
// different attributes using bitmask operations:
|
||||||
|
//
|
||||||
|
// box.SetBorderAttributes(tcell.AttrUnderline | tcell.AttrBold)
|
||||||
|
func (b *Box) SetBorderAttributes(attr tcell.AttrMask) *Box {
|
||||||
|
b.borderAttributes = attr
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
|
||||||
// SetTitle sets the box's title.
|
// SetTitle sets the box's title.
|
||||||
func (b *Box) SetTitle(title string) *Box {
|
func (b *Box) SetTitle(title string) *Box {
|
||||||
b.title = title
|
b.title = title
|
||||||
@ -233,7 +245,7 @@ func (b *Box) Draw(screen tcell.Screen) {
|
|||||||
|
|
||||||
// Draw border.
|
// Draw border.
|
||||||
if b.border && b.width >= 2 && b.height >= 2 {
|
if b.border && b.width >= 2 && b.height >= 2 {
|
||||||
border := background.Foreground(b.borderColor)
|
border := background.Foreground(b.borderColor) | tcell.Style(b.borderAttributes)
|
||||||
var vertical, horizontal, topLeft, topRight, bottomLeft, bottomRight rune
|
var vertical, horizontal, topLeft, topRight, bottomLeft, bottomRight rune
|
||||||
if b.focus.HasFocus() {
|
if b.focus.HasFocus() {
|
||||||
horizontal = Borders.HorizontalFocus
|
horizontal = Borders.HorizontalFocus
|
||||||
|
@ -1,11 +1,15 @@
|
|||||||
// Demo code for the Box primitive.
|
// Demo code for the Box primitive.
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import "github.com/rivo/tview"
|
import (
|
||||||
|
"github.com/gdamore/tcell"
|
||||||
|
"github.com/rivo/tview"
|
||||||
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
box := tview.NewBox().
|
box := tview.NewBox().
|
||||||
SetBorder(true).
|
SetBorder(true).
|
||||||
|
SetBorderAttributes(tcell.AttrBold).
|
||||||
SetTitle("A [red]c[yellow]o[green]l[darkcyan]o[blue]r[darkmagenta]f[red]u[yellow]l[white] [black:red]c[:yellow]o[:green]l[:darkcyan]o[:blue]r[:darkmagenta]f[:red]u[:yellow]l[white:] [::bu]title")
|
SetTitle("A [red]c[yellow]o[green]l[darkcyan]o[blue]r[darkmagenta]f[red]u[yellow]l[white] [black:red]c[:yellow]o[:green]l[:darkcyan]o[:blue]r[:darkmagenta]f[:red]u[:yellow]l[white:] [::bu]title")
|
||||||
if err := tview.NewApplication().SetRoot(box, true).Run(); err != nil {
|
if err := tview.NewApplication().SetRoot(box, true).Run(); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user