ScrollBar.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. // Copyright (c) 2008-2023 the Urho3D project
  2. // License: MIT
  3. #pragma once
  4. #include "../UI/BorderImage.h"
  5. namespace Urho3D
  6. {
  7. class Button;
  8. class Slider;
  9. /// Scroll bar %UI element with forward and back buttons.
  10. class URHO3D_API ScrollBar : public BorderImage
  11. {
  12. URHO3D_OBJECT(ScrollBar, BorderImage);
  13. public:
  14. /// Construct.
  15. explicit ScrollBar(Context* context);
  16. /// Destruct.
  17. ~ScrollBar() override;
  18. /// Register object factory.
  19. /// @nobind
  20. static void RegisterObject(Context* context);
  21. /// Apply attribute changes that can not be applied immediately.
  22. void ApplyAttributes() override;
  23. /// React to resize.
  24. void OnResize(const IntVector2& newSize, const IntVector2& delta) override;
  25. /// React to editable status change.
  26. void OnSetEditable() override;
  27. /// Set orientation type.
  28. /// @property
  29. void SetOrientation(Orientation orientation);
  30. /// Set slider range maximum value (minimum value is always 0).
  31. /// @property
  32. void SetRange(float range);
  33. /// Set slider current value.
  34. /// @property
  35. void SetValue(float value);
  36. /// Change slider current value by a delta.
  37. void ChangeValue(float delta);
  38. /// Set button scroll step.
  39. /// @property
  40. void SetScrollStep(float step);
  41. /// Set button step factor, can be used to adjust the step for constant pixel size.
  42. /// @property
  43. void SetStepFactor(float factor);
  44. /// Scroll back one step.
  45. void StepBack();
  46. /// Scroll forward one step.
  47. void StepForward();
  48. /// Return scrollbar orientation.
  49. /// @property
  50. Orientation GetOrientation() const;
  51. /// Return slider range.
  52. /// @property
  53. float GetRange() const;
  54. /// Return slider current value.
  55. /// @property
  56. float GetValue() const;
  57. /// Return button scroll step.
  58. /// @property
  59. float GetScrollStep() const { return scrollStep_; }
  60. /// Return button step factor.
  61. /// @property
  62. float GetStepFactor() const { return stepFactor_; }
  63. /// Return scroll step multiplied by factor.
  64. /// @property
  65. float GetEffectiveScrollStep() const;
  66. /// Return back button element.
  67. /// @property
  68. Button* GetBackButton() const { return backButton_; }
  69. /// Return forward button element.
  70. /// @property
  71. Button* GetForwardButton() const { return forwardButton_; }
  72. /// Return slider element.
  73. /// @property
  74. Slider* GetSlider() const { return slider_; }
  75. protected:
  76. /// Filter implicit attributes in serialization process.
  77. bool FilterImplicitAttributes(XMLElement& dest) const override;
  78. /// Filter implicit attributes in serialization process for internal button.
  79. bool FilterButtonImplicitAttributes(XMLElement& dest, const String& name) const;
  80. /// Back button.
  81. SharedPtr<Button> backButton_;
  82. /// Forward button.
  83. SharedPtr<Button> forwardButton_;
  84. /// Slider.
  85. SharedPtr<Slider> slider_;
  86. /// Scroll step.
  87. float scrollStep_;
  88. /// Step factor.
  89. float stepFactor_;
  90. /// Left button image rect.
  91. IntRect leftRect_;
  92. /// Right button image rect.
  93. IntRect rightRect_;
  94. /// Up button image rect.
  95. IntRect upRect_;
  96. /// Down button image rect.
  97. IntRect downRect_;
  98. private:
  99. /// Handle back button pressed.
  100. void HandleBackButtonPressed(StringHash eventType, VariantMap& eventData);
  101. /// Handle forward button pressed.
  102. void HandleForwardButtonPressed(StringHash eventType, VariantMap& eventData);
  103. /// Handle slider movement.
  104. void HandleSliderChanged(StringHash eventType, VariantMap& eventData);
  105. /// Handle slider touch and click on "paging" area.
  106. void HandleSliderPaged(StringHash eventType, VariantMap& eventData);
  107. };
  108. }