TachyonUI 0.1.0
High-performance UI for building tools.
Loading...
Searching...
No Matches
gui_numeric_field_config.h
Go to the documentation of this file.
1#pragma once
2
3#include <algorithm>
4#include <cfloat>
5#include <cmath>
6#include <stdint.h>
7#include <type_traits>
8
9namespace tachyon
10{
13
18 template<typename T>
20
22 template<>
23 struct NumericFieldConfig<double>
24 {
25 double stepPerPixel = 0.01;
26 double minVal = -DBL_MAX;
27 double maxVal = DBL_MAX;
28
31 double Calculate(int32_t offset, double speedScale, double startValue) const
32 {
33 double result = startValue + offset * speedScale * stepPerPixel;
34 if (std::isnan(result)) return 0.0;
35 return std::clamp(result, minVal, maxVal);
36 }
37 };
38
40 template<>
41 struct NumericFieldConfig<float>
42 {
43 double stepPerPixel = 0.01;
44 float minVal = -FLT_MAX;
45 float maxVal = FLT_MAX;
46
49 float Calculate(int32_t offset, double speedScale, float startValue) const
50 {
51 double result = double(startValue) + offset * speedScale * stepPerPixel;
52 if (std::isnan(result)) return 0.0f;
53 return float(std::clamp(result, double(minVal), double(maxVal)));
54 }
55 };
56
58 template<>
59 struct NumericFieldConfig<uint64_t>
60 {
61 double stepPerPixel = 1.00;
62 uint64_t minVal = 0;
63 uint64_t maxVal = UINT64_MAX;
66 uint64_t Calculate(int32_t offset, double speedScale, uint64_t startValue) const
67 {
68 double result = double(startValue) + offset * speedScale * stepPerPixel;
69 return uint64_t(std::clamp(result, double(minVal), double(maxVal)));
70 }
71 };
72
74 template<>
75 struct NumericFieldConfig<uint32_t>
76 {
77 double stepPerPixel = 1.00;
78 uint32_t minVal = 0;
79 uint32_t maxVal = UINT32_MAX;
82 uint32_t Calculate(int32_t offset, double speedScale, uint32_t startValue) const
83 {
84 double result = double(startValue) + offset * speedScale * stepPerPixel;
85 return uint32_t(std::clamp(result, double(minVal), double(maxVal)));
86 }
87 };
88
90 template<>
91 struct NumericFieldConfig<uint16_t>
92 {
93 double stepPerPixel = 1.00;
94 uint16_t minVal = 0;
95 uint16_t maxVal = UINT16_MAX;
98 uint16_t Calculate(int32_t offset, double speedScale, uint16_t startValue) const
99 {
100 double result = double(startValue) + offset * speedScale * stepPerPixel;
101 return uint16_t(std::clamp(result, double(minVal), double(maxVal)));
102 }
103 };
104
106 template<>
107 struct NumericFieldConfig<uint8_t>
108 {
109 double stepPerPixel = 1.00;
110 uint8_t minVal = 0;
111 uint8_t maxVal = UINT8_MAX;
114 uint8_t Calculate(int32_t offset, double speedScale, uint8_t startValue) const
115 {
116 double result = double(startValue) + offset * speedScale * stepPerPixel;
117 return uint8_t(std::clamp(result, double(minVal), double(maxVal)));
118 }
119 };
120
122 template<>
123 struct NumericFieldConfig<int64_t>
124 {
125 double stepPerPixel = 1.00;
126 int64_t minVal = INT64_MIN;
127 int64_t maxVal = INT64_MAX;
130 int64_t Calculate(int32_t offset, double speedScale, int64_t startValue) const
131 {
132 double result = double(startValue) + offset * speedScale * stepPerPixel;
133 return int64_t(std::clamp(result, double(minVal), double(maxVal)));
134 }
135 };
136
138 template<>
139 struct NumericFieldConfig<int32_t>
140 {
141 double stepPerPixel = 1.00;
142 int32_t minVal = INT32_MIN;
143 int32_t maxVal = INT32_MAX;
146 int32_t Calculate(int32_t offset, double speedScale, int32_t startValue) const
147 {
148 double result = double(startValue) + offset * speedScale * stepPerPixel;
149 return int32_t(std::clamp(result, double(minVal), double(maxVal)));
150 }
151 };
152
154 template<>
155 struct NumericFieldConfig<int16_t>
156 {
157 double stepPerPixel = 1.00;
158 int16_t minVal = INT16_MIN;
159 int16_t maxVal = INT16_MAX;
162 int16_t Calculate(int32_t offset, double speedScale, int16_t startValue) const
163 {
164 double result = double(startValue) + offset * speedScale * stepPerPixel;
165 return int16_t(std::clamp(result, double(minVal), double(maxVal)));
166 }
167 };
168
170 template<>
171 struct NumericFieldConfig<int8_t>
172 {
173 double stepPerPixel = 1.00;
174 int8_t minVal = INT8_MIN;
175 int8_t maxVal = INT8_MAX;
178 int8_t Calculate(int32_t offset, double speedScale, int8_t startValue) const
179 {
180 double result = double(startValue) + offset * speedScale * stepPerPixel;
181 return int8_t(std::clamp(result, double(minVal), double(maxVal)));
182 }
183 };
184
185}
Definition gui_logging.h:24
double Calculate(int32_t offset, double speedScale, double startValue) const
The value after dragging offset pixels from startValue; speedScale is the modifier factor (Ctrl 0....
Definition gui_numeric_field_config.h:31
double minVal
lowest allowed value
Definition gui_numeric_field_config.h:26
double maxVal
highest allowed value
Definition gui_numeric_field_config.h:27
double stepPerPixel
value change per pixel dragged
Definition gui_numeric_field_config.h:25
float Calculate(int32_t offset, double speedScale, float startValue) const
The value after dragging offset pixels from startValue; speedScale is the modifier factor (Ctrl 0....
Definition gui_numeric_field_config.h:49
double stepPerPixel
value change per pixel dragged
Definition gui_numeric_field_config.h:43
float minVal
lowest allowed value
Definition gui_numeric_field_config.h:44
float maxVal
highest allowed value
Definition gui_numeric_field_config.h:45
double stepPerPixel
value change per pixel dragged
Definition gui_numeric_field_config.h:157
int16_t Calculate(int32_t offset, double speedScale, int16_t startValue) const
The value after dragging offset pixels from startValue; speedScale is the modifier factor (Ctrl 0....
Definition gui_numeric_field_config.h:162
int16_t minVal
lowest allowed value
Definition gui_numeric_field_config.h:158
int16_t maxVal
highest allowed value
Definition gui_numeric_field_config.h:159
int32_t minVal
lowest allowed value
Definition gui_numeric_field_config.h:142
int32_t maxVal
highest allowed value
Definition gui_numeric_field_config.h:143
int32_t Calculate(int32_t offset, double speedScale, int32_t startValue) const
The value after dragging offset pixels from startValue; speedScale is the modifier factor (Ctrl 0....
Definition gui_numeric_field_config.h:146
double stepPerPixel
value change per pixel dragged
Definition gui_numeric_field_config.h:141
int64_t minVal
lowest allowed value
Definition gui_numeric_field_config.h:126
double stepPerPixel
value change per pixel dragged
Definition gui_numeric_field_config.h:125
int64_t maxVal
highest allowed value
Definition gui_numeric_field_config.h:127
int64_t Calculate(int32_t offset, double speedScale, int64_t startValue) const
The value after dragging offset pixels from startValue; speedScale is the modifier factor (Ctrl 0....
Definition gui_numeric_field_config.h:130
double stepPerPixel
value change per pixel dragged
Definition gui_numeric_field_config.h:173
int8_t maxVal
highest allowed value
Definition gui_numeric_field_config.h:175
int8_t Calculate(int32_t offset, double speedScale, int8_t startValue) const
The value after dragging offset pixels from startValue; speedScale is the modifier factor (Ctrl 0....
Definition gui_numeric_field_config.h:178
int8_t minVal
lowest allowed value
Definition gui_numeric_field_config.h:174
uint16_t minVal
lowest allowed value
Definition gui_numeric_field_config.h:94
uint16_t maxVal
highest allowed value
Definition gui_numeric_field_config.h:95
uint16_t Calculate(int32_t offset, double speedScale, uint16_t startValue) const
The value after dragging offset pixels from startValue; speedScale is the modifier factor (Ctrl 0....
Definition gui_numeric_field_config.h:98
double stepPerPixel
value change per pixel dragged
Definition gui_numeric_field_config.h:93
uint32_t maxVal
highest allowed value
Definition gui_numeric_field_config.h:79
double stepPerPixel
value change per pixel dragged
Definition gui_numeric_field_config.h:77
uint32_t Calculate(int32_t offset, double speedScale, uint32_t startValue) const
The value after dragging offset pixels from startValue; speedScale is the modifier factor (Ctrl 0....
Definition gui_numeric_field_config.h:82
uint32_t minVal
lowest allowed value
Definition gui_numeric_field_config.h:78
uint64_t maxVal
highest allowed value
Definition gui_numeric_field_config.h:63
uint64_t Calculate(int32_t offset, double speedScale, uint64_t startValue) const
The value after dragging offset pixels from startValue; speedScale is the modifier factor (Ctrl 0....
Definition gui_numeric_field_config.h:66
double stepPerPixel
value change per pixel dragged
Definition gui_numeric_field_config.h:61
uint64_t minVal
lowest allowed value
Definition gui_numeric_field_config.h:62
uint8_t minVal
lowest allowed value
Definition gui_numeric_field_config.h:110
uint8_t Calculate(int32_t offset, double speedScale, uint8_t startValue) const
The value after dragging offset pixels from startValue; speedScale is the modifier factor (Ctrl 0....
Definition gui_numeric_field_config.h:114
double stepPerPixel
value change per pixel dragged
Definition gui_numeric_field_config.h:109
uint8_t maxVal
highest allowed value
Definition gui_numeric_field_config.h:111
Drag speed and range of a numeric Field, specialized per value type.
Definition gui_numeric_field_config.h:19