MCPcopy Create free account
hub / github.com/FastLED/FastLED / JsonUiNumberFieldInternal

Class JsonUiNumberFieldInternal

src/platforms/shared/ui/json/number_field.cpp.hpp:13–62  ·  view source on GitHub ↗

Definition of the internal class that was previously in number_field_internal.h

Source from the content-addressed store, hash-verified

11
12// Definition of the internal class that was previously in number_field_internal.h
13class JsonUiNumberFieldInternal : public JsonUiInternal {
14private:
15 float mValue;
16 float mMin;
17 float mMax;
18
19public:
20 // Constructor: Initializes the base JsonUiInternal with name, and sets initial values.
21 JsonUiNumberFieldInternal(const fl::string& name, float value, float min, float max)
22 FL_NOEXCEPT : JsonUiInternal(name), mValue(value), mMin(min), mMax(max) {}
23
24 // Override toJson to serialize the number field's data directly.
25 void toJson(fl::json& json) const FL_NOEXCEPT override {
26 json.set("name", name());
27 json.set("type", "number");
28 json.set("group", groupName());
29 json.set("id", id());
30 json.set("value", mValue);
31 json.set("min", mMin);
32 json.set("max", mMax);
33 }
34
35 // Override updateInternal to handle updates from JSON.
36 void updateInternal(const fl::json& json) FL_NOEXCEPT override {
37 float value = json | 0.0f;
38 if (value < mMin) {
39 value = mMin;
40 } else if (value > mMax) {
41 value = mMax;
42 }
43 mValue = value;
44 }
45
46 // Accessors for the number field values.
47 float value() const FL_NOEXCEPT { return mValue; }
48 float getMin() const FL_NOEXCEPT { return mMin; }
49 float getMax() const FL_NOEXCEPT { return mMax; }
50
51 void setValue(float value) FL_NOEXCEPT {
52 if (value < mMin) {
53 value = mMin;
54 } else if (value > mMax) {
55 value = mMax;
56 }
57 mValue = value;
58 }
59
60 void setMin(float min) FL_NOEXCEPT { mMin = min; }
61 void setMax(float max) FL_NOEXCEPT { mMax = max; }
62};
63
64JsonNumberFieldImpl::JsonNumberFieldImpl(const fl::string &name, float value,
65 float min, float max) FL_NOEXCEPT {

Callers

nothing calls this directly

Calls 2

idClass · 0.85
setMethod · 0.45

Tested by

no test coverage detected