BsGUISliderField.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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 horizontal slider and a floating point input box.
  10. */
  11. class BS_ED_EXPORT GUISliderField : public TGUIField<GUISliderField>
  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. /**
  23. * Style type name for the internal slider.
  24. */
  25. static const String& getSliderStyleType();
  26. GUISliderField(const PrivatelyConstruct& dummy, const GUIContent& labelContent, UINT32 labelWidth,
  27. const String& style, const GUIDimensions& dimensions, bool withLabel);
  28. /**
  29. * @brief Returns the value of the input field/slider.
  30. */
  31. float getValue() const;
  32. /**
  33. * @brief Sets a new value in the input field/slider.
  34. */
  35. void setValue(float value);
  36. /**
  37. * @brief Sets a minimum and maximum allow values in the input field.
  38. * Set to large negative/positive values if you don't require clamping.
  39. */
  40. void setRange(float min, float max);
  41. /**
  42. * @brief Sets a step that defines the minimal increment the value can be increased/decreased by. Set to zero
  43. * to have no step.
  44. */
  45. void setStep(float step);
  46. /**
  47. * @brief Checks is the input field currently active.
  48. */
  49. bool hasInputFocus() const { return mHasInputFocus; }
  50. /**
  51. * @copydoc GUIElement::setTint
  52. */
  53. virtual void setTint(const Color& color) override;
  54. Event<void(float)> onValueChanged; /**< Triggers when the field value changes. */
  55. protected:
  56. virtual ~GUISliderField();
  57. /**
  58. * @copydoc GUIElementContainer::updateClippedBounds
  59. */
  60. void updateClippedBounds() override;
  61. /**
  62. * @copydoc GUIElementContainer::styleUpdated
  63. */
  64. void styleUpdated() override;
  65. /**
  66. * @brief Triggered when the input box value changes.
  67. */
  68. void valueChanged(const WString& newValue);
  69. /**
  70. * @brief Triggered when the slider is moved.
  71. */
  72. void sliderChanged(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. GUIInputBox* mInputBox;
  87. GUISliderHorz* mSlider;
  88. bool mHasInputFocus;
  89. };
  90. }