diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index c07595c..0d96292 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -28,3 +28,4 @@ I'm very picky about the code that goes into this repo. So if you violate any of - Function/type/variable/constant names must be as descriptive as they are right now. Follow the conventions of the package. - All functions/types/variables/constants, even private ones, must have comments in good English. These comments must be elaborate enough so that new users of the package understand them and can follow them. Provide examples if you have to. - Your changes must not decrease the project's [Go Report](https://goreportcard.com/report/github.com/rivo/tview) rating. +- No breaking changes unless there is absolutely no other way. diff --git a/README.md b/README.md index a98b2fd..689095b 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.11 (2018-03-02) + - Added a `RemoveItem()` function to `Grid` and `Flex`. - v0.10 (2018-02-22) - Direct access to the `screen` object through callback in `Box` (i.e. for all primitives). - v0.9 (2018-02-20) diff --git a/flex.go b/flex.go index cd24437..ec428bd 100644 --- a/flex.go +++ b/flex.go @@ -83,6 +83,17 @@ func (f *Flex) AddItem(item Primitive, fixedSize, proportion int, focus bool) *F return f } +// RemoveItem removes all items for the given primitive from the container, +// keeping the order of the remaining items intact. +func (f *Flex) RemoveItem(p Primitive) *Flex { + for index := len(f.items) - 1; index >= 0; index-- { + if f.items[index].Item == p { + f.items = append(f.items[:index], f.items[index+1:]...) + } + } + return f +} + // Draw draws this primitive onto the screen. func (f *Flex) Draw(screen tcell.Screen) { f.Box.Draw(screen) diff --git a/grid.go b/grid.go index f77ec71..5fc6ec3 100644 --- a/grid.go +++ b/grid.go @@ -202,6 +202,17 @@ func (g *Grid) AddItem(p Primitive, row, column, height, width, minGridHeight, m return g } +// RemoveItem removes all items for the given primitive from the grid, keeping +// the order of the remaining items intact. +func (g *Grid) RemoveItem(p Primitive) *Grid { + for index := len(g.items) - 1; index >= 0; index-- { + if g.items[index].Item == p { + g.items = append(g.items[:index], g.items[index+1:]...) + } + } + return g +} + // Clear removes all items from the grid. func (g *Grid) Clear() *Grid { g.items = nil