Skip to content

Commit

Permalink
Notification history btn lifetime (#3885)
Browse files Browse the repository at this point in the history
* Notification history btn lifetime

* update
  • Loading branch information
Grantim authored Dec 17, 2024
1 parent c0c1e0b commit 383f567
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
45 changes: 45 additions & 0 deletions source/MRViewer/MRRibbonNotification.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ void RibbonNotifier::pushNotification( const RibbonNotification& notification )
addNotification_( notifications_, notification );
addNotification_( notificationsHistory_, notification );

currentHistoryBtnTimer_ = showHistoryBtnMaxTime_;
scrollDownNeeded_ = true;
requestClosestRedraw_();
}
Expand All @@ -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 )
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -187,6 +222,9 @@ void RibbonNotifier::drawHistory_( float scaling, const Box2i& limitFramebuffer
if ( lostFoucsClickCheck() )
{
historyMode_ = false;
currentHistoryBtnTimer_ = showHistoryBtnMaxTime_;
if ( currentHistoryBtnTimer_ > 0 )
requestClosestRedraw_();
}

ImGui::End();
Expand Down Expand Up @@ -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;
Expand Down
7 changes: 7 additions & 0 deletions source/MRViewer/MRRibbonNotification.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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_;
Expand Down

0 comments on commit 383f567

Please sign in to comment.