BsGUISliderField.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. * @copydoc GUIElement::setTint
  48. */
  49. virtual void setTint(const Color& color) override;
  50. Event<void(float)> onValueChanged; /**< Triggers when the field value changes. */
  51. protected:
  52. virtual ~GUISliderField();
  53. /**
  54. * @brief Sets a new value in the input field/slider without setting off an event.
  55. */
  56. void setValueInternal(float value);
  57. /**
  58. * @copydoc GUIElementContainer::styleUpdated
  59. */
  60. void styleUpdated() override;
  61. /**
  62. * @brief Triggered when the input box value changes.
  63. */
  64. void valueChanged(const WString& newValue);
  65. /**
  66. * @brief Triggered when the slider is moved.
  67. */
  68. void sliderChanged(float newValue);
  69. /**
  70. * @brief Callback that checks can the provided string be
  71. * converted to a floating point value.
  72. */
  73. static bool floatFilter(const WString& str);
  74. GUIInputBox* mInputBox;
  75. GUISliderHorz* mSlider;
  76. };
  77. }