2
0

UITextButton.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // SPDX-FileCopyrightText: 2021 Jorrit Rouwe
  2. // SPDX-License-Identifier: MIT
  3. #pragma once
  4. #include <UI/UIStaticText.h>
  5. /// Clickable text button
  6. class UITextButton : public UIStaticText
  7. {
  8. public:
  9. JPH_DECLARE_RTTI_VIRTUAL(UITextButton)
  10. using ClickAction = function<void()>;
  11. /// Properties
  12. void SetDownColor(ColorArg inColor) { mDownTextColor = inColor; }
  13. void SetHighlightColor(ColorArg inColor) { mHighlightTextColor = inColor; }
  14. void SetSelectedColor(ColorArg inColor) { mSelectedTextColor = inColor; }
  15. void SetRepeat(float inRepeatStartTime, float inRepeatTime) { mRepeatStartTime = inRepeatStartTime; mRepeatTime = inRepeatTime; }
  16. void SetClickAction(ClickAction inAction) { mClickAction = inAction; }
  17. /// Cloning / copying
  18. virtual void CopyTo(UIElement *ioElement) const override;
  19. /// Actions
  20. virtual bool MouseDown(int inX, int inY) override;
  21. virtual bool MouseUp(int inX, int inY) override;
  22. virtual bool MouseMove(int inX, int inY) override;
  23. virtual void MouseCancel() override;
  24. /// Update element
  25. virtual void Update(float inDeltaTime) override;
  26. /// Draw element
  27. virtual void Draw() const override;
  28. protected:
  29. /// Draw element custom
  30. void DrawCustom() const;
  31. /// Properties
  32. Color mDownTextColor { Color::sGrey };
  33. Color mHighlightTextColor { Color::sWhite };
  34. Color mSelectedTextColor { Color::sWhite };
  35. float mRepeatStartTime = -1.0f;
  36. float mRepeatTime = 0.5f;
  37. ClickAction mClickAction;
  38. /// State
  39. bool mPressed = false;
  40. bool mIsRepeating = false;
  41. float mRepeatTimeLeft = 0;
  42. };