2019-11-23 20:27:39 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2015 Neo Kim (neo.kim@neofect.com)
|
|
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
|
|
|
|
2022-07-09 22:23:34 +08:00
|
|
|
https://axis-project.github.io/
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef __UISCROLLVIEWBAR_H__
|
|
|
|
#define __UISCROLLVIEWBAR_H__
|
|
|
|
|
|
|
|
#include "ui/UIScrollView.h"
|
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
NS_AX_BEGIN
|
2019-11-23 20:27:39 +08:00
|
|
|
/**
|
|
|
|
* @addtogroup ui
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
|
|
|
class Sprite;
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
namespace ui
|
|
|
|
{
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Scroll bar being attached to ScrollView layout container.
|
|
|
|
*/
|
2022-07-15 19:44:31 +08:00
|
|
|
class CC_GUI_DLL ScrollViewBar : public ProtectedNode
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Default constructor
|
|
|
|
* @js ctor
|
|
|
|
* @lua new
|
|
|
|
*/
|
|
|
|
ScrollViewBar(ScrollView* parent, ScrollView::Direction direction);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
/**
|
|
|
|
* Default destructor
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
|
|
|
virtual ~ScrollViewBar();
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
/**
|
|
|
|
* Create a scroll bar with its parent scroll view and direction.
|
|
|
|
* @return A scroll bar instance.
|
|
|
|
*/
|
|
|
|
static ScrollViewBar* create(ScrollView* parent, ScrollView::Direction direction);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
/**
|
|
|
|
* @brief Set the scroll bar position from the left-bottom corner (horizontal) or right-top corner (vertical).
|
|
|
|
*
|
|
|
|
* @param positionFromCorner The position from the left-bottom corner (horizontal) or right-top corner (vertical).
|
|
|
|
*/
|
|
|
|
void setPositionFromCorner(const Vec2& positionFromCorner);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
/**
|
|
|
|
* @brief Get the scroll bar position from the left-bottom corner (horizontal) or right-top corner (vertical).
|
|
|
|
*
|
|
|
|
* @return positionFromCorner
|
|
|
|
*/
|
|
|
|
Vec2 getPositionFromCorner() const;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
/**
|
|
|
|
* @brief Set the scroll bar's width
|
|
|
|
*
|
|
|
|
* @param width The scroll bar's width
|
|
|
|
*/
|
|
|
|
void setWidth(float width);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
/**
|
|
|
|
* @brief Get the scroll bar's width
|
|
|
|
*
|
|
|
|
* @return the scroll bar's width
|
|
|
|
*/
|
|
|
|
float getWidth() const;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
/**
|
|
|
|
* @brief Set scroll bar auto hide state
|
|
|
|
*
|
|
|
|
* @param scroll bar auto hide state
|
|
|
|
*/
|
|
|
|
void setAutoHideEnabled(bool autoHideEnabled);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
/**
|
|
|
|
* @brief Query scroll bar auto hide state
|
|
|
|
*
|
|
|
|
* @return True if scroll bar auto hide is enabled, false otherwise.
|
|
|
|
*/
|
|
|
|
bool isAutoHideEnabled() const { return _autoHideEnabled; }
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
/**
|
|
|
|
* @brief Set scroll bar auto hide time
|
|
|
|
*
|
|
|
|
* @param scroll bar auto hide time
|
|
|
|
*/
|
|
|
|
void setAutoHideTime(float autoHideTime) { _autoHideTime = autoHideTime; }
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
/**
|
|
|
|
* @brief Get the scroll bar's auto hide time
|
|
|
|
*
|
|
|
|
* @return the scroll bar's auto hide time
|
|
|
|
*/
|
|
|
|
float getAutoHideTime() const { return _autoHideTime; }
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
/**
|
|
|
|
* @brief This is called by parent ScrollView when the parent is scrolled. Don't call this directly.
|
|
|
|
*
|
|
|
|
* @param amount how much the inner container of ScrollView is out of boundary
|
|
|
|
*/
|
|
|
|
virtual void onScrolled(const Vec2& outOfBoundary);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
/**
|
|
|
|
* @lua NA
|
|
|
|
*/
|
|
|
|
virtual void setOpacity(uint8_t opacity) override { _opacity = opacity; }
|
|
|
|
virtual uint8_t getOpacity() const override { return _opacity; }
|
|
|
|
virtual void onEnter() override;
|
|
|
|
virtual void update(float deltaTime) override;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
/**
|
|
|
|
* @brief This is called by parent ScrollView when a touch is began. Don't call this directly.
|
|
|
|
*/
|
|
|
|
void onTouchBegan();
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
/**
|
|
|
|
* @brief This is called by parent ScrollView when a touch is ended. Don't call this directly.
|
|
|
|
*/
|
|
|
|
void onTouchEnded();
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2022-03-18 21:46:07 +08:00
|
|
|
virtual bool init() override;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
private:
|
|
|
|
float calculateLength(float innerContainerMeasure, float scrollViewMeasure, float outOfBoundaryValue);
|
2021-12-25 10:04:45 +08:00
|
|
|
Vec2 calculatePosition(float innerContainerMeasure,
|
|
|
|
float scrollViewMeasure,
|
|
|
|
float innerContainerPosition,
|
|
|
|
float outOfBoundaryValue,
|
|
|
|
float actualLength);
|
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
void updateLength(float length);
|
|
|
|
void processAutoHide(float deltaTime);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
ScrollView* _parent;
|
|
|
|
ScrollView::Direction _direction;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
Sprite* _upperHalfCircle;
|
|
|
|
Sprite* _lowerHalfCircle;
|
|
|
|
Sprite* _body;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
uint8_t _opacity;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
float _marginFromBoundary;
|
|
|
|
float _marginForLength;
|
|
|
|
|
|
|
|
bool _touching;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
bool _autoHideEnabled;
|
|
|
|
float _autoHideTime;
|
|
|
|
float _autoHideRemainingTime;
|
|
|
|
};
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
} // namespace ui
|
2019-11-23 20:27:39 +08:00
|
|
|
// end of ui group
|
|
|
|
/// @}
|
2022-07-11 17:50:21 +08:00
|
|
|
NS_AX_END
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
#endif /* defined(__UISCROLLVIEWBAR_H__) */
|