commit 6f41229358e7fc91b5dc1d2824d3dab8fb876ca3
parent 285cd7128e255a73987f30fae7aab2cdcc5949fe
Author: dsp56300 <dsp56300@users.noreply.github.com>
Date: Sun, 14 Jul 2024 17:50:07 +0200
apply 128 patches layout when switchting to grid for the first time
Diffstat:
4 files changed, 65 insertions(+), 3 deletions(-)
diff --git a/source/jucePluginEditorLib/patchmanager/grid.cpp b/source/jucePluginEditorLib/patchmanager/grid.cpp
@@ -35,6 +35,34 @@ namespace jucePluginEditorLib::patchManager
Component::paint(g);
}
+ void Grid::setItemWidth(const float _width)
+ {
+ if(m_itemWidth == _width)
+ return;
+
+ m_itemWidth = _width;
+ updateViewportSize();
+ }
+
+ void Grid::setItemHeight(float _height)
+ {
+ if(_height <= 0.0f)
+ return;
+
+ m_itemHeight = _height;
+ m_suggestedItemsPerRow = 0;
+ updateViewportSize();
+ }
+
+ void Grid::setSuggestedItemsPerRow(uint32_t _count)
+ {
+ if(m_suggestedItemsPerRow == _count)
+ return;
+
+ m_suggestedItemsPerRow = _count;
+ updateViewportSize();
+ }
+
void Grid::setVisibleItemRange(const std::pair<uint32_t, uint32_t>& _range)
{
const auto& start = _range.first;
@@ -187,7 +215,8 @@ namespace jucePluginEditorLib::patchManager
void Grid::updateViewportSize()
{
const auto availableHeight = getHeight() - m_viewport.getScrollBarThickness() - 1;
- m_itemHeight = static_cast<float>(availableHeight) / 32.0f;
+ if(m_suggestedItemsPerRow)
+ m_itemHeight = static_cast<float>(availableHeight) / static_cast<float>(m_suggestedItemsPerRow);
m_itemContainer.setSize(static_cast<int>(m_itemWidth * static_cast<float>(getNeededColumnCount())), availableHeight);
m_viewport.setSize(getWidth(), getHeight());
diff --git a/source/jucePluginEditorLib/patchmanager/grid.h b/source/jucePluginEditorLib/patchmanager/grid.h
@@ -21,6 +21,11 @@ namespace jucePluginEditorLib::patchManager
auto getItemWidth() const { return m_itemWidth; }
auto getItemHeight() const { return m_itemHeight; }
+ auto getSuggestedItemsPerRow() const { return m_suggestedItemsPerRow; }
+
+ void setItemWidth(float _width);
+ void setItemHeight(float _height);
+ void setSuggestedItemsPerRow(uint32_t _count);
void setVisibleItemRange(const std::pair<uint32_t, uint32_t>& _range);
@@ -61,6 +66,7 @@ namespace jucePluginEditorLib::patchManager
private:
float m_itemHeight = 15;
float m_itemWidth = 140;
+ uint32_t m_suggestedItemsPerRow = 32;
GridViewport m_viewport;
GridItemContainer m_itemContainer;
diff --git a/source/jucePluginEditorLib/patchmanager/patchmanager.cpp b/source/jucePluginEditorLib/patchmanager/patchmanager.cpp
@@ -246,7 +246,31 @@ namespace jucePluginEditorLib::patchManager
dynamic_cast<Component*>(newModel)->setVisible(true);
dynamic_cast<Component*>(oldModel)->setVisible(false);
+ if(m_firstTimeGridLayout && _layout == LayoutType::Grid)
+ {
+ m_firstTimeGridLayout = false;
+ setGridLayout128();
+ }
+ else
+ {
+ resized();
+ }
+ }
+
+ bool PatchManager::setGridLayout128()
+ {
+ if(m_layout != LayoutType::Grid)
+ return false;
+
+ const auto columnCount = 128.0f / static_cast<float>(m_grid->getSuggestedItemsPerRow());
+
+ const auto pos = static_cast<int>(static_cast<float>(getWidth()) - m_grid->getItemWidth() * columnCount - static_cast<float>(m_resizerBarB.getWidth()));
+
+ m_stretchableManager.setItemPosition(3, pos - 1); // prevent rounding issues
+
resized();
+
+ return true;
}
bool PatchManager::selectPatch(const uint32_t _part, const int _offset)
@@ -494,7 +518,7 @@ namespace jucePluginEditorLib::patchManager
return true;
}
- void PatchManager::setListStatus(uint32_t _selected, uint32_t _total)
+ void PatchManager::setListStatus(uint32_t _selected, uint32_t _total) const
{
m_status->setListStatus(_selected, _total);
}
diff --git a/source/jucePluginEditorLib/patchmanager/patchmanager.h b/source/jucePluginEditorLib/patchmanager/patchmanager.h
@@ -59,7 +59,7 @@ namespace jucePluginEditorLib::patchManager
bool selectPatch(uint32_t _part, const pluginLib::patchDB::DataSource& _ds, uint32_t _program);
- void setListStatus(uint32_t _selected, uint32_t _total);
+ void setListStatus(uint32_t _selected, uint32_t _total) const;
pluginLib::patchDB::Color getPatchColor(const pluginLib::patchDB::PatchPtr& _patch) const;
@@ -103,6 +103,8 @@ namespace jucePluginEditorLib::patchManager
LayoutType getLayout() const { return m_layout; }
void setLayout(LayoutType _layout);
+ bool setGridLayout128();
+
private:
bool selectPatch(uint32_t _part, int _offset);
@@ -167,5 +169,6 @@ namespace jucePluginEditorLib::patchManager
std::unordered_map<pluginLib::patchDB::TagType, std::string> m_tagTypeNames;
LayoutType m_layout = LayoutType::List;
+ bool m_firstTimeGridLayout = true;
};
}