MeshLib
 
Loading...
Searching...
No Matches
MRRibbonNotification.h
Go to the documentation of this file.
1#pragma once
2#include "MRViewerFwd.h"
4#include "MRAsyncTimer.h"
5#include <functional>
6#include <chrono>
7
8namespace MR
9{
11{
12 // Callback for notification
13 // if it is not null, a button will be drawn, and callback will be invoked on button click
14 using OnButtonClick = std::function<void()>;
16
17 // Name of button that will be drawn if callback is enabled
18 std::string buttonName = "OK";
19 // Header of notification
20 std::string header;
21 // Text of notification
22 std::string text;
23 // Type of notification
25 // Time that notification stays visible
26 float lifeTimeSec = 10.0f;
27 // if notifications are equal to last one added, it just increment counter
28 // note that if there is present `onButtonClick` this function always returns false
29 bool operator==( const RibbonNotification& other ) const;
30};
31
32// class to hold and operate with notifications
34{
35public:
36 // adds new notification for drawing
37 void pushNotification( const RibbonNotification& notification );
38 // draws all present notifications
39 void drawNotifications( float scaling );
40private:
41 struct NotificationWithTimer
42 {
43 RibbonNotification notification;
44 float timer{ 0.0f };
45 int sameCounter = 1;
46 };
47 std::vector<NotificationWithTimer> notifications_;
48 void filterInvalid_( int numInvalid = -1 );
49#ifndef __EMSCRIPTEN__
50 Time requestedTime_{ Time::max() };
51 AsyncRequest asyncRequest_;
52#endif
53 void requestClosestRedraw_();
54};
55
56}
Definition MRRibbonNotification.h:34
void drawNotifications(float scaling)
void pushNotification(const RibbonNotification &notification)
Definition MRCameraOrientationPlugin.h:7
std::chrono::time_point< std::chrono::system_clock > Time
Definition MRAsyncTimer.h:17
NotificationType
Definition MRNotificationType.h:7
Definition MRRibbonNotification.h:11
std::string buttonName
Definition MRRibbonNotification.h:18
std::function< void()> OnButtonClick
Definition MRRibbonNotification.h:14
OnButtonClick onButtonClick
Definition MRRibbonNotification.h:15
std::string text
Definition MRRibbonNotification.h:22
NotificationType type
Definition MRRibbonNotification.h:24
float lifeTimeSec
Definition MRRibbonNotification.h:26
bool operator==(const RibbonNotification &other) const
std::string header
Definition MRRibbonNotification.h:20