Flex and Grid don't clear their backgrounds anymore. Resolves #104

This commit is contained in:
Oliver 2018-05-02 17:02:52 +02:00
parent f855bee020
commit d7d44cb0d2
5 changed files with 25 additions and 9 deletions

View File

@ -64,6 +64,8 @@ Add your issue here on GitHub. Feel free to get in touch if you have any questio
(There are no corresponding tags in the project. I only keep such a history in this README.)
- v0.15 (2018-05-02)
- `Flex` and `Grid` don't clear their background per default, thus allowing for custom modals. See the [Wiki](https://github.com/rivo/tview/wiki/Modal) for an example.
- v0.14 (2018-04-13)
- Added an `Escape()` function which keep strings like color or region tags from being recognized as such.
- Added `ANSIIWriter()` and `TranslateANSII()` which convert ANSII escape sequences to `tview` color tags.

8
box.go
View File

@ -223,9 +223,11 @@ func (b *Box) Draw(screen tcell.Screen) {
// Fill background.
background := def.Background(b.backgroundColor)
for y := b.y; y < b.y+b.height; y++ {
for x := b.x; x < b.x+b.width; x++ {
screen.SetContent(x, y, ' ', nil, background)
if b.backgroundColor != tcell.ColorDefault {
for y := b.y; y < b.y+b.height; y++ {
for x := b.x; x < b.x+b.width; x++ {
screen.SetContent(x, y, ' ', nil, background)
}
}
}

BIN
demos/modal/centered.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 74 KiB

15
flex.go
View File

@ -33,17 +33,24 @@ type Flex struct {
// FlexRow or FlexColumn.
direction int
// If set to true, will use the entire screen as its available space instead
// its box dimensions.
// If set to true, Flex will use the entire screen as its available space
// instead its box dimensions.
fullScreen bool
}
// NewFlex returns a new flexbox layout container with no primitives and its
// 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:
//
// flex.SetBackgroundColor(tview.Styles.PrimitiveBackgroundColor)
func NewFlex() *Flex {
f := &Flex{
Box: NewBox(),
Box: NewBox().SetBackgroundColor(tcell.ColorDefault),
direction: FlexColumn,
}
f.focus = f
@ -96,8 +103,6 @@ func (f *Flex) RemoveItem(p Primitive) *Flex {
// Draw draws this primitive onto the screen.
func (f *Flex) Draw(screen tcell.Screen) {
f.Box.Draw(screen)
// Calculate size and position of the items.
// Do we use the entire screen?

View File

@ -59,9 +59,16 @@ 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:
//
// grid.SetBackgroundColor(tview.Styles.PrimitiveBackgroundColor)
func NewGrid() *Grid {
g := &Grid{
Box: NewBox(),
Box: NewBox().SetBackgroundColor(tcell.ColorDefault),
bordersColor: Styles.GraphicsColor,
}
g.focus = g