BsGUIFloatField.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. virtual void setTint(const Color& color) override;
  45. Event<void(float)> onValueChanged; /**< Triggers when the field value changes. */
  46. protected:
  47. virtual ~GUIFloatField();
  48. /**
  49. * @copydoc GUIElementContainer::updateClippedBounds
  50. */
  51. void updateClippedBounds() override;
  52. /**
  53. * @copydoc GUIElementContainer::_hasCustomCursor
  54. */
  55. bool _hasCustomCursor(const Vector2I position, CursorType& type) const override;
  56. /**
  57. * @copydoc GUIElementContainer::_mouseEvent
  58. */
  59. virtual bool _mouseEvent(const GUIMouseEvent& ev) override;
  60. /**
  61. * @copydoc GUIElementContainer::styleUpdated
  62. */
  63. void styleUpdated() override;
  64. /**
  65. * @brief Triggered when the input box value changes.
  66. */
  67. void valueChanged(const WString& newValue);
  68. /**
  69. * @brief Triggered when the input box value changes, but unlike the previous
  70. * overload the value is parsed into a floating point value.
  71. */
  72. void valueChanged(float newValue);
  73. /**
  74. * @brief Triggers when the input box receives keyboard focus.
  75. */
  76. void focusGained();
  77. /**
  78. * @brief Triggers when the input box loses keyboard focus.
  79. */
  80. void focusLost();
  81. /**
  82. * @brief Callback that checks can the provided string be
  83. * converted to a floating point value.
  84. */
  85. static bool floatFilter(const WString& str);
  86. static const float DRAG_SPEED;
  87. GUIInputBox* mInputBox;
  88. float mValue;
  89. INT32 mLastDragPos;
  90. float mMinValue;
  91. float mMaxValue;
  92. bool mIsDragging;
  93. bool mHasInputFocus;
  94. };
  95. }