diff --git a/README.md b/README.md index eca7824..1ebfc01 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/box.go b/box.go index a552c3d..086ff5a 100644 --- a/box.go +++ b/box.go @@ -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) + } } } diff --git a/demos/modal/centered.png b/demos/modal/centered.png new file mode 100644 index 0000000..7511a05 Binary files /dev/null and b/demos/modal/centered.png differ diff --git a/flex.go b/flex.go index 5648b4a..4a7b419 100644 --- a/flex.go +++ b/flex.go @@ -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? diff --git a/grid.go b/grid.go index 2088647..f7d61a5 100644 --- a/grid.go +++ b/grid.go @@ -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