BsGUIFloatField.h 2.7 KB

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