WidgetSliderScroll.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. * This source file is part of RmlUi, the HTML/CSS Interface Middleware
  3. *
  4. * For the latest information, see http://github.com/mikke89/RmlUi
  5. *
  6. * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
  7. * Copyright (c) 2019 The RmlUi Team, and contributors
  8. *
  9. * Permission is hereby granted, free of charge, to any person obtaining a copy
  10. * of this software and associated documentation files (the "Software"), to deal
  11. * in the Software without restriction, including without limitation the rights
  12. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  13. * copies of the Software, and to permit persons to whom the Software is
  14. * furnished to do so, subject to the following conditions:
  15. *
  16. * The above copyright notice and this permission notice shall be included in
  17. * all copies or substantial portions of the Software.
  18. *
  19. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  20. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  21. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  22. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  23. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  24. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  25. * THE SOFTWARE.
  26. *
  27. */
  28. #ifndef RMLUICOREWIDGETSLIDERSCROLL_H
  29. #define RMLUICOREWIDGETSLIDERSCROLL_H
  30. #include "WidgetSlider.h"
  31. namespace Rml {
  32. namespace Core {
  33. /**
  34. @author Peter Curry
  35. */
  36. class WidgetSliderScroll : public WidgetSlider
  37. {
  38. public:
  39. WidgetSliderScroll(Element* parent);
  40. virtual ~WidgetSliderScroll();
  41. /// Sets the length of the entire track in scrollable units (usually lines or characters). This affects the
  42. /// length of the bar element and the speed of scrolling using the mouse-wheel or arrows.
  43. /// @param[in] track_length The length of the track.
  44. /// @param[in] force_resize True to resize the bar immediately, false to wait until the next format.
  45. void SetTrackLength(float track_length, bool force_resize = true);
  46. /// Sets the length the bar represents in scrollable units (usually lines or characters), relative to the track
  47. /// length. For example, for a scroll bar, this would represent how big each visible 'page' is compared to the
  48. /// whole document (which would be set as the track length).
  49. /// @param[in] bar_length The length of the slider's bar.
  50. /// @param[in] force_resize True to resize the bar immediately, false to wait until the next format.
  51. void SetBarLength(float bar_length, bool force_resize = true);
  52. /// Sets the line height of the parent element; this is used for scrolling speeds.
  53. /// @param[in] line_height The line height of the parent element.
  54. void SetLineHeight(float line_height);
  55. /// Lays out and resizes the internal elements.
  56. /// @param[in] containing_block The padded box containing the slider. This is used to resolve relative properties.
  57. /// @param[in] length The total length, in pixels, of the slider widget.
  58. void FormatElements(const Vector2f& containing_block, float slider_length);
  59. protected:
  60. /// Called when the slider's bar position is set or dragged.
  61. /// @param bar_position[in] The new position of the bar (0 representing the start of the track, 1 representing the end).
  62. /// @return The new position of the bar.
  63. float OnBarChange(float bar_position) override;
  64. /// Called when the slider is incremented by one 'line', either by the down / right key or a mouse-click on the
  65. /// increment arrow.
  66. /// @return The new position of the bar.
  67. float OnLineIncrement() override;
  68. /// Called when the slider is decremented by one 'line', either by the up / left key or a mouse-click on the
  69. /// decrement arrow.
  70. /// @return The new position of the bar.
  71. float OnLineDecrement() override;
  72. /// Called when the slider is incremented by one 'page', either by the page-up key or a mouse-click on the
  73. /// track below / right of the bar.
  74. /// @return The new position of the bar.
  75. float OnPageIncrement(float click_position) override;
  76. /// Called when the slider is incremented by one 'page', either by the page-down key or a mouse-click on the
  77. /// track above / left of the bar.
  78. /// @return The new position of the bar.
  79. float OnPageDecrement(float click_position) override;
  80. private:
  81. // Returns the bar position after scrolling for a number of pixels.
  82. float Scroll(float distance);
  83. float track_length;
  84. float bar_length;
  85. float line_height;
  86. };
  87. }
  88. }
  89. #endif