From a2885dd403f3b89210bb5cf8da968958b7ee73b1 Mon Sep 17 00:00:00 2001 From: Oliver <480930+rivo@users.noreply.github.com> Date: Sun, 19 May 2024 11:23:12 +0200 Subject: [PATCH] Fixed multiple items in grid. Fixes #987 --- CONTRIBUTING.md | 2 +- grid.go | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 92f6886..0f1db60 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -28,7 +28,7 @@ I'm very picky about the code that goes into this repo. So if you violate any of - Your code must follow the structure of the existing code. Don't just patch something on. Try to understand how `tview` is currently designed and follow that design. Your code needs to be consistent with existing code. - If you're adding code that increases the work required to maintain the project, you must be willing to take responsibility for that extra work. I will ask you to maintain your part of the code in the long run. - 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. Start all sentences upper-case, as is common in English, and end them with a period. +- 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. Start all sentences upper-case, as is common in English, and end them with a period. Comments in their own lines must not exceed the 80 character border. Break over if necessary. - A new function should be located close to related functions in the file. For example, `GetColor()` should come after (or before) `SetColor()`. - 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/grid.go b/grid.go index c191bfe..83648e4 100644 --- a/grid.go +++ b/grid.go @@ -281,11 +281,12 @@ ItemLoop: continue // Disqualified. } - // Check for overlaps. + // Check for overlaps and multiple layouts of the same item. for index, existing := range items { - // Do they overlap? - if item.Row >= existing.Row+existing.Height || item.Row+item.Height <= existing.Row || - item.Column >= existing.Column+existing.Width || item.Column+item.Width <= existing.Column { + // Do they overlap or are identical? + if item.Item != existing.Item && + (item.Row >= existing.Row+existing.Height || item.Row+item.Height <= existing.Row || + item.Column >= existing.Column+existing.Width || item.Column+item.Width <= existing.Column) { break // They don't. } @@ -303,7 +304,7 @@ ItemLoop: if itemMin < existingMin { continue ItemLoop // This one isn't. Drop it. } - items[index] = item + items[index] = item // This one is. Replace the other. continue ItemLoop }