gearmulator

Emulation of classic VA synths of the late 90s/2000s that are based on Motorola 56300 family DSPs
Log | Files | Refs | Submodules | README | LICENSE

tabgroup.cpp (1177B)


      1 #include "tabgroup.h"
      2 
      3 #include "editor.h"
      4 
      5 namespace genericUI
      6 {
      7 	TabGroup::TabGroup(std::string _name, std::vector<std::string> _pageNames, std::vector<std::string> _buttonNames)
      8 		: m_name(std::move(_name))
      9 		, m_pageNames(std::move(_pageNames))
     10 		, m_buttonNames(std::move(_buttonNames))
     11 	{
     12 	}
     13 
     14 	void TabGroup::create(const Editor& _editor)
     15 	{
     16 		for (const auto& pageName : m_pageNames)
     17 			m_tabs.push_back(_editor.findComponent(pageName));
     18 
     19 		for (const auto& buttonName : m_buttonNames)
     20 			m_tabButtons.push_back(_editor.findComponentT<juce::Button>(buttonName));
     21 
     22 		for(size_t i=0; i<m_tabButtons.size(); ++i)
     23 			m_tabButtons[i]->onClick = [this, i] { setPage(i); };
     24 
     25 		setPage(0);
     26 	}
     27 
     28 	bool TabGroup::selectTabWithComponent(const juce::Component* _component) const
     29 	{
     30 		for (size_t i=0; i<m_tabs.size(); ++i)
     31 		{
     32 			if (m_tabs[i] == _component || m_tabs[i]->isParentOf(_component))
     33 			{
     34 				setPage(i);
     35 				return true;
     36 			}
     37 		}
     38 		return false;
     39 	}
     40 
     41 	void TabGroup::setPage(const size_t _page) const
     42 	{
     43 		for(size_t i=0; i<m_tabs.size(); ++i)
     44 		{
     45 			m_tabs[i]->setVisible(_page == i);
     46 			m_tabButtons[i]->setToggleState(_page == i, juce::dontSendNotification);
     47 		}
     48 	}
     49 }