Skip to content

Commit 383f567

Browse files
authored
Notification history btn lifetime (#3885)
* Notification history btn lifetime * update
1 parent c0c1e0b commit 383f567

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

source/MRViewer/MRRibbonNotification.cpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ void RibbonNotifier::pushNotification( const RibbonNotification& notification )
3838
addNotification_( notifications_, notification );
3939
addNotification_( notificationsHistory_, notification );
4040

41+
currentHistoryBtnTimer_ = showHistoryBtnMaxTime_;
4142
scrollDownNeeded_ = true;
4243
requestClosestRedraw_();
4344
}
@@ -52,12 +53,40 @@ void RibbonNotifier::draw( float scaling, const Box2i& limitFramebuffer )
5253
filterInvalid_( -1 );
5354
}
5455

56+
void RibbonNotifier::setHitoryButtonMaxLifeTime( float histBtnMaxLifeTime )
57+
{
58+
if ( showHistoryBtnMaxTime_ == histBtnMaxLifeTime )
59+
return; // do nothing
60+
if ( showHistoryBtnMaxTime_ <= 0 && histBtnMaxLifeTime <= 0 )
61+
return; // do nothing
62+
63+
if ( showHistoryBtnMaxTime_ <= 0 )
64+
{
65+
currentHistoryBtnTimer_ = histBtnMaxLifeTime;
66+
}
67+
else
68+
{
69+
if ( currentHistoryBtnTimer_ > 0 )
70+
currentHistoryBtnTimer_ += ( histBtnMaxLifeTime - showHistoryBtnMaxTime_ ); // decrease current timer
71+
}
72+
showHistoryBtnMaxTime_ = histBtnMaxLifeTime;
73+
requestClosestRedraw_();
74+
}
75+
5576
void RibbonNotifier::drawHistoryButton_( float scaling, const Box2i& limitFramebuffer )
5677
{
5778
using namespace StyleConsts::Notification;
5879
if ( notificationsHistory_.empty() )
5980
return;
6081

82+
if ( showHistoryBtnMaxTime_ > 0 )
83+
{
84+
if ( currentHistoryBtnTimer_ >= 0 && !historyMode_ )
85+
currentHistoryBtnTimer_ -= ImGui::GetIO().DeltaTime;
86+
if ( currentHistoryBtnTimer_ < 0 )
87+
return;
88+
}
89+
6190
const auto windowSzie = ImVec2( 36, cHistoryButtonSizeY ) * scaling;
6291
Vector2f windowPos = Vector2f( float( limitFramebuffer.min.x ), float( getViewerInstance().framebufferSize.y - limitFramebuffer.min.y ) - windowSzie.y );
6392
if ( cornerPosition == RibbonNotificationCorner::LowerRight )
@@ -113,6 +142,12 @@ void RibbonNotifier::drawHistoryButton_( float scaling, const Box2i& limitFrameb
113142
notifications_.clear();
114143
scrollDownNeeded_ = true;
115144
}
145+
else
146+
{
147+
currentHistoryBtnTimer_ = showHistoryBtnMaxTime_;
148+
if ( currentHistoryBtnTimer_ > 0 )
149+
requestClosestRedraw_();
150+
}
116151
}
117152

118153
auto drawList = window->DrawList;
@@ -187,6 +222,9 @@ void RibbonNotifier::drawHistory_( float scaling, const Box2i& limitFramebuffer
187222
if ( lostFoucsClickCheck() )
188223
{
189224
historyMode_ = false;
225+
currentHistoryBtnTimer_ = showHistoryBtnMaxTime_;
226+
if ( currentHistoryBtnTimer_ > 0 )
227+
requestClosestRedraw_();
190228
}
191229

192230
ImGui::End();
@@ -499,6 +537,13 @@ void RibbonNotifier::requestClosestRedraw_()
499537
if ( neededTime < minTimeReq )
500538
minTimeReq = neededTime;
501539
}
540+
541+
if ( showHistoryBtnMaxTime_ > 0 && currentHistoryBtnTimer_ > 0 )
542+
{
543+
if ( currentHistoryBtnTimer_ < minTimeReq )
544+
minTimeReq = currentHistoryBtnTimer_;
545+
}
546+
502547
if ( minTimeReq == FLT_MAX )
503548
return;
504549
requestRedraw_ = true;

source/MRViewer/MRRibbonNotification.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,15 @@ class MRVIEWER_CLASS RibbonNotifier
6565
public:
6666
// adds new notification for drawing
6767
MRVIEWER_API void pushNotification( const RibbonNotification& notification );
68+
6869
// main draw function. draw actual notification or history, and history button
6970
// limitFramebuffer - available framebuffer space (usually same as `Viewer::getViewportsBounds()`)
7071
MRVIEWER_API void draw( float scaling, const Box2i& limitFramebuffer );
7172

73+
// set maximum time while history button will be present on screen
74+
// negative value means that history button will never be hidden
75+
MRVIEWER_API void setHitoryButtonMaxLifeTime( float histBtnMaxLifeTime );
76+
7277
// this value is used as notification `lifeTimeSec` if negative values passed
7378
float defaultNotificationLifeTimeSeconds = 5.0f;
7479

@@ -89,6 +94,8 @@ class MRVIEWER_CLASS RibbonNotifier
8994
bool requestRedraw_ = false;
9095
bool historyMode_ = false;
9196

97+
float showHistoryBtnMaxTime_{ -1.0f }; // negative value here means that there is no need to hide history button
98+
float currentHistoryBtnTimer_{ -1.0f }; // update to validly hide the button
9299
#ifndef __EMSCRIPTEN__
93100
Time requestedTime_{ Time::max() };
94101
AsyncRequest asyncRequest_;

0 commit comments

Comments
 (0)