init
Some checks failed
Docker. / Ubuntu (push) Has been cancelled
User-agent updater. / User-agent (push) Failing after 15s
Lock Threads / lock (push) Failing after 10s
Waiting for answer. / waiting-for-answer (push) Failing after 22s
Needs user action. / needs-user-action (push) Failing after 8s
Can't reproduce. / cant-reproduce (push) Failing after 8s
Close stale issues and PRs / stale (push) Has been cancelled
Some checks failed
Docker. / Ubuntu (push) Has been cancelled
User-agent updater. / User-agent (push) Failing after 15s
Lock Threads / lock (push) Failing after 10s
Waiting for answer. / waiting-for-answer (push) Failing after 22s
Needs user action. / needs-user-action (push) Failing after 8s
Can't reproduce. / cant-reproduce (push) Failing after 8s
Close stale issues and PRs / stale (push) Has been cancelled
This commit is contained in:
155
Telegram/lib_ui/ui/wrap/slide_wrap.h
Normal file
155
Telegram/lib_ui/ui/wrap/slide_wrap.h
Normal file
@@ -0,0 +1,155 @@
|
||||
// This file is part of Desktop App Toolkit,
|
||||
// a set of libraries for developing nice desktop applications.
|
||||
//
|
||||
// For license and copyright information please follow this link:
|
||||
// https://github.com/desktop-app/legal/blob/master/LEGAL
|
||||
//
|
||||
#pragma once
|
||||
|
||||
#include "ui/effects/animations.h"
|
||||
#include "ui/wrap/padding_wrap.h"
|
||||
|
||||
namespace Ui {
|
||||
|
||||
template <typename Widget = RpWidget>
|
||||
class SlideWrap;
|
||||
|
||||
template <>
|
||||
class SlideWrap<RpWidget> : public Wrap<PaddingWrap<RpWidget>> {
|
||||
using Parent = Wrap<PaddingWrap<RpWidget>>;
|
||||
|
||||
public:
|
||||
SlideWrap(
|
||||
QWidget *parent,
|
||||
object_ptr<RpWidget> &&child);
|
||||
SlideWrap(
|
||||
QWidget *parent,
|
||||
const style::margins &padding);
|
||||
SlideWrap(
|
||||
QWidget *parent,
|
||||
object_ptr<RpWidget> &&child,
|
||||
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);
|
||||
}
|
||||
SlideWrap *hide(anim::type animated) {
|
||||
return toggle(false, animated);
|
||||
}
|
||||
SlideWrap *finishAnimating();
|
||||
SlideWrap *toggleOn(
|
||||
rpl::producer<bool> &&shown,
|
||||
anim::type animated = anim::type::normal);
|
||||
|
||||
bool animating() const {
|
||||
return _animation.animating();
|
||||
}
|
||||
bool toggled() const {
|
||||
return _toggled;
|
||||
}
|
||||
auto toggledValue() const {
|
||||
return _toggledChanged.events_starting_with_copy(_toggled);
|
||||
}
|
||||
void setMinimalHeight(int height);
|
||||
|
||||
QMargins getMargins() const override;
|
||||
|
||||
protected:
|
||||
int resizeGetHeight(int newWidth) override;
|
||||
void wrappedSizeUpdated(QSize size) override;
|
||||
|
||||
private:
|
||||
void animationStep();
|
||||
|
||||
rpl::event_stream<bool> _toggledChanged;
|
||||
Animations::Simple _animation;
|
||||
int _duration = 0;
|
||||
bool _toggled = true;
|
||||
bool _up = false;
|
||||
int _minimalHeight = 0;
|
||||
|
||||
};
|
||||
|
||||
template <typename Widget>
|
||||
class SlideWrap : public Wrap<PaddingWrap<Widget>, SlideWrap<RpWidget>> {
|
||||
using Parent = Wrap<PaddingWrap<Widget>, SlideWrap<RpWidget>>;
|
||||
|
||||
public:
|
||||
SlideWrap(
|
||||
QWidget *parent,
|
||||
object_ptr<Widget> &&child)
|
||||
: Parent(parent, std::move(child)) {
|
||||
}
|
||||
SlideWrap(
|
||||
QWidget *parent,
|
||||
const style::margins &padding)
|
||||
: Parent(parent, padding) {
|
||||
}
|
||||
SlideWrap(
|
||||
QWidget *parent,
|
||||
object_ptr<Widget> &&child,
|
||||
const style::margins &padding)
|
||||
: Parent(parent, std::move(child), padding) {
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
SlideWrap *show(anim::type animated) {
|
||||
return chain(Parent::show(animated));
|
||||
}
|
||||
SlideWrap *hide(anim::type animated) {
|
||||
return chain(Parent::hide(animated));
|
||||
}
|
||||
SlideWrap *finishAnimating() {
|
||||
return chain(Parent::finishAnimating());
|
||||
}
|
||||
SlideWrap *toggleOn(
|
||||
rpl::producer<bool> &&shown,
|
||||
anim::type animated = anim::type::normal) {
|
||||
return chain(Parent::toggleOn(std::move(shown), animated));
|
||||
}
|
||||
|
||||
private:
|
||||
SlideWrap *chain(SlideWrap<RpWidget> *result) {
|
||||
return static_cast<SlideWrap*>(result);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
inline object_ptr<SlideWrap<>> CreateSlideSkipWidget(
|
||||
QWidget *parent,
|
||||
int skip) {
|
||||
return object_ptr<SlideWrap<>>(
|
||||
parent,
|
||||
QMargins(0, 0, 0, skip));
|
||||
}
|
||||
|
||||
class MultiSlideTracker {
|
||||
public:
|
||||
template <typename Widget>
|
||||
void track(const SlideWrap<Widget> *wrap) {
|
||||
_widgets.push_back(wrap);
|
||||
_widgetAdded.fire({});
|
||||
}
|
||||
|
||||
rpl::producer<bool> atLeastOneShownValue() const;
|
||||
rpl::producer<bool> atLeastOneShownValueLater() const;
|
||||
|
||||
private:
|
||||
std::vector<const SlideWrap<Ui::RpWidget>*> _widgets;
|
||||
rpl::event_stream<> _widgetAdded;
|
||||
|
||||
};
|
||||
|
||||
} // namespace Ui
|
||||
|
||||
Reference in New Issue
Block a user