BsGUIFloatField.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "BsEditorPrerequisites.h"
  5. #include "GUI/BsGUIFieldBase.h"
  6. namespace bs
  7. {
  8. /** @addtogroup GUI-Editor
  9. * @{
  10. */
  11. /**
  12. * A composite GUI object representing an editor field. Editor fields are a combination of a label and an input field.
  13. * Label is optional. This specific implementation displays a floating point input field.
  14. */
  15. class BS_ED_EXPORT GUIFloatField : public TGUIField<GUIFloatField>
  16. {
  17. public:
  18. /** Returns type name of the GUI element used for finding GUI element styles. */
  19. static const String& getGUITypeName();
  20. /** Style type name for the internal input box. */
  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. /** Returns the value of the input field. */
  25. float getValue() const;
  26. /** Sets a new value in the input field, it returns the clamped value according to range and step. */
  27. float setValue(float value);
  28. /**
  29. * Sets a minimum and maximum allowed values in the input field. Set to large negative/positive values if you don't
  30. * require clamping.
  31. */
  32. void setRange(float min, float max);
  33. /** Sets the minimum change allowed for the input field. */
  34. void setStep(float step);
  35. /** Returns the minimum change allowed for the input field. */
  36. float getStep() const{ return mStep; }
  37. /** Checks is the input field currently active. */
  38. bool hasInputFocus() const { return mHasInputFocus; }
  39. /** @copydoc GUIElement::setTint */
  40. void setTint(const Color& color) override;
  41. Event<void(float)> onValueChanged; /**< Triggers when the field value changes. */
  42. Event<void()> onConfirm; /**< Triggered when the user hits the Enter key with the input box in focus. */
  43. /** @name Internal
  44. * @{
  45. */
  46. /**
  47. * Sets a new value in the input field, and also allows you to choose should the field trigger an onValueChanged
  48. * event.
  49. */
  50. void _setValue(float value, bool triggerEvent);
  51. /** @} */
  52. protected:
  53. virtual ~GUIFloatField() = default;
  54. /** @copydoc GUIElementContainer::_hasCustomCursor */
  55. bool _hasCustomCursor(Vector2I position, CursorType& type) const override;
  56. /** @copydoc GUIElementContainer::_mouseEvent */
  57. bool _mouseEvent(const GUIMouseEvent& ev) override;
  58. /** @copydoc GUIElementContainer::styleUpdated */
  59. void styleUpdated() override;
  60. /** Triggered when the input box value changes. */
  61. void valueChanged(const String& newValue);
  62. /** Triggers when the input box receives or loses keyboard focus. */
  63. void focusChanged(bool focus);
  64. /** Triggered when the users confirms input in the input box. */
  65. void inputConfirmed();
  66. /** Updates the underlying input box with the text representing the provided floating point value. */
  67. void setText(float value);
  68. /** Clamps the provided value to current valid range, and step interval. */
  69. float applyRangeAndStep(float value) const;
  70. /** Callback that checks can the provided string be converted to a floating point value. */
  71. static bool floatFilter(const String& str);
  72. static const float DRAG_SPEED;
  73. GUIInputBox* mInputBox;
  74. float mValue;
  75. INT32 mLastDragPos;
  76. float mMinValue;
  77. float mMaxValue;
  78. float mStep;
  79. bool mIsDragging;
  80. bool mHasInputFocus;
  81. };
  82. /** @} */
  83. }