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;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SlideWrap<RpWidget> *SlideWrap<RpWidget>::setDirectionUp(bool up) {
|
||||||
|
_up = up;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
SlideWrap<RpWidget> *SlideWrap<RpWidget>::toggle(
|
SlideWrap<RpWidget> *SlideWrap<RpWidget>::toggle(
|
||||||
bool shown,
|
bool shown,
|
||||||
anim::type animated) {
|
anim::type animated) {
|
||||||
|
|
@ -92,22 +97,28 @@ SlideWrap<RpWidget> *SlideWrap<RpWidget>::toggleOn(
|
||||||
}
|
}
|
||||||
|
|
||||||
void SlideWrap<RpWidget>::animationStep() {
|
void SlideWrap<RpWidget>::animationStep() {
|
||||||
auto newWidth = width();
|
const auto weak = wrapped();
|
||||||
if (auto weak = wrapped()) {
|
if (weak && !_up) {
|
||||||
auto margins = getMargins();
|
const auto margins = getMargins();
|
||||||
weak->moveToLeft(margins.left(), margins.top());
|
weak->moveToLeft(margins.left(), margins.top());
|
||||||
newWidth = weak->width();
|
|
||||||
}
|
}
|
||||||
auto current = _animation.value(_toggled ? 1. : 0.);
|
const auto newWidth = weak ? weak->width() : width();
|
||||||
auto newHeight = wrapped()
|
const auto current = _animation.value(_toggled ? 1. : 0.);
|
||||||
|
const auto newHeight = weak
|
||||||
? (_animation.animating()
|
? (_animation.animating()
|
||||||
? anim::interpolate(0, wrapped()->heightNoMargins(), current)
|
? anim::interpolate(0, weak->heightNoMargins(), current)
|
||||||
: (_toggled ? wrapped()->height() : 0))
|
: (_toggled ? weak->height() : 0))
|
||||||
: 0;
|
: 0;
|
||||||
|
if (weak && _up) {
|
||||||
|
const auto margins = getMargins();
|
||||||
|
weak->moveToLeft(
|
||||||
|
margins.left(),
|
||||||
|
margins.top() - (weak->height() - newHeight));
|
||||||
|
}
|
||||||
if (newWidth != width() || newHeight != height()) {
|
if (newWidth != width() || newHeight != height()) {
|
||||||
resize(newWidth, newHeight);
|
resize(newWidth, newHeight);
|
||||||
}
|
}
|
||||||
auto shouldBeHidden = !_toggled && !_animation.animating();
|
const auto shouldBeHidden = !_toggled && !_animation.animating();
|
||||||
if (shouldBeHidden != isHidden()) {
|
if (shouldBeHidden != isHidden()) {
|
||||||
const auto guard = MakeWeak(this);
|
const auto guard = MakeWeak(this);
|
||||||
setVisible(!shouldBeHidden);
|
setVisible(!shouldBeHidden);
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,7 @@ public:
|
||||||
const style::margins &padding);
|
const style::margins &padding);
|
||||||
|
|
||||||
SlideWrap *setDuration(int duration);
|
SlideWrap *setDuration(int duration);
|
||||||
|
SlideWrap *setDirectionUp(bool up);
|
||||||
SlideWrap *toggle(bool shown, anim::type animated);
|
SlideWrap *toggle(bool shown, anim::type animated);
|
||||||
SlideWrap *show(anim::type animated) {
|
SlideWrap *show(anim::type animated) {
|
||||||
return toggle(true, animated);
|
return toggle(true, animated);
|
||||||
|
|
@ -62,10 +63,11 @@ protected:
|
||||||
private:
|
private:
|
||||||
void animationStep();
|
void animationStep();
|
||||||
|
|
||||||
bool _toggled = true;
|
|
||||||
rpl::event_stream<bool> _toggledChanged;
|
rpl::event_stream<bool> _toggledChanged;
|
||||||
Animations::Simple _animation;
|
Animations::Simple _animation;
|
||||||
int _duration = 0;
|
int _duration = 0;
|
||||||
|
bool _toggled = true;
|
||||||
|
bool _up = false;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -94,6 +96,9 @@ public:
|
||||||
SlideWrap *setDuration(int duration) {
|
SlideWrap *setDuration(int duration) {
|
||||||
return chain(Parent::setDuration(duration));
|
return chain(Parent::setDuration(duration));
|
||||||
}
|
}
|
||||||
|
SlideWrap *setDirectionUp(bool up) {
|
||||||
|
return chain(Parent::setDirectionUp(up));
|
||||||
|
}
|
||||||
SlideWrap *toggle(bool shown, anim::type animated) {
|
SlideWrap *toggle(bool shown, anim::type animated) {
|
||||||
return chain(Parent::toggle(shown, animated));
|
return chain(Parent::toggle(shown, animated));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue