From 383f5678a89fe121c951b1c77253c35223c55214 Mon Sep 17 00:00:00 2001 From: Grant Karapetyan Date: Tue, 17 Dec 2024 19:02:26 +0300 Subject: [PATCH] Notification history btn lifetime (#3885) * Notification history btn lifetime * update --- source/MRViewer/MRRibbonNotification.cpp | 45 ++++++++++++++++++++++++ source/MRViewer/MRRibbonNotification.h | 7 ++++ 2 files changed, 52 insertions(+) diff --git a/source/MRViewer/MRRibbonNotification.cpp b/source/MRViewer/MRRibbonNotification.cpp index 47f5d45bfc56..777c4af77c89 100644 --- a/source/MRViewer/MRRibbonNotification.cpp +++ b/source/MRViewer/MRRibbonNotification.cpp @@ -38,6 +38,7 @@ void RibbonNotifier::pushNotification( const RibbonNotification& notification ) addNotification_( notifications_, notification ); addNotification_( notificationsHistory_, notification ); + currentHistoryBtnTimer_ = showHistoryBtnMaxTime_; scrollDownNeeded_ = true; requestClosestRedraw_(); } @@ -52,12 +53,40 @@ void RibbonNotifier::draw( float scaling, const Box2i& limitFramebuffer ) filterInvalid_( -1 ); } +void RibbonNotifier::setHitoryButtonMaxLifeTime( float histBtnMaxLifeTime ) +{ + if ( showHistoryBtnMaxTime_ == histBtnMaxLifeTime ) + return; // do nothing + if ( showHistoryBtnMaxTime_ <= 0 && histBtnMaxLifeTime <= 0 ) + return; // do nothing + + if ( showHistoryBtnMaxTime_ <= 0 ) + { + currentHistoryBtnTimer_ = histBtnMaxLifeTime; + } + else + { + if ( currentHistoryBtnTimer_ > 0 ) + currentHistoryBtnTimer_ += ( histBtnMaxLifeTime - showHistoryBtnMaxTime_ ); // decrease current timer + } + showHistoryBtnMaxTime_ = histBtnMaxLifeTime; + requestClosestRedraw_(); +} + void RibbonNotifier::drawHistoryButton_( float scaling, const Box2i& limitFramebuffer ) { using namespace StyleConsts::Notification; if ( notificationsHistory_.empty() ) return; + if ( showHistoryBtnMaxTime_ > 0 ) + { + if ( currentHistoryBtnTimer_ >= 0 && !historyMode_ ) + currentHistoryBtnTimer_ -= ImGui::GetIO().DeltaTime; + if ( currentHistoryBtnTimer_ < 0 ) + return; + } + const auto windowSzie = ImVec2( 36, cHistoryButtonSizeY ) * scaling; Vector2f windowPos = Vector2f( float( limitFramebuffer.min.x ), float( getViewerInstance().framebufferSize.y - limitFramebuffer.min.y ) - windowSzie.y ); if ( cornerPosition == RibbonNotificationCorner::LowerRight ) @@ -113,6 +142,12 @@ void RibbonNotifier::drawHistoryButton_( float scaling, const Box2i& limitFrameb notifications_.clear(); scrollDownNeeded_ = true; } + else + { + currentHistoryBtnTimer_ = showHistoryBtnMaxTime_; + if ( currentHistoryBtnTimer_ > 0 ) + requestClosestRedraw_(); + } } auto drawList = window->DrawList; @@ -187,6 +222,9 @@ void RibbonNotifier::drawHistory_( float scaling, const Box2i& limitFramebuffer if ( lostFoucsClickCheck() ) { historyMode_ = false; + currentHistoryBtnTimer_ = showHistoryBtnMaxTime_; + if ( currentHistoryBtnTimer_ > 0 ) + requestClosestRedraw_(); } ImGui::End(); @@ -499,6 +537,13 @@ void RibbonNotifier::requestClosestRedraw_() if ( neededTime < minTimeReq ) minTimeReq = neededTime; } + + if ( showHistoryBtnMaxTime_ > 0 && currentHistoryBtnTimer_ > 0 ) + { + if ( currentHistoryBtnTimer_ < minTimeReq ) + minTimeReq = currentHistoryBtnTimer_; + } + if ( minTimeReq == FLT_MAX ) return; requestRedraw_ = true; diff --git a/source/MRViewer/MRRibbonNotification.h b/source/MRViewer/MRRibbonNotification.h index 4893070fc39c..f74e5ad68620 100644 --- a/source/MRViewer/MRRibbonNotification.h +++ b/source/MRViewer/MRRibbonNotification.h @@ -65,10 +65,15 @@ class MRVIEWER_CLASS RibbonNotifier public: // adds new notification for drawing MRVIEWER_API void pushNotification( const RibbonNotification& notification ); + // main draw function. draw actual notification or history, and history button // limitFramebuffer - available framebuffer space (usually same as `Viewer::getViewportsBounds()`) MRVIEWER_API void draw( float scaling, const Box2i& limitFramebuffer ); + // set maximum time while history button will be present on screen + // negative value means that history button will never be hidden + MRVIEWER_API void setHitoryButtonMaxLifeTime( float histBtnMaxLifeTime ); + // this value is used as notification `lifeTimeSec` if negative values passed float defaultNotificationLifeTimeSeconds = 5.0f; @@ -89,6 +94,8 @@ class MRVIEWER_CLASS RibbonNotifier bool requestRedraw_ = false; bool historyMode_ = false; + float showHistoryBtnMaxTime_{ -1.0f }; // negative value here means that there is no need to hide history button + float currentHistoryBtnTimer_{ -1.0f }; // update to validly hide the button #ifndef __EMSCRIPTEN__ Time requestedTime_{ Time::max() }; AsyncRequest asyncRequest_;