Fix default background transparency of Flex and Grid

This commit is contained in:
Trevor Slocum 2020-05-24 21:40:34 -07:00
parent 093fa4d2ee
commit 961c23145c
6 changed files with 18 additions and 22 deletions

View File

@ -38,11 +38,9 @@ tview [blocks until the queued function returns](https://github.com/rivo/tview/b
All clicks are handled as single clicks until an interval is set with [Application.SetDoubleClickInterval](https://docs.rocketnine.space/gitlab.com/tslocum/cview/#Application.SetDoubleClickInterval).
## All primitives have non-transparent backgrounds by default
## Setting a primitive's background color to `tcell.ColorDefault` does not result in transparency
Setting background colors to `tcell.ColorDefault` is insufficient. Call
`SetBackgroundTransparent(true)` to enable background transparency. See
[#15](https://gitlab.com/tslocum/cview/-/issues/15) for more info.
Call `SetBackgroundTransparent(true)` to enable background transparency.
## Lists and Forms do not wrap around by default

6
doc.go
View File

@ -137,9 +137,9 @@ character that may be used in color or region tags will be recognized. Examples:
You can use the Escape() function to insert brackets automatically where needed.
Note that setting the background color of a primitive to tcell.ColorDefault is
insufficient to achieve transparency (having one or more widgets behind another
widget). Call SetBackgroundTransparent to enable transparency.
Setting the background color of a primitive to tcell.ColorDefault will use the
default terminal background color. To enable transparency (allowing one or more
primitives to display behind a primitive) call SetBackgroundTransparent.
Styles

11
flex.go
View File

@ -44,15 +44,14 @@ type Flex struct {
// direction set to FlexColumn. To add primitives to this layout, see AddItem().
// To change the direction, see SetDirection().
//
// Note that Box, the superclass of Flex, will have its background color set to
// transparent so that any nil flex items will leave their background unchanged.
// To clear a Flex's background before any items are drawn, set it to the
// desired color:
// Note that Flex will have a transparent background by default so that any nil
// flex items will show primitives behind the Flex.
// To disable this transparency:
//
// flex.SetBackgroundColor(cview.Styles.PrimitiveBackgroundColor)
// flex.SetBackgroundTransparent(false)
func NewFlex() *Flex {
f := &Flex{
Box: NewBox().SetBackgroundColor(tcell.ColorDefault),
Box: NewBox().SetBackgroundTransparent(true),
direction: FlexColumn,
}
f.focus = f

2
go.mod
View File

@ -8,5 +8,5 @@ require (
github.com/mattn/go-runewidth v0.0.9
github.com/rivo/uniseg v0.1.0
gitlab.com/tslocum/cbind v0.1.1
golang.org/x/sys v0.0.0-20200515095857-1151b9dac4a9 // indirect
golang.org/x/sys v0.0.0-20200523222454-059865788121 // indirect
)

4
go.sum
View File

@ -20,8 +20,8 @@ gitlab.com/tslocum/cbind v0.1.1/go.mod h1:rX7vkl0pUSg/yy427MmD1FZAf99S7WwpUlxF/q
golang.org/x/sys v0.0.0-20190626150813-e07cf5db2756 h1:9nuHUbU8dRnRRfj9KjWUVrJeoexdbeMjttk6Oh1rD10=
golang.org/x/sys v0.0.0-20190626150813-e07cf5db2756/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200515095857-1151b9dac4a9 h1:YTzHMGlqJu67/uEo1lBv0n3wBXhXNeUbB1XfN2vmTm0=
golang.org/x/sys v0.0.0-20200515095857-1151b9dac4a9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200523222454-059865788121 h1:rITEj+UZHYC927n8GT97eC3zrpzXdb/voyeOuVKS46o=
golang.org/x/sys v0.0.0-20200523222454-059865788121/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=

11
grid.go
View File

@ -61,15 +61,14 @@ type Grid struct {
// NewGrid returns a new grid-based layout container with no initial primitives.
//
// Note that Box, the superclass of Grid, will have its background color set to
// transparent so that any grid areas not covered by any primitives will leave
// their background unchanged. To clear a Grid's background before any items are
// drawn, set it to the desired color:
// Note that Grid will have a transparent background by default so that any
// areas not covered by any primitives will show primitives behind the Grid.
// To disable this transparency:
//
// grid.SetBackgroundColor(cview.Styles.PrimitiveBackgroundColor)
// grid.SetBackgroundTransparent(false)
func NewGrid() *Grid {
g := &Grid{
Box: NewBox().SetBackgroundColor(tcell.ColorDefault),
Box: NewBox().SetBackgroundTransparent(true),
bordersColor: Styles.GraphicsColor,
}
g.focus = g