Skip to content

Commit

Permalink
[SUTK] Distinguise between voluntary end and involuntary end of the a…
Browse files Browse the repository at this point in the history
…nimations (abort)

And check again for grabbed tab if it is overlapping again and shift tabs accordingly.
  • Loading branch information
ravi688 committed Nov 20, 2024
1 parent 17d8f90 commit 7a5175b
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 19 deletions.
6 changes: 3 additions & 3 deletions sutk/include/sutk/AnimationEngine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ namespace SUTK
// Must be implemented by deriving class
virtual void onStep(f32 deltaValue) noexcept = 0;
// Must be called in the end of the overriding method
virtual void onEnd() noexcept
virtual void onEnd(com::Bool isAborted) noexcept
{
if(m_group)
m_group->absent(this);
Expand Down Expand Up @@ -136,7 +136,7 @@ namespace SUTK
if(m_group)
{
m_isStarted = com::False;
onEnd();
onEnd(com::True);
// TODO: optimize this,
// if abort() is called during traversal of m_group->m_anims
// and if this animation equals to the current animation
Expand All @@ -152,7 +152,7 @@ namespace SUTK
if(it != animContexts.end())
{
m_isStarted = com::False;
onEnd();
onEnd(com::True);
animContexts.erase(animContexts.indexToIterator(std::distance(animContexts.begin(), it)));
}
else
Expand Down
6 changes: 6 additions & 0 deletions sutk/include/sutk/NotebookView.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ namespace SUTK
virtual void onWhenAllEnd() noexcept override;
public:
TabAnimGroup(UIDriver& driver, NotebookView* notebook) noexcept;
NotebookView* getNotebook() noexcept { return m_notebook; }
};

class TabShiftAnimation;
Expand All @@ -138,9 +139,13 @@ namespace SUTK
std::vector<TabShiftAnimation*> m_inFlightLeftShifts;
std::vector<TabShiftAnimation*> m_inFlightRightShifts;
com::Bool m_isAborting;
protected:
virtual void onPresent(AnimationEngine::AnimContextBase* animContext) noexcept override;
virtual void onAbsent(AnimationEngine::AnimContextBase* animContext) noexcept override;
public:
TabShiftAnimGroup(UIDriver& driver, NotebookView* notebook) noexcept;

NotebookView* getNotebook() noexcept { return m_notebook; }
void abort() noexcept;
};

Expand Down Expand Up @@ -185,6 +190,7 @@ namespace SUTK
public:
NotebookView(UIDriver& driver, Container* parent, com::Bool isLayoutIgnore = com::False, Layer layer = InvalidLayer) noexcept;
~NotebookView() noexcept;
void checkForTabSwap() noexcept;

OnPageSelectEvent& getOnPageSelectEvent() noexcept { return m_onPageSelectEvent; }

Expand Down
4 changes: 2 additions & 2 deletions sutk/source/AnimationEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace SUTK
if(ctx->step(getRunnableUIDriver().getDeltaTime()))
{
ctx->m_isStarted = com::False;
ctx->onEnd();
ctx->onEnd(com::False);
// Now this animation has been completed, and should be now be destroyed
this->m_animContexts.eraseCurrent();
delete ctx;
Expand All @@ -50,7 +50,7 @@ namespace SUTK
if(ctx->step(ctx->getUIDriver().getDeltaTime()))
{
ctx->m_isStarted = com::False;
ctx->onEnd();
ctx->onEnd(com::False);
// Now this animation has been completed, and should be now be destroyed
ctx->m_group->getAnims().eraseCurrent();
ctx->m_group = com::null_pointer<AnimGroup>();
Expand Down
46 changes: 32 additions & 14 deletions sutk/source/NotebookView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ namespace SUTK
LayoutAttributes& attr = m_tab->getLayoutAttributes();
attr.prefSize = m_tab->getSize();
}
virtual void onEnd() noexcept override
virtual void onEnd(com::Bool isAborted) noexcept override
{
auto node = m_tab->getNext();
while(node)
Expand All @@ -238,7 +238,7 @@ namespace SUTK
node = node->getNext();
}
m_tab->getUIDriver().destroyContainer<TabView>(m_tab);
AnimContextBase::onEnd();
AnimContextBase::onEnd(isAborted);
}
public:
TabRemoveAnimation(UIDriver& driver, TabAnimGroup* group, TabView* tab) noexcept : AnimContextBase(driver, group), m_tab(tab) { }
Expand All @@ -262,7 +262,7 @@ namespace SUTK
{
m_tab->moveRight(deltaValue);
}
virtual void onEnd() noexcept override
virtual void onEnd(com::Bool isAborted) noexcept override
{
if(m_isLeft)
{
Expand Down Expand Up @@ -294,7 +294,10 @@ namespace SUTK
dynamic_cast<TabView*>(tabContainer->getChilds()[swapIndex])->m_index = swapIndex;
m_tab->m_index = index;

AnimContextBase::onEnd();
if(!isAborted)
dynamic_cast<TabShiftAnimGroup*>(getAnimGroup())->getNotebook()->checkForTabSwap();

AnimContextBase::onEnd(isAborted);
}
public:
TabShiftAnimation(UIDriver& driver, TabShiftAnimGroup* group, TabView* tab, com::Bool isLeft) noexcept : AnimContextBase(driver, group), m_tab(tab), m_isLeft(isLeft) { }
Expand Down Expand Up @@ -350,6 +353,14 @@ namespace SUTK

}

void TabShiftAnimGroup::onPresent(AnimationEngine::AnimContextBase* animContext) noexcept
{

}
void TabShiftAnimGroup::onAbsent(AnimationEngine::AnimContextBase* animContext) noexcept
{

}
TabShiftAnimGroup::TabShiftAnimGroup(UIDriver& driver, NotebookView* notebook) noexcept : AnimGroup(driver), m_notebook(notebook), m_isAborting(com::False)
{

Expand All @@ -363,18 +374,11 @@ namespace SUTK
});
}

void NotebookView::onMouseMove(Vec2Df pos) noexcept
void NotebookView::checkForTabSwap() noexcept
{
TabView* tabView = this->m_tabRearrangeContext.grabbedTabView;
if(!m_tabRearrangeContext.isMoved)
{
m_tabRearrangeContext.layer = tabView->getLayer();
tabView->setLayer(MaxLayer);
m_tabRearrangeContext.isMoved = com::True;
}
pos = m_tabRearrangeContext.positionOffset + tabView->getParent()->getScreenCoordsToLocalCoords(pos);
tabView->setPosition(pos);
TabView* tabView = m_tabRearrangeContext.grabbedTabView;
TabView* next = tabView->getNext();
auto pos = tabView->getPosition();
if(next)
{
f32 middle = next->getPosition().x + next->getSize().width * 0.5f;
Expand Down Expand Up @@ -404,6 +408,20 @@ namespace SUTK
}
}

void NotebookView::onMouseMove(Vec2Df pos) noexcept
{
TabView* tabView = this->m_tabRearrangeContext.grabbedTabView;
if(!m_tabRearrangeContext.isMoved)
{
m_tabRearrangeContext.layer = tabView->getLayer();
tabView->setLayer(MaxLayer);
m_tabRearrangeContext.isMoved = com::True;
}
pos = m_tabRearrangeContext.positionOffset + tabView->getParent()->getScreenCoordsToLocalCoords(pos);
tabView->setPosition(pos);
checkForTabSwap();
}

void NotebookView::abortTabAnim() noexcept
{
// for(auto& ctx : m_animContexts)
Expand Down

0 comments on commit 7a5175b

Please sign in to comment.