From 6316443b27cffbf0205e07edc0616d370044893c Mon Sep 17 00:00:00 2001 From: John Preston Date: Tue, 22 Feb 2022 15:48:51 +0300 Subject: [PATCH] Allow SlideWrap to slide up, not only down. --- ui/wrap/slide_wrap.cpp | 29 ++++++++++++++++++++--------- ui/wrap/slide_wrap.h | 7 ++++++- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/ui/wrap/slide_wrap.cpp b/ui/wrap/slide_wrap.cpp index 8075c5b..1dcd246 100644 --- a/ui/wrap/slide_wrap.cpp +++ b/ui/wrap/slide_wrap.cpp @@ -46,6 +46,11 @@ SlideWrap *SlideWrap::setDuration(int duration) { return this; } +SlideWrap *SlideWrap::setDirectionUp(bool up) { + _up = up; + return this; +} + SlideWrap *SlideWrap::toggle( bool shown, anim::type animated) { @@ -92,22 +97,28 @@ SlideWrap *SlideWrap::toggleOn( } void SlideWrap::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); diff --git a/ui/wrap/slide_wrap.h b/ui/wrap/slide_wrap.h index d972d7f..fcee961 100644 --- a/ui/wrap/slide_wrap.h +++ b/ui/wrap/slide_wrap.h @@ -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 _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)); }