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