Skip to content

Commit 7f6610e

Browse files
committed
Add tab animations when creating/deleting tabs
1 parent cc28363 commit 7f6610e

2 files changed

Lines changed: 25 additions & 9 deletions

File tree

Source/TabComponent.cpp

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -240,11 +240,11 @@ class TabComponent::TabBarButtonComponent final : public Component {
240240
SafePointer<Canvas> cnv;
241241
TabComponent* parent;
242242
ScaledImage tabImage;
243-
bool isDragging = false;
244243
ComponentDragger dragger;
245244
TabDragConstrainer tabDragConstrainer;
246245

247246
CloseTabButton closeButton = CloseTabButton(Icons::Clear);
247+
bool isDragging : 1 = false;
248248
};
249249

250250
TabComponent::TabComponent(PluginEditor* editor)
@@ -383,7 +383,8 @@ Canvas* TabComponent::openPatch(pd::Patch::Ptr existingPatch, bool const warnIfA
383383
}
384384

385385
auto* cnv = canvases.add(new Canvas(editor, existingPatch));
386-
386+
newCanvases.insert(cnv);
387+
387388
auto const patchTitle = existingPatch->getTitle();
388389
// Open help files and references in Locked Mode
389390
if (patchTitle.contains("-help") || patchTitle.equalsIgnoreCase("reference"))
@@ -662,7 +663,16 @@ void TabComponent::handleAsyncUpdate()
662663
for (auto* cnv : getCanvases()) {
663664
cnv->saveViewportState();
664665
}
665-
666+
667+
UnorderedMap<Canvas*, Rectangle<int>> oldTabBounds;
668+
for(auto& tabbar : tabbars)
669+
{
670+
for(auto* tab : tabbar)
671+
{
672+
oldTabBounds.insert({tab->cnv, tab->getBounds()});
673+
}
674+
}
675+
666676
tabbars[0].clear();
667677
tabbars[1].clear();
668678

@@ -713,12 +723,22 @@ void TabComponent::handleAsyncUpdate()
713723

714724
if (!cnv) {
715725
cnv = canvases.add(new Canvas(editor, patch));
726+
newCanvases.insert(cnv);
716727
resized();
717728
cnv->restoreViewportState();
718729
}
719730

720731
// Create tab buttons
721732
auto* newTabButton = new TabBarButtonComponent(cnv, this);
733+
if(newCanvases.contains(cnv))
734+
{
735+
newTabButton->setBounds(getWidth(), 0, 0, 30);
736+
newCanvases.erase(cnv);
737+
}
738+
else if(oldTabBounds.contains(cnv)) {
739+
newTabButton->setBounds(oldTabBounds[cnv]);
740+
}
741+
722742
tabbars[patch->splitViewIndex == 1].add(newTabButton);
723743
addAndMakeVisible(newTabButton);
724744
}
@@ -957,7 +977,6 @@ void TabComponent::resized()
957977
}
958978

959979
bool wasOverflown = false;
960-
961980
for (auto* tabButton : tabButtons) {
962981
if (tabWidth > splitBounds.getWidth()) {
963982
wasOverflown = true;
@@ -977,11 +996,7 @@ void TabComponent::resized()
977996
continue; // We reserve space for it, but don't set the bounds to create a ghost tab
978997
}
979998

980-
if (draggingOverTabbar) {
981-
animator.animateComponent(tabButton, targetBounds, 1.0f, 200, false, 3.0, 0.0);
982-
} else {
983-
tabButton->setBounds(targetBounds);
984-
}
999+
animator.animateComponent(tabButton, targetBounds, 1.0f, 200, false, 3.0, 0.0);
9851000
}
9861001

9871002
tabOverflowButtons[i].setVisible(wasOverflown);

Source/TabComponent.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ class TabComponent final : public Component
8989
StackArray<SmallArray<SafePointer<Canvas>, 12>, 2> lastShownTabs;
9090

9191
StackArray<pd::Patch*, 2> lastSplitPatches { nullptr, nullptr };
92+
UnorderedSet<Canvas*> newCanvases;
9293
t_glist* lastActiveCanvas = nullptr;
9394

9495
bool draggingOverTabbar = false;

0 commit comments

Comments
 (0)