1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

Added some methods to TabbedButtonBar for animating tab movements.

This commit is contained in:
jules 2013-11-16 22:11:48 +00:00
parent d911633e0b
commit ac7271c10b
2 changed files with 35 additions and 6 deletions

View file

@ -299,12 +299,12 @@ void TabbedButtonBar::removeTab (const int tabIndex)
resized();
}
void TabbedButtonBar::moveTab (const int currentIndex, const int newIndex)
void TabbedButtonBar::moveTab (const int currentIndex, const int newIndex, const bool animate)
{
TabInfo* const currentTab = tabs [currentTabIndex];
tabs.move (currentIndex, newIndex);
currentTabIndex = tabs.indexOf (currentTab);
resized();
updateTabPositions (animate);
}
int TabbedButtonBar::getNumTabs() const
@ -369,6 +369,16 @@ int TabbedButtonBar::indexOfTabButton (const TabBarButton* button) const
return -1;
}
Rectangle<int> TabbedButtonBar::getTargetBounds (TabBarButton* button) const
{
if (button == nullptr || indexOfTabButton (button) == -1)
return Rectangle<int>();
ComponentAnimator& animator = Desktop::getInstance().getAnimator();
return animator.isAnimating (button) ? animator.getComponentDestination (button) : button->getBounds();
}
void TabbedButtonBar::lookAndFeelChanged()
{
extraTabsButton = nullptr;
@ -381,6 +391,12 @@ void TabbedButtonBar::paint (Graphics& g)
}
void TabbedButtonBar::resized()
{
updateTabPositions (false);
}
//==============================================================================
void TabbedButtonBar::updateTabPositions (bool animate)
{
LookAndFeel& lf = getLookAndFeel();
@ -462,6 +478,7 @@ void TabbedButtonBar::resized()
int pos = 0;
TabBarButton* frontTab = nullptr;
ComponentAnimator& animator = Desktop::getInstance().getAnimator();
for (int i = 0; i < tabs.size(); ++i)
{
@ -471,10 +488,18 @@ void TabbedButtonBar::resized()
if (i < numVisibleButtons)
{
if (isVertical())
tb->setBounds (0, pos, getWidth(), bestLength);
const Rectangle<int> newBounds (isVertical() ? Rectangle<int> (0, pos, getWidth(), bestLength)
: Rectangle<int> (pos, 0, bestLength, getHeight()));
if (animate)
{
animator.animateComponent (tb, newBounds, 1.0f, 200, false, 3.0, 0.0);
}
else
tb->setBounds (pos, 0, bestLength, getHeight());
{
animator.cancelAnimation (tb, false);
tb->setBounds (newBounds);
}
tb->toBack();

View file

@ -217,7 +217,7 @@ public:
/** Moves a tab to a new index in the list.
Pass -1 as the index to move it to the end of the list.
*/
void moveTab (int currentIndex, int newIndex);
void moveTab (int currentIndex, int newIndex, bool animate = false);
/** Returns the number of tabs in the bar. */
int getNumTabs() const;
@ -254,6 +254,9 @@ public:
/** Returns the index of a TabBarButton if it belongs to this bar. */
int indexOfTabButton (const TabBarButton* button) const;
/** Returns the final bounds of this button if it is currently being animated. */
Rectangle<int> getTargetBounds (TabBarButton* button) const;
//==============================================================================
/** Callback method to indicate the selected tab has been changed.
@see setCurrentTabIndex
@ -357,6 +360,7 @@ private:
void showExtraItemsMenu();
static void extraItemsMenuCallback (int, TabbedButtonBar*);
void updateTabPositions (bool animate);
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (TabbedButtonBar)
};