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

Class JsonUiSliderInternal

src/platforms/shared/ui/json/slider.cpp.hpp:16–89  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

14
15// Definition of the internal class that was previously in slider_internal.h
16class JsonUiSliderInternal : public JsonUiInternal {
17private:
18 float mMin;
19 float mMax;
20 float mValue;
21 float mStep;
22 bool mStepExplicitlySet;
23
24public:
25 // Constructor: Initializes the base JsonUiInternal with name, and sets initial values.
26 JsonUiSliderInternal(const fl::string& name, float value, float min, float max, float step = -1)
27 FL_NOEXCEPT : JsonUiInternal(name), mMin(min), mMax(max), mValue(value), mStep(step), mStepExplicitlySet(false) {
28 if (fl::almost_equal(mStep, -1.f) && mMax > mMin) {
29 mStep = (mMax - mMin) / 255.0f;
30 } else if (!fl::almost_equal(mStep, -1.f)) {
31 mStepExplicitlySet = true;
32 }
33 }
34
35 // Override toJson to serialize the slider's data directly.
36 void toJson(fl::json& json) const FL_NOEXCEPT override {
37 json.set("name", name());
38 json.set("type", "slider");
39 json.set("group", groupName());
40 json.set("id", id());
41 json.set("value", mValue);
42 json.set("min", mMin);
43 json.set("max", mMax);
44 // Only output step if it was explicitly set by the user
45 if (mStepExplicitlySet) {
46 json.set("step", mStep);
47 }
48 }
49
50 // Override updateInternal to handle updates from JSON.
51 void updateInternal(const fl::json& json) FL_NOEXCEPT override {
52 float value = json | 0.0f;
53 if (value < mMin) {
54 value = mMin;
55 } else if (value > mMax) {
56 value = mMax;
57 }
58 mValue = value;
59 }
60
61 // Accessors for the slider values.
62 float value() const FL_NOEXCEPT { return mValue; }
63 float getMin() const FL_NOEXCEPT { return mMin; }
64 float getMax() const FL_NOEXCEPT { return mMax; }
65 float step() const FL_NOEXCEPT { return mStep; }
66
67 void setValue(float value) FL_NOEXCEPT {
68 if (value < mMin) {
69 value = mMin;
70 } else if (value > mMax) {
71 value = mMax;
72 }
73 mValue = value;

Callers

nothing calls this directly

Calls 2

idClass · 0.85
setMethod · 0.45

Tested by

no test coverage detected