From 906331c5a512e54424b148a2a89590bc03a704ff Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sun, 13 Aug 2017 00:12:19 +0300 Subject: Change height in item containers if some items hidden by filter. --- src/gui/widgets/itemcontainer.cpp | 25 ++++++++++++++++++++----- src/gui/widgets/itemcontainer.h | 3 ++- 2 files changed, 22 insertions(+), 6 deletions(-) (limited to 'src/gui') diff --git a/src/gui/widgets/itemcontainer.cpp b/src/gui/widgets/itemcontainer.cpp index f53af32a6..5f1cd4b05 100644 --- a/src/gui/widgets/itemcontainer.cpp +++ b/src/gui/widgets/itemcontainer.cpp @@ -242,6 +242,7 @@ ItemContainer::ItemContainer(const Widget2 *const widget, mSelectionListeners(), mGridColumns(1), mGridRows(1), + mDrawRows(1), mSelectedIndex(-1), mLastUsedSlot(-1), mTag(0), @@ -1080,14 +1081,26 @@ void ItemContainer::adjustHeight() mGridRows = maxRows; } + const int num = updateMatrix(); + if (mShowEmptyRows == ShowEmptyRows_false) + { + mDrawRows = num / mGridColumns; + if (mDrawRows == 0 || num % mGridColumns > 0) + ++mDrawRows; + + maxRows = mDrawRows; + } + else + { + mDrawRows = mGridRows; + } setHeight(maxRows * mBoxHeight); - updateMatrix(); } -void ItemContainer::updateMatrix() +int ItemContainer::updateMatrix() { if (mInventory == nullptr) - return; + return 0; mRedraw = true; delete []mShowMatrix; @@ -1175,8 +1188,10 @@ void ItemContainer::updateMatrix() for (int idx = j * mGridColumns + i; idx < maxSize; idx ++) mShowMatrix[idx] = -1; - for (size_t idx = 0, sz = sortedItems.size(); idx < sz; idx ++) + const int num = CAST_S32(sortedItems.size()); + for (size_t idx = 0, sz = num; idx < sz; idx ++) delete sortedItems[idx]; + return num; } int ItemContainer::getSlotIndex(int x, int y) const @@ -1219,7 +1234,7 @@ int ItemContainer::getSlotByXY(int x, int y) const void ItemContainer::setFilter(const int tag) { mTag = tag; - updateMatrix(); + adjustHeight(); } void ItemContainer::setSortType(const int sortType) diff --git a/src/gui/widgets/itemcontainer.h b/src/gui/widgets/itemcontainer.h index ba640d374..c992c43f5 100644 --- a/src/gui/widgets/itemcontainer.h +++ b/src/gui/widgets/itemcontainer.h @@ -123,7 +123,7 @@ class ItemContainer final : public Widget, void setName(const std::string &str) { mName = str; } - void updateMatrix(); + int updateMatrix(); bool getClickCount() const noexcept2 A_WARN_UNUSED { return mClicks != 0; } @@ -202,6 +202,7 @@ class ItemContainer final : public Widget, SelectionListenerList mSelectionListeners; int mGridColumns; int mGridRows; + int mDrawRows; int mSelectedIndex; int mLastUsedSlot; int mTag; -- cgit v1.2.3-70-g09d2