2
0

UITextButton.h 1.6 KB

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