BsGUIFloatField.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. #pragma once
  2. #include "BsEditorPrerequisites.h"
  3. #include "BsGUIFieldBase.h"
  4. namespace BansheeEngine
  5. {
  6. /**
  7. * @brief A composite GUI object representing an editor field. Editor fields are a combination
  8. * of a label and an input field. Label is optional. This specific implementation
  9. * displays a floating point input field.
  10. */
  11. class BS_ED_EXPORT GUIFloatField : public TGUIField<GUIFloatField>
  12. {
  13. public:
  14. /**
  15. * Returns type name of the GUI element used for finding GUI element styles.
  16. */
  17. static const String& getGUITypeName();
  18. /**
  19. * Style type name for the internal input box.
  20. */
  21. static const String& getInputStyleType();
  22. GUIFloatField(const PrivatelyConstruct& dummy, const GUIContent& labelContent, UINT32 labelWidth,
  23. const String& style, const GUIDimensions& dimensions, bool withLabel);
  24. /**
  25. * @brief Returns the value of the input field.
  26. */
  27. float getValue() const { return mValue; }
  28. /**
  29. * @brief Sets a new value in the input field.
  30. */
  31. void setValue(float value);
  32. /**
  33. * @brief Sets a minimum and maximum allow values in the input field.
  34. * Set to large negative/positive values if you don't require clamping.
  35. */
  36. void setRange(float min, float max);
  37. /**
  38. * @brief Checks is the input field currently active.
  39. */
  40. bool hasInputFocus() const { return mHasInputFocus; }
  41. /**
  42. * @copydoc GUIElement::setTint
  43. */
  44. void setTint(const Color& color) override;
  45. /**
  46. * @brief Sets a new value in the input field, and also allows you to choose should the field trigger an
  47. * onValueChanged event.
  48. */
  49. void _setValue(float value, bool triggerEvent);
  50. Event<void(float)> onValueChanged; /**< Triggers when the field value changes. */
  51. Event<void()> onConfirm; /**< Triggered when the user hits the Enter key with the input box in focus. */
  52. protected:
  53. virtual ~GUIFloatField();
  54. /**
  55. * @copydoc GUIElementContainer::_hasCustomCursor
  56. */
  57. bool _hasCustomCursor(const Vector2I position, CursorType& type) const override;
  58. /**
  59. * @copydoc GUIElementContainer::_mouseEvent
  60. */
  61. virtual bool _mouseEvent(const GUIMouseEvent& ev) override;
  62. /**
  63. * @copydoc GUIElementContainer::styleUpdated
  64. */
  65. void styleUpdated() override;
  66. /**
  67. * @brief Triggered when the input box value changes.
  68. */
  69. void valueChanged(const WString& newValue);
  70. /**
  71. * @brief Triggered when the input box value changes, but unlike the previous
  72. * overload the value is parsed into a floating point value.
  73. */
  74. void valueChanged(float newValue);
  75. /**
  76. * @brief Triggers when the input box receives or loses keyboard focus.
  77. */
  78. void focusChanged(bool focus);
  79. /**
  80. * @brief Triggered when the users confirms input in the input box.
  81. */
  82. void inputConfirmed();
  83. /**
  84. * @brief Callback that checks can the provided string be
  85. * converted to a floating point value.
  86. */
  87. static bool floatFilter(const WString& str);
  88. static const float DRAG_SPEED;
  89. GUIInputBox* mInputBox;
  90. float mValue;
  91. INT32 mLastDragPos;
  92. float mMinValue;
  93. float mMaxValue;
  94. bool mIsDragging;
  95. bool mHasInputFocus;
  96. };
  97. }