MeshLib C++ Docs
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 "MRMesh/MRBox.h"
7#include <functional>
8#include <chrono>
9
10namespace MR
11{
14
15
17{
18 enum Tag : unsigned
19 {
20 None = 0b0000,
21 Report = 0b0001,
24 Important = 0b1000,
27 };
28};
30
31using NotificationTagMask = unsigned;
32
39
41{
44 using OnButtonClick = std::function<void()>;
46
48 std::string buttonName = "OK";
50 std::string header;
52 std::string text;
57 float lifeTimeSec = -1.0f;
62 bool operator==( const RibbonNotification& other ) const;
63};
64
66class MRVIEWER_CLASS RibbonNotifier
67{
68public:
70 MRVIEWER_API void pushNotification( const RibbonNotification& notification );
71
74 MRVIEWER_API void draw( const Box2i& limitFramebuffer );
75
78 MRVIEWER_API void setHitoryButtonMaxLifeTime( float histBtnMaxLifeTime );
79
82
85
88private:
89 struct NotificationWithTimer
90 {
92 float timer{ 0.0f };
93 int sameCounter = 1;
94 };
95 std::vector<NotificationWithTimer> notifications_;
96 std::vector<NotificationWithTimer> notificationsHistory_;
97 bool requestRedraw_ = false;
98 bool historyMode_ = false;
99
100 float showHistoryBtnMaxTime_{ -1.0f };
101 float currentHistoryBtnTimer_{ -1.0f };
102#ifndef __EMSCRIPTEN__
103 Time requestedTime_{ Time::max() };
104 AsyncRequest asyncRequest_;
105#endif
106
108 void drawHistoryButton_( const Box2i& limitFramebuffer );
110 void drawHistory_( const Box2i& limitFramebuffer );
112 void drawFloating_( const Box2i& limitFramebuffer );
113
115 bool scrollDownNeeded_ = false;
116 float prevHistoryScrollMax_ = 0.0f;
117 struct DrawNotificationSettings
118 {
119 int index{ 0 };
120 float width{ 0.0f };
121 bool historyMode{ false };
122 Vector2f* currentPos{ nullptr };
123 };
126 bool drawNotification_( const DrawNotificationSettings& settings );
127 void addNotification_( std::vector<NotificationWithTimer>& store, const RibbonNotification& notification );
128 void filterInvalid_( int numInvalid = -1 );
129 void requestClosestRedraw_();
130};
131
132}
#define MR_MAKE_FLAG_OPERATORS(T)
Generates operators for a enum (at namespace scope).
Definition MRFlagOperators.h:6
class to hold and operate with notifications
Definition MRRibbonNotification.h:67
std::string buttonName
Name of button that will be drawn if callback is enabled.
Definition MRRibbonNotification.h:48
float timer
Definition MRRibbonNotification.h:92
NotificationTagMask tags
it ANDs with RibbonNotifier allowed tags to see if notification should be displayed
Definition MRRibbonNotification.h:59
std::function< void()> OnButtonClick
Definition MRRibbonNotification.h:44
void draw(const Box2i &limitFramebuffer)
float width
Definition MRRibbonNotification.h:120
NotificationType
Definition MRNotificationType.h:10
OnButtonClick onButtonClick
Definition MRRibbonNotification.h:45
std::string text
Text of notification.
Definition MRRibbonNotification.h:52
NotificationTagMask allowedTagMask
this mask is used to control allowed notifications by filtering with tags
Definition MRRibbonNotification.h:84
void setHitoryButtonMaxLifeTime(float histBtnMaxLifeTime)
RibbonNotificationCorner cornerPosition
position of notifications on screen
Definition MRRibbonNotification.h:87
bool historyMode
Definition MRRibbonNotification.h:121
unsigned NotificationTagMask
Definition MRRibbonNotification.h:31
Vector2f * currentPos
Definition MRRibbonNotification.h:122
NotificationType type
Type of notification.
Definition MRRibbonNotification.h:54
float lifeTimeSec
Definition MRRibbonNotification.h:57
bool operator==(const RibbonNotification &other) const
void pushNotification(const RibbonNotification &notification)
adds new notification for drawing
RibbonNotification notification
Definition MRRibbonNotification.h:91
float defaultNotificationLifeTimeSeconds
this value is used as notification lifeTimeSec if negative values passed
Definition MRRibbonNotification.h:81
RibbonNotificationCorner
corner where notifications will appear
Definition MRRibbonNotification.h:35
std::string header
Header of notification.
Definition MRRibbonNotification.h:50
int sameCounter
Definition MRRibbonNotification.h:93
Tag
Definition MRRibbonNotification.h:19
int index
Definition MRRibbonNotification.h:119
@ other
Angle, normally float. Measure in radians.
Definition MRFeatureObject.h:27
@ Info
Definition MRNotificationType.h:13
@ LowerRight
Definition MRRibbonNotification.h:37
@ LowerLeft
Definition MRRibbonNotification.h:36
@ ImplicitChanges
Definition MRRibbonNotification.h:23
@ Report
Definition MRRibbonNotification.h:21
@ Recommendation
Definition MRRibbonNotification.h:22
@ All
Definition MRRibbonNotification.h:26
@ Important
Definition MRRibbonNotification.h:24
@ Default
Definition MRRibbonNotification.h:25
@ None
Definition MRRibbonNotification.h:20
only for bindings generation
Definition MRCameraOrientationPlugin.h:8
Definition MRRibbonNotification.h:17
Definition MRRibbonNotification.h:41