| 38 | #endif |
| 39 | |
| 40 | class UIButton : public UIElement { |
| 41 | public: |
| 42 | FL_NO_COPY(UIButton) |
| 43 | UIButton(const char *name) FL_NOEXCEPT; |
| 44 | ~UIButton() FL_NOEXCEPT; |
| 45 | bool isPressed() const FL_NOEXCEPT { |
| 46 | if (mImpl.isPressed()) { |
| 47 | return true; |
| 48 | } |
| 49 | if (mButtonInput) { |
| 50 | return mButtonInput->isPressed(); |
| 51 | } |
| 52 | return false; |
| 53 | } |
| 54 | bool clicked() const FL_NOEXCEPT { |
| 55 | if (mImpl.clicked()) { |
| 56 | return true; |
| 57 | } |
| 58 | if (mButtonInput) { |
| 59 | return mButtonInput->clicked(); |
| 60 | } |
| 61 | return false; |
| 62 | } |
| 63 | int clickedCount() const FL_NOEXCEPT; |
| 64 | operator bool() const FL_NOEXCEPT { return clicked(); } |
| 65 | bool value() const FL_NOEXCEPT { return clicked(); } |
| 66 | |
| 67 | void addRealButton(fl::shared_ptr<IButtonInput> button) FL_NOEXCEPT; |
| 68 | |
| 69 | void click() FL_NOEXCEPT { mImpl.click(); } |
| 70 | |
| 71 | // Override setGroup to also update the implementation |
| 72 | void setGroup(const fl::string& groupName) FL_NOEXCEPT override { |
| 73 | UIElement::setGroup(groupName); |
| 74 | // Update the implementation's group if it has the method (WASM platforms) |
| 75 | mImpl.setGroup(groupName); |
| 76 | } |
| 77 | |
| 78 | int onChanged(function<void(UIButton &)> callback) FL_NOEXCEPT { |
| 79 | int id = mCallbacks.add(callback); |
| 80 | mListener.addToEngineEventsOnce(); |
| 81 | return id; |
| 82 | } |
| 83 | |
| 84 | int onClicked(function<void()> callback) FL_NOEXCEPT { |
| 85 | int id = mCallbacks.add([callback](UIButton &btn) { |
| 86 | if (btn.clicked()) { |
| 87 | callback(); |
| 88 | } |
| 89 | }); |
| 90 | mListener.addToEngineEventsOnce(); |
| 91 | return id; |
| 92 | } |
| 93 | |
| 94 | int onPressed(function<void()> callback) FL_NOEXCEPT { |
| 95 | int id = mPressCallbacks.add(callback); |
| 96 | mListener.addToEngineEventsOnce(); |
| 97 | return id; |