Definition of the internal class that was previously in checkbox_internal.h
| 9 | |
| 10 | // Definition of the internal class that was previously in checkbox_internal.h |
| 11 | class JsonUiCheckboxInternal : public JsonUiInternal { |
| 12 | private: |
| 13 | bool mValue; |
| 14 | |
| 15 | public: |
| 16 | // Constructor: Initializes the base JsonUiInternal with name, and sets initial value. |
| 17 | JsonUiCheckboxInternal(const fl::string& name, bool value = false) |
| 18 | FL_NOEXCEPT : JsonUiInternal(name), mValue(value) {} |
| 19 | |
| 20 | // Override toJson to serialize the checkbox's data directly. |
| 21 | void toJson(fl::json& json) const FL_NOEXCEPT override { |
| 22 | json.set("name", name()); |
| 23 | json.set("type", "checkbox"); |
| 24 | json.set("group", groupName()); |
| 25 | json.set("id", id()); |
| 26 | json.set("value", mValue); |
| 27 | } |
| 28 | |
| 29 | // Override updateInternal to handle updates from JSON. |
| 30 | void updateInternal(const fl::json& json) FL_NOEXCEPT override { |
| 31 | mValue = json | false; |
| 32 | } |
| 33 | |
| 34 | // Accessors for the checkbox value. |
| 35 | bool value() const FL_NOEXCEPT { return mValue; } |
| 36 | void setValue(bool value) FL_NOEXCEPT { mValue = value; } |
| 37 | }; |
| 38 | |
| 39 | JsonCheckboxImpl::JsonCheckboxImpl(const fl::string &name, bool value) FL_NOEXCEPT { |
| 40 | // Create an instance of the new internal class |