Allow SlideWrap to slide up, not only down.
This commit is contained in:
parent
43c61172d8
commit
6316443b27
2 changed files with 26 additions and 10 deletions
|
|
@ -46,6 +46,11 @@ SlideWrap<RpWidget> *SlideWrap<RpWidget>::setDuration(int duration) {
|
|||
return this;
|
||||
}
|
||||
|
||||
SlideWrap<RpWidget> *SlideWrap<RpWidget>::setDirectionUp(bool up) {
|
||||
_up = up;
|
||||
return this;
|
||||
}
|
||||
|
||||
SlideWrap<RpWidget> *SlideWrap<RpWidget>::toggle(
|
||||
bool shown,
|
||||
anim::type animated) {
|
||||
|
|
@ -92,22 +97,28 @@ SlideWrap<RpWidget> *SlideWrap<RpWidget>::toggleOn(
|
|||
}
|
||||
|
||||
void SlideWrap<RpWidget>::animationStep() {
|
||||
auto newWidth = width();
|
||||
if (auto weak = wrapped()) {
|
||||
auto margins = getMargins();
|
||||
const auto weak = wrapped();
|
||||
if (weak && !_up) {
|
||||
const auto margins = getMargins();
|
||||
weak->moveToLeft(margins.left(), margins.top());
|
||||
newWidth = weak->width();
|
||||
}
|
||||
auto current = _animation.value(_toggled ? 1. : 0.);
|
||||
auto newHeight = wrapped()
|
||||
const auto newWidth = weak ? weak->width() : width();
|
||||
const auto current = _animation.value(_toggled ? 1. : 0.);
|
||||
const auto newHeight = weak
|
||||
? (_animation.animating()
|
||||
? anim::interpolate(0, wrapped()->heightNoMargins(), current)
|
||||
: (_toggled ? wrapped()->height() : 0))
|
||||
? anim::interpolate(0, weak->heightNoMargins(), current)
|
||||
: (_toggled ? weak->height() : 0))
|
||||
: 0;
|
||||
if (weak && _up) {
|
||||
const auto margins = getMargins();
|
||||
weak->moveToLeft(
|
||||
margins.left(),
|
||||
margins.top() - (weak->height() - newHeight));
|
||||
}
|
||||
if (newWidth != width() || newHeight != height()) {
|
||||
resize(newWidth, newHeight);
|
||||
}
|
||||
auto shouldBeHidden = !_toggled && !_animation.animating();
|
||||
const auto shouldBeHidden = !_toggled && !_animation.animating();
|
||||
if (shouldBeHidden != isHidden()) {
|
||||
const auto guard = MakeWeak(this);
|
||||
setVisible(!shouldBeHidden);
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ public:
|
|||
const style::margins &padding);
|
||||
|
||||
SlideWrap *setDuration(int duration);
|
||||
SlideWrap *setDirectionUp(bool up);
|
||||
SlideWrap *toggle(bool shown, anim::type animated);
|
||||
SlideWrap *show(anim::type animated) {
|
||||
return toggle(true, animated);
|
||||
|
|
@ -62,10 +63,11 @@ protected:
|
|||
private:
|
||||
void animationStep();
|
||||
|
||||
bool _toggled = true;
|
||||
rpl::event_stream<bool> _toggledChanged;
|
||||
Animations::Simple _animation;
|
||||
int _duration = 0;
|
||||
bool _toggled = true;
|
||||
bool _up = false;
|
||||
|
||||
};
|
||||
|
||||
|
|
@ -94,6 +96,9 @@ public:
|
|||
SlideWrap *setDuration(int duration) {
|
||||
return chain(Parent::setDuration(duration));
|
||||
}
|
||||
SlideWrap *setDirectionUp(bool up) {
|
||||
return chain(Parent::setDirectionUp(up));
|
||||
}
|
||||
SlideWrap *toggle(bool shown, anim::type animated) {
|
||||
return chain(Parent::toggle(shown, animated));
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue