| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213 |
- // Copyright (c) 2008-2023 the Urho3D project
- // License: MIT
- #pragma once
- #include "../UI/UIElement.h"
- namespace Urho3D
- {
- class BorderImage;
- class ScrollBar;
- /// Scrollable %UI element for showing a (possibly large) child element.
- class URHO3D_API ScrollView : public UIElement
- {
- URHO3D_OBJECT(ScrollView, UIElement);
- public:
- /// Construct.
- explicit ScrollView(Context* context);
- /// Destruct.
- ~ScrollView() override;
- /// Register object factory.
- /// @nobind
- static void RegisterObject(Context* context);
- /// Perform UI element update.
- void Update(float timeStep) override;
- /// Apply attribute changes that can not be applied immediately.
- void ApplyAttributes() override;
- /// React to mouse wheel.
- void OnWheel(int delta, MouseButtonFlags buttons, QualifierFlags qualifiers) override;
- /// React to a key press.
- void OnKey(Key key, MouseButtonFlags buttons, QualifierFlags qualifiers) override;
- /// React to resize.
- void OnResize(const IntVector2& newSize, const IntVector2& delta) override;
- /// Return whether the element could handle wheel input.
- bool IsWheelHandler() const override { return true; }
- /// Set content element.
- /// @property
- void SetContentElement(UIElement* element);
- /// Set view offset from the top-left corner.
- /// @property
- void SetViewPosition(const IntVector2& position);
- /// Set view offset from the top-left corner.
- void SetViewPosition(int x, int y);
- /// Set scrollbars' visibility manually. Disables scrollbar autoshow/hide.
- void SetScrollBarsVisible(bool horizontal, bool vertical);
- /// Set horizontal scrollbar visibility manually. Disables scrollbar autoshow/hide.
- /// @property
- void SetHorizontalScrollBarVisible(bool visible);
- /// Set vertical scrollbar visibility manually. Disables scrollbar autoshow/hide.
- /// @property
- void SetVerticalScrollBarVisible(bool visible);
- /// Set whether to automatically show/hide scrollbars. Default true.
- /// @property
- void SetScrollBarsAutoVisible(bool enable);
- /// Set arrow key scroll step. Also sets it on the scrollbars.
- /// @property
- void SetScrollStep(float step);
- /// Set arrow key page step.
- /// @property
- void SetPageStep(float step);
- /// Set scroll deceleration.
- /// @property
- void SetScrollDeceleration(float deceleration) { scrollDeceleration_ = deceleration; }
- /// Set scroll snap epsilon.
- /// @property
- void SetScrollSnapEpsilon(float snap) { scrollSnapEpsilon_ = snap; }
- /// Set whether child elements should be disabled while touch scrolling.
- /// @property
- void SetAutoDisableChildren(bool disable) { autoDisableChildren_ = disable; };
- /// Set how much touch movement is needed to trigger child element disabling.
- /// @property
- void SetAutoDisableThreshold(float amount) { autoDisableThreshold_ = amount; };
- /// Return view offset from the top-left corner.
- /// @property
- const IntVector2& GetViewPosition() const { return viewPosition_; }
- /// Return content element.
- /// @property
- UIElement* GetContentElement() const { return contentElement_; }
- /// Return horizontal scroll bar.
- /// @property
- ScrollBar* GetHorizontalScrollBar() const { return horizontalScrollBar_; }
- /// Return vertical scroll bar.
- /// @property
- ScrollBar* GetVerticalScrollBar() const { return verticalScrollBar_; }
- /// Return scroll panel.
- /// @property
- BorderImage* GetScrollPanel() const { return scrollPanel_; }
- /// Return whether scrollbars are automatically shown/hidden.
- /// @property
- bool GetScrollBarsAutoVisible() const { return scrollBarsAutoVisible_; }
- /// Return whether the horizontal scrollbar is visible.
- /// @property
- bool GetHorizontalScrollBarVisible() const;
- /// Return whether the vertical scrollbar is visible.
- /// @property
- bool GetVerticalScrollBarVisible() const;
- /// Return arrow key scroll step.
- /// @property
- float GetScrollStep() const;
- /// Return arrow key page step.
- /// @property
- float GetPageStep() const { return pageStep_; }
- /// Return scroll deceleration.
- /// @property
- float GetScrollDeceleration() const { return scrollDeceleration_; }
- /// Return scroll snap epsilon.
- /// @property
- float GetScrollSnapEpsilon() const { return scrollSnapEpsilon_; }
- /// Return whether child element will be disabled while touch scrolling.
- /// @property
- bool GetAutoDisableChildren() const { return autoDisableChildren_; }
- /// Return how much touch movement is needed to trigger child element disabling.
- /// @property
- float GetAutoDisableThreshold() const { return autoDisableThreshold_; }
- /// Set view position attribute.
- void SetViewPositionAttr(const IntVector2& value);
- protected:
- /// Filter implicit attributes in serialization process.
- bool FilterImplicitAttributes(XMLElement& dest) const override;
- /// Filter implicit attributes in serialization process for internal scroll bar.
- bool FilterScrollBarImplicitAttributes(XMLElement& dest, const String& name) const;
- /// Resize panel based on scrollbar visibility.
- void UpdatePanelSize();
- /// Recalculate view size, validate view position and update scrollbars.
- void UpdateViewSize();
- /// Update the scrollbars' ranges and positions.
- void UpdateScrollBars();
- /// Limit and update the view with a new position.
- void UpdateView(const IntVector2& position);
- /// Content element.
- SharedPtr<UIElement> contentElement_;
- /// Horizontal scroll bar.
- SharedPtr<ScrollBar> horizontalScrollBar_;
- /// Vertical scroll bar.
- SharedPtr<ScrollBar> verticalScrollBar_;
- /// Scroll panel element.
- SharedPtr<BorderImage> scrollPanel_;
- /// Current view offset from the top-left corner.
- IntVector2 viewPosition_;
- /// Total view size.
- IntVector2 viewSize_;
- /// View offset attribute.
- IntVector2 viewPositionAttr_;
- /// Accumulated touch scroll speed.
- Vector2 touchScrollSpeed_;
- /// Max touch scroll speed.
- Vector2 touchScrollSpeedMax_;
- /// Arrow key page step.
- float pageStep_;
- /// Automatically show/hide scrollbars flag.
- bool scrollBarsAutoVisible_;
- /// Ignore scrollbar events flag. Used to prevent possible endless loop when resizing.
- bool ignoreEvents_;
- /// Resize content widget width to match panel. Internal flag, used by the ListView class.
- bool resizeContentWidth_;
- /// Scroll deceleration.
- float scrollDeceleration_;
- /// Scroll snap epsilon.
- float scrollSnapEpsilon_;
- /// Used to trigger scroll smoothing when false.
- bool scrollTouchDown_;
- /// Used to prevent touch scroll - scroll bar conflict.
- bool barScrolling_;
- /// Used to determine if child elements should be disabled while touch scrolling, to prevent their trigger.
- bool autoDisableChildren_;
- /// Used to determine if children have been disabled.
- bool scrollChildrenDisable_;
- /// Distance moved with touch scrolling.
- float touchDistanceSum_;
- /// Threshold to trigger auto disable children.
- float autoDisableThreshold_;
- private:
- /// Handle scrollbar value changed.
- void HandleScrollBarChanged(StringHash eventType, VariantMap& eventData);
- /// Handle scrollbar visibility changed.
- void HandleScrollBarVisibleChanged(StringHash eventType, VariantMap& eventData);
- /// Handle content element resized.
- void HandleElementResized(StringHash eventType, VariantMap& eventData);
- /// Handle touch move event for scrolling.
- void HandleTouchMove(StringHash eventType, VariantMap& eventData);
- /// Handle the scroll smoothing.
- void ScrollSmooth(float timeStep);
- };
- }
|