diff --git a/sutk/include/sutk/AnimationEngine.hpp b/sutk/include/sutk/AnimationEngine.hpp index 44dfe9d3..d1e28500 100644 --- a/sutk/include/sutk/AnimationEngine.hpp +++ b/sutk/include/sutk/AnimationEngine.hpp @@ -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); @@ -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 @@ -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 diff --git a/sutk/include/sutk/NotebookView.hpp b/sutk/include/sutk/NotebookView.hpp index 10d4f343..f819d5c7 100644 --- a/sutk/include/sutk/NotebookView.hpp +++ b/sutk/include/sutk/NotebookView.hpp @@ -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; @@ -138,9 +139,13 @@ namespace SUTK std::vector m_inFlightLeftShifts; std::vector 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; }; @@ -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; } diff --git a/sutk/source/AnimationEngine.cpp b/sutk/source/AnimationEngine.cpp index 5db9e3d5..e0b2e40f 100644 --- a/sutk/source/AnimationEngine.cpp +++ b/sutk/source/AnimationEngine.cpp @@ -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; @@ -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(); diff --git a/sutk/source/NotebookView.cpp b/sutk/source/NotebookView.cpp index 2bb1847f..fefbd1e8 100644 --- a/sutk/source/NotebookView.cpp +++ b/sutk/source/NotebookView.cpp @@ -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) @@ -238,7 +238,7 @@ namespace SUTK node = node->getNext(); } m_tab->getUIDriver().destroyContainer(m_tab); - AnimContextBase::onEnd(); + AnimContextBase::onEnd(isAborted); } public: TabRemoveAnimation(UIDriver& driver, TabAnimGroup* group, TabView* tab) noexcept : AnimContextBase(driver, group), m_tab(tab) { } @@ -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) { @@ -294,7 +294,10 @@ namespace SUTK dynamic_cast(tabContainer->getChilds()[swapIndex])->m_index = swapIndex; m_tab->m_index = index; - AnimContextBase::onEnd(); + if(!isAborted) + dynamic_cast(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) { } @@ -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) { @@ -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; @@ -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)