Skip to content

Commit

Permalink
Add dont-clip-margin feature to ScrollPane
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoguzhu committed Jul 10, 2020
1 parent cfd88ef commit b53d839
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 25 deletions.
59 changes: 34 additions & 25 deletions libfairygui/Classes/ScrollPane.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,24 +42,25 @@ static inline float sp_EaseFunc(float t, float d)

ScrollPane::ScrollPane(GComponent* owner)
: _vtScrollBar(nullptr),
_hzScrollBar(nullptr),
_header(nullptr),
_footer(nullptr),
_pageController(nullptr),
_needRefresh(false),
_refreshBarAxis(0),
_aniFlag(0),
_loop(0),
_headerLockedSize(0),
_footerLockedSize(0),
_vScrollNone(false),
_hScrollNone(false),
_tweening(0),
_xPos(0),
_yPos(0),
_floating(false),
_mouseWheelEnabled(true),
_hover(false)
_hzScrollBar(nullptr),
_header(nullptr),
_footer(nullptr),
_pageController(nullptr),
_needRefresh(false),
_refreshBarAxis(0),
_aniFlag(0),
_loop(0),
_headerLockedSize(0),
_footerLockedSize(0),
_vScrollNone(false),
_hScrollNone(false),
_tweening(0),
_xPos(0),
_yPos(0),
_floating(false),
_dontClipMargin(false),
_mouseWheelEnabled(true),
_hover(false)
{
_owner = owner;

Expand Down Expand Up @@ -134,6 +135,7 @@ void ScrollPane::setup(ByteBuffer* buffer)
_inertiaDisabled = (flags & 256) != 0;
_maskContainer->setClippingEnabled((flags & 512) == 0);
_floating = (flags & 1024) != 0;
_dontClipMargin = (flags & 2048) != 0;

if (scrollBarDisplay == ScrollBarDisplayType::DEFAULT)
{
Expand Down Expand Up @@ -758,6 +760,13 @@ void ScrollPane::handleSizeChanged()
maskRect.size.width += _vtScrollBar->getWidth();
if (_hScrollNone && _hzScrollBar != nullptr)
maskRect.size.height += _hzScrollBar->getHeight();
if (_dontClipMargin)
{
maskRect.origin.x -= _owner->_margin.left;
maskRect.size.width += _owner->_margin.left + _owner->_margin.right;
maskRect.origin.y -= _owner->_margin.top;
maskRect.size.height += _owner->_margin.top + _owner->_margin.bottom;
}
_maskContainer->setClippingRegion(maskRect);

if (_vtScrollBar)
Expand Down Expand Up @@ -787,10 +796,10 @@ void ScrollPane::handleSizeChanged()
max += _footerLockedSize;
if (_refreshBarAxis == 0)
_container->setPosition2(clampf(_container->getPositionX(), -max, _headerLockedSize),
clampf(_container->getPositionY2(), -_overlapSize.height, 0));
clampf(_container->getPositionY2(), -_overlapSize.height, 0));
else
_container->setPosition2(clampf(_container->getPositionX(), -_overlapSize.width, 0),
clampf(_container->getPositionY2(), -max, _headerLockedSize));
clampf(_container->getPositionY2(), -max, _headerLockedSize));

if (_header != nullptr)
{
Expand Down Expand Up @@ -977,9 +986,9 @@ void ScrollPane::updateScrollBarVisible2(GScrollBar* bar)
{
if (bar->isVisible())
GTween::to(1, 0, 0.5f)
->setDelay(0.5f)
->onComplete1(CC_CALLBACK_1(ScrollPane::onBarTweenComplete, this))
->setTarget(bar, TweenPropType::Alpha);
->setDelay(0.5f)
->onComplete1(CC_CALLBACK_1(ScrollPane::onBarTweenComplete, this))
->setTarget(bar, TweenPropType::Alpha);
}
else
{
Expand Down Expand Up @@ -1221,7 +1230,7 @@ float ScrollPane::updateTargetAndDuration(float pos, int axis)
{
if (v2 > 1000)
ratio = pow((v2 - 1000) / 1000, 2);
}
}
#endif

if (ratio != 0)
Expand All @@ -1237,7 +1246,7 @@ float ScrollPane::updateTargetAndDuration(float pos, int axis)
float change = (int)(v * duration * 0.4f);
pos += change;
}
}
}

if (duration < TWEEN_TIME_DEFAULT)
duration = TWEEN_TIME_DEFAULT;
Expand Down
1 change: 1 addition & 0 deletions libfairygui/Classes/ScrollPane.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ class ScrollPane : public cocos2d::Ref
float _decelerationRate;
bool _pageMode;
bool _floating;
bool _dontClipMargin;

float _xPos;
float _yPos;
Expand Down

0 comments on commit b53d839

Please sign in to comment.