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
81 float defaultNotificationLifeTimeSeconds = 5.0f;
82
84 NotificationTagMask allowedTagMask = NotificationTags::Default;
85
87 RibbonNotificationCorner cornerPosition = RibbonNotificationCorner::LowerLeft;
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
auto width(const Box< V > &box)
returns size along x axis
Definition MRBox.h:354
MRVIEWER_API void setHitoryButtonMaxLifeTime(float histBtnMaxLifeTime)
std::string buttonName
Name of button that will be drawn if callback is enabled.
Definition MRRibbonNotification.h:48
MRVIEWER_API void pushNotification(const RibbonNotification &notification)
adds new notification for drawing
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
NotificationType
Definition MRNotificationType.h:10
OnButtonClick onButtonClick
Definition MRRibbonNotification.h:45
std::string text
Text of notification.
Definition MRRibbonNotification.h:52
unsigned NotificationTagMask
Definition MRRibbonNotification.h:31
NotificationType type
Type of notification.
Definition MRRibbonNotification.h:54
MRVIEWER_API void draw(const Box2i &limitFramebuffer)
float lifeTimeSec
Definition MRRibbonNotification.h:57
bool operator==(const RibbonNotification &other) const
RibbonNotification notification
Definition MRRibbonNotification.h:91
RibbonNotificationCorner
corner where notifications will appear
Definition MRRibbonNotification.h:35
std::string header
Header of notification.
Definition MRRibbonNotification.h:50
Tag
Definition MRRibbonNotification.h:19
@ other
Angle, normally float. Measure in radians.
@ 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