Nix (Dev) 3.5.10
dev - 3.5.10 - 1af9301
Loading...
Searching...
No Matches
utils.hpp
Go to the documentation of this file.
1#ifndef IV_SRC_UI_UTILS_HPP_
2#define IV_SRC_UI_UTILS_HPP_
3
4#include "alarms/enums.hpp"
6
7#include <algorithm>
8#include <cstdint>
9
11{
12
14{
15 switch (justify)
16 {
17 case 1:
19
20 case 2:
22
23 case 3:
25
26 case 4:
28
29 case 0:
30 case 5:
31 default:
33
34 case 6:
36
37 case 7:
39
40 case 8:
42
43 case 9:
45 }
46}
47
49getAlarmStateRepresentation(std::optional<iv::alarms::eAlarmState> alarmState,
50 std::optional<iv::alarms::eAlarmPriority> alarmPriority)
51{
52 iv::ui::AlarmStateRepresentation alarmStateRepresentation {.color = std::nullopt,
53 .isBlinking = false,
54 .blinkingColor = std::nullopt};
55
56 if (not alarmState.has_value() or not alarmPriority.has_value())
57 {
58 return alarmStateRepresentation;
59 }
60
61 switch (alarmState.value())
62 {
64 alarmStateRepresentation.color = iv::alarms::getAlarmColor(
65 alarmState.value(), iv::alarms::eAlarmType::Normal, alarmPriority.value());
66 break;
67
70 alarmStateRepresentation.isBlinking = true;
71 alarmStateRepresentation.blinkingColor = iv::alarms::getAlarmColor(
72 alarmState.value(), iv::alarms::eAlarmType::Normal, alarmPriority.value());
73 break;
74
77 break;
78 }
79
80 return alarmStateRepresentation;
81}
82
84{
85public:
86 PaginationIndex(uint64_t totalElements, uint64_t elementsPerPage, bool allPagesMustBeFilled = false)
87 : m_currentIndex(0), m_totalElements(totalElements), m_elementsPerPage(elementsPerPage),
88 m_allPagesMustBeFilled(allPagesMustBeFilled)
89 {
90 }
91
92 [[nodiscard]] uint64_t getCurrentIndex() const
93 {
94 return m_currentIndex;
95 }
96 [[nodiscard]] uint64_t getElementsPerPage() const
97 {
98 return m_elementsPerPage;
99 }
100 [[nodiscard]] uint64_t getTotalElements() const
101 {
102 return m_totalElements;
103 }
104
105 void setTotalElements(uint64_t totalElements)
106 {
107 this->m_totalElements = totalElements;
108 }
109
110 void setElementsPerPage(uint64_t elementsPerPage)
111 {
112 this->m_elementsPerPage = elementsPerPage;
113 }
114
115 void setAllPagesMustBeFilled(bool allPagesMustBeFilled)
116 {
117 this->m_allPagesMustBeFilled = allPagesMustBeFilled;
118 }
119
121 {
123 {
125
127 {
129 }
130 }
131 }
132
134 {
135 if (m_currentIndex > 0)
136 {
138 }
139 }
140
141 void nextPage()
142 {
143 uint64_t nextPageIndex = m_currentIndex + m_elementsPerPage;
145 {
146 nextPageIndex = std::min(nextPageIndex, m_totalElements - m_elementsPerPage);
147 }
148
149 if (nextPageIndex < m_totalElements)
150 {
151 m_currentIndex = nextPageIndex;
152 }
153 else
154 {
156 }
157 }
158
160 {
162 {
164 }
165 else
166 {
167 m_currentIndex = 0;
168 }
169 }
170
171 void goToPage(uint64_t pageNumber)
172 {
173 uint64_t pageIndex = pageNumber * m_elementsPerPage;
174
176 {
177 pageIndex = std::min(pageIndex, m_totalElements - m_elementsPerPage);
178 }
179
180 if (pageIndex < m_totalElements)
181 {
182 m_currentIndex = pageIndex;
183 }
184 else
185 {
187 }
188 }
189
190 [[nodiscard]] uint64_t getCurrentPage() const
191 {
193 }
194
195 [[nodiscard]] uint64_t getTotalPages() const
196 {
198 }
199
200 void reset()
201 {
202 m_currentIndex = 0;
203 }
204
205private:
210};
211
212}// namespace iv::ui::utils
213
214#endif//IV_SRC_UI_UTILS_HPP_
Definition utils.hpp:84
void previousPage()
Definition utils.hpp:159
uint64_t getTotalElements() const
Definition utils.hpp:100
void setTotalElements(uint64_t totalElements)
Definition utils.hpp:105
uint64_t m_currentIndex
Definition utils.hpp:206
uint64_t m_elementsPerPage
Definition utils.hpp:208
uint64_t m_totalElements
Definition utils.hpp:207
uint64_t getCurrentPage() const
Definition utils.hpp:190
PaginationIndex(uint64_t totalElements, uint64_t elementsPerPage, bool allPagesMustBeFilled=false)
Definition utils.hpp:86
void decrementIndex()
Definition utils.hpp:133
void setAllPagesMustBeFilled(bool allPagesMustBeFilled)
Definition utils.hpp:115
void setElementsPerPage(uint64_t elementsPerPage)
Definition utils.hpp:110
void incrementIndex()
Definition utils.hpp:120
void reset()
Definition utils.hpp:200
bool m_allPagesMustBeFilled
Definition utils.hpp:209
uint64_t getElementsPerPage() const
Definition utils.hpp:96
uint64_t getTotalPages() const
Definition utils.hpp:195
void goToPage(uint64_t pageNumber)
Definition utils.hpp:171
void nextPage()
Definition utils.hpp:141
uint64_t getCurrentIndex() const
Definition utils.hpp:92
iv::types::color getAlarmColor(iv::alarms::eAlarmState state, iv::alarms::eAlarmType type, iv::alarms::eAlarmPriority priority)
Definition enums.hpp:125
Definition utils.hpp:11
iv::ui::eAnchorPoint justifyToAnchorPoint(uint8_t justify)
Definition utils.hpp:13
iv::ui::AlarmStateRepresentation getAlarmStateRepresentation(std::optional< iv::alarms::eAlarmState > alarmState, std::optional< iv::alarms::eAlarmPriority > alarmPriority)
Definition utils.hpp:49
eAnchorPoint
Definition enums.hpp:8
Definition representationsStructs.hpp:17