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"
6#include <functional>
7#include <chrono>
8
9namespace MR
10{
11
13{
14 enum Tag : unsigned
15 {
16 None = 0b0000,
17 Report = 0b0001,
20 Important = 0b1000,
23 };
24};
26
27using NotificationTagMask = unsigned;
28
30{
31 // Callback for notification
32 // if it is not null, a button will be drawn, and callback will be invoked on button click
33 using OnButtonClick = std::function<void()>;
35
36 // Name of button that will be drawn if callback is enabled
37 std::string buttonName = "OK";
38 // Header of notification
39 std::string header;
40 // Text of notification
41 std::string text;
42 // Type of notification
44 // Time that notification stays visible
45 // negative value means to use default one
46 float lifeTimeSec = -1.0f;
47 // it ANDs with RibbonNotifier allowed tags to see if notification should be displayed
49 // if notifications are equal to last one added, it just increment counter
50 // note that if there is present `onButtonClick` this function always returns false
51 bool operator==( const RibbonNotification& other ) const;
52};
53
54// class to hold and operate with notifications
55class MRVIEWER_CLASS RibbonNotifier
56{
57public:
58 // adds new notification for drawing
59 MRVIEWER_API void pushNotification( const RibbonNotification& notification );
60 // main draw function. draw actual notification or history, and history button
61 MRVIEWER_API void draw( float scaling, float scenePosX, float topPanelHeight );
62
63 // this value is used as notification `lifeTimeSec` if negative values passed
64 float defaultNotificationLifeTimeSeconds = 5.0f;
65
66 // this mask is used to control allowed notifications by filtering with tags
67 NotificationTagMask allowedTagMask = NotificationTags::Default;
68private:
69 struct NotificationWithTimer
70 {
71 RibbonNotification notification;
72 float timer{ 0.0f };
73 int sameCounter = 1;
74 };
75 std::vector<NotificationWithTimer> notifications_;
76 std::vector<NotificationWithTimer> notificationsHistory_;
77 bool requestRedraw_ = false;
78 bool historyMode_ = false;
79
80#ifndef __EMSCRIPTEN__
81 Time requestedTime_{ Time::max() };
82 AsyncRequest asyncRequest_;
83#endif
84
85 // draw button to show last notifications
86 void drawHistoryButton_( float scaling, float scenePosX );
87 // draw notification history
88 void drawHistory_( float scaling, float scenePosX, float topPanelHeight );
89 // draw floating notifications
90 void drawFloating_( float scaling, float scenePosX );
91
92 // set this true on open history and on new notification added
93 bool scrollDownNeeded_ = false;
94 float prevHistoryScrollMax_ = 0.0f;
95 struct DrawNotificationSettings
96 {
97 int index{ 0 };
98 float scalig{ 1.0f };
99 float width{ 0.0f };
100 bool historyMode{ false };
101 Vector2f* currentPos{ nullptr };
102 };
103 // draws one notification
104 // returns false if need to close
105 bool drawNotification_( const DrawNotificationSettings& settings );
106 void addNotification_( std::vector<NotificationWithTimer>& store, const RibbonNotification& notification );
107 void filterInvalid_( int numInvalid = -1 );
108 void requestClosestRedraw_();
109};
110
111}
#define MR_MAKE_FLAG_OPERATORS(T)
Definition MRFlagOperators.h:6
Definition MRRibbonNotification.h:56
MRVIEWER_API void draw(float scaling, float scenePosX, float topPanelHeight)
MRVIEWER_API void pushNotification(const RibbonNotification &notification)
auto width(const Box< V > &box)
returns size along x axis
Definition MRMesh/MRBox.h:247
Definition MRCameraOrientationPlugin.h:8
std::chrono::time_point< std::chrono::system_clock > Time
Definition MRAsyncTimer.h:17
NotificationType
Definition MRNotificationType.h:7
unsigned NotificationTagMask
Definition MRRibbonNotification.h:27
Definition MRRibbonNotification.h:13
Tag
Definition MRRibbonNotification.h:15
@ ImplicitChanges
Definition MRRibbonNotification.h:19
@ Report
Definition MRRibbonNotification.h:17
@ Recommendation
Definition MRRibbonNotification.h:18
@ All
Definition MRRibbonNotification.h:22
@ Important
Definition MRRibbonNotification.h:20
@ Default
Definition MRRibbonNotification.h:21
@ None
Definition MRRibbonNotification.h:16
Definition MRRibbonNotification.h:30
std::function< void()> OnButtonClick
Definition MRRibbonNotification.h:33
OnButtonClick onButtonClick
Definition MRRibbonNotification.h:34
std::string text
Definition MRRibbonNotification.h:41
bool operator==(const RibbonNotification &other) const
std::string header
Definition MRRibbonNotification.h:39