From 22c815664a764f3b9cc10f162e9d6a63d1487b8a Mon Sep 17 00:00:00 2001 From: ravi688 Date: Tue, 7 Jan 2025 21:50:39 +0530 Subject: [PATCH] [SUTK] Bring tab associated with currently viewed NotebookPage into view of TabBar's ScrollContainer - Affected test: NOTEBOOK - Changes can be noticed by adding many new tabs and the newly created tab should come into view (i.e. shouldn't be hiding on the either side). --- sutk/include/sutk/NotebookView.hpp | 13 +++++++++++-- sutk/source/NotebookView.cpp | 15 +++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/sutk/include/sutk/NotebookView.hpp b/sutk/include/sutk/NotebookView.hpp index c87e7630..f28aa860 100644 --- a/sutk/include/sutk/NotebookView.hpp +++ b/sutk/include/sutk/NotebookView.hpp @@ -136,7 +136,16 @@ namespace SUTK Tab* getSelectedTab() noexcept { return m_selectedTab; } }; - typedef MaskedScrollableContainer ScrollableTabBar; + class SUTK_API ScrollableTabBar : public MaskedScrollableContainer + { + using MaskedScrollableContainer::MaskedScrollableContainer; + public: + // Brings (instantaneously) TabView associated with the Tab under the area of ScrollContainer of this ScrollableTabBar. + // If the Tab is hiding on the right side of the ScrollContainer, then the Tab is brought into view on the Right side + // If the Tab is hiding on the left side of the ScrollContainer, then the Tab is brought into view on the Left side + // No action is taken if the Tab is already into view. + void scrollToTab(Tab* tab) noexcept; + }; class TabRemoveAnimation; class TabInsertAnimation; @@ -231,7 +240,7 @@ namespace SUTK ~NotebookView() noexcept; void checkForTabSwap() noexcept; - TabBar* getTabBar() noexcept { return m_tabBar; } + ScrollableTabBar* getTabBar() noexcept { return m_tabBar; } OnPageSelectEvent& getOnPageSelectEvent() noexcept { return m_onPageSelectEvent; } diff --git a/sutk/source/NotebookView.cpp b/sutk/source/NotebookView.cpp index 7e4e08bd..af80786f 100644 --- a/sutk/source/NotebookView.cpp +++ b/sutk/source/NotebookView.cpp @@ -594,6 +594,19 @@ namespace SUTK } } + void ScrollableTabBar::scrollToTab(Tab* tab) noexcept + { + ScrollContainer* scrollCont = getScrollContainer(); + // Get rectangle of TabView in the local space of ScrollContainer + auto rect = tab->getTabView()->getRectRelativeTo(scrollCont); + // If the TabView is hiding on the right side of the ScrollContainer then scroll to left + if(f32 distance = rect.getRight() - scrollCont->getSize().width; distance > 0) + scrollCont->addScrollDelta(Vec2Df::left() * distance); + // else If the TabView is hiding on the left side of the ScrollContainer then scroll to right + else if(f32 distance = rect.getLeft() - scrollCont->getPosition().x; distance < 0) + scrollCont->addScrollDelta(Vec2Df::left() * distance); + } + Tab* NotebookView::createTab(const std::string_view labelStr, NotebookPage* page, Tab* afterTab) noexcept { // Create TabView @@ -656,6 +669,8 @@ namespace SUTK void NotebookView::viewPage(NotebookPage* page) noexcept { m_tabBar->selectTab(page->getTab()); + // The tab associated with this page must be in the view + m_tabBar->scrollToTab(page->getTab()); } static NotebookPage* GetAdjacentPage(NotebookPage* page) noexcept