Skip to content

Commit

Permalink
Add timer for last operation time label (#2503)
Browse files Browse the repository at this point in the history
  • Loading branch information
Grantim committed Apr 2, 2024
1 parent 4c9e6ae commit b551f49
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
21 changes: 18 additions & 3 deletions source/MRViewer/MRRibbonMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -382,9 +382,6 @@ void RibbonMenu::drawCollapseButton_()
ImGuiHoveredFlags_AllowWhenBlockedByActiveItem );
if ( hovered && openedTimer_ <= openedMaxSecs_ )
{
#ifndef __EMSCRIPTEN__
asyncRequest_.reset();
#endif
openedTimer_ = openedMaxSecs_;
collapseState_ = CollapseState::Opened;
}
Expand Down Expand Up @@ -2198,15 +2195,33 @@ void RibbonMenu::drawLastOperationTimeWindow_()
{
auto bgDrawList = ImGui::GetBackgroundDrawList();
if ( !bgDrawList || ProgressBar::isOrdered() )
{
openedLastOperationTimeTimer_ = 10.0f; // 10 seconds should be enough
return;
}

if ( openedLastOperationTimeTimer_ < 0.0f )
return;

float lastTimeSec = ProgressBar::getLastOperationTime();
if ( lastTimeSec < 0.0f )
return;

if ( lastTimeSec < 1e-3f )
lastTimeSec = 0.0f;

openedLastOperationTimeTimer_ -= ImGui::GetIO().DeltaTime;
#ifdef __EMSCRIPTEN__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdollar-in-identifier-extension"
EM_ASM( postEmptyEvent( $0, 2 ), int( openedLastOperationTimeTimer_ * 1000 ) );
#pragma clang diagnostic pop
#else
asyncRequest_.requestIfNotSet(
std::chrono::system_clock::now() + std::chrono::milliseconds( std::llround( openedLastOperationTimeTimer_ * 1000 ) ),
[] () { CommandLoop::appendCommand( [] () { getViewerInstance().incrementForceRedrawFrames(); } ); } );
#endif

const auto& title = ProgressBar::getLastOperationTitle();
auto timeText = fmt::format( "{:.1f} sec", lastTimeSec );

Expand Down
1 change: 1 addition & 0 deletions source/MRViewer/MRRibbonMenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ class MRVIEWER_CLASS RibbonMenu : public ImGuiMenu
// seconds to stay opened if not pinned
float openedMaxSecs_{ 2.0f };
float openedTimer_{ openedMaxSecs_ };
float openedLastOperationTimeTimer_{ openedMaxSecs_ };

int activeTabIndex_{ 0 };
RibbonFontManager fontManager_;
Expand Down

0 comments on commit b551f49

Please sign in to comment.