Added RemoveItem() to Grid and Flex. Resolves #63

pull/62/merge
Oliver 6 years ago
parent a5c65a977d
commit 3bac79f308

@ -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.

@ -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)

@ -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)

@ -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

Loading…
Cancel
Save