From 1cc3440fccc7112486a31038e1876a0e777000dd Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Wed, 30 Nov 2022 17:08:49 +0300 Subject: [PATCH] Added new loading element animation for peer list. --- .../ui/effects/loading_element.cpp | 97 +++++++++++++++++-- .../SourceFiles/ui/effects/loading_element.h | 6 ++ 2 files changed, 93 insertions(+), 10 deletions(-) diff --git a/Telegram/SourceFiles/ui/effects/loading_element.cpp b/Telegram/SourceFiles/ui/effects/loading_element.cpp index 67de701cf..6ff648cb4 100644 --- a/Telegram/SourceFiles/ui/effects/loading_element.cpp +++ b/Telegram/SourceFiles/ui/effects/loading_element.cpp @@ -10,12 +10,12 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/effects/glare.h" #include "base/object_ptr.h" -#include "styles/palette.h" -#include "styles/style_basic.h" -#include "styles/style_widgets.h" #include "base/random.h" +#include "styles/palette.h" #include "ui/painter.h" #include "ui/rp_widget.h" +#include "styles/style_basic.h" +#include "styles/style_widgets.h" namespace Ui { namespace { @@ -52,7 +52,7 @@ void LoadingText::paint(QPainter &p, int width) { p.setPen(Qt::NoPen); - p.setBrush(st::dialogsDateFg); + p.setBrush(st::windowBgOver); const auto h = _st.style.font->ascent; p.drawRoundedRect( 0, @@ -63,13 +63,63 @@ void LoadingText::paint(QPainter &p, int width) { h / 2); } -} // namespace +class LoadingPeerListItem final : public LoadingElement { +public: + LoadingPeerListItem(const style::PeerListItem &st) : _st(st) { + } -object_ptr CreateLoadingTextWidget( + [[nodiscard]] int height() const override { + return _st.height; + } + void paint(QPainter &p, int width) override { + auto hq = PainterHighQualityEnabler(p); + + const auto &style = _st.nameStyle; + const auto offset = -style.font->ascent + - (style.lineHeight - style.font->height); + + p.setPen(Qt::NoPen); + p.setBrush(st::windowBgOver); + + p.drawEllipse( + _st.photoPosition.x(), + _st.photoPosition.y(), + _st.photoSize, + _st.photoSize); + + constexpr auto kNameWidth = 60; + constexpr auto kStatusWidth = 100; + + const auto h1 = st::semiboldTextStyle.font->ascent; + p.drawRoundedRect( + _st.namePosition.x(), + _st.namePosition.y() + offset, + kNameWidth, + h1, + h1 / 2, + h1 / 2); + + const auto h2 = st::defaultTextStyle.font->ascent; + p.drawRoundedRect( + _st.statusPosition.x(), + _st.statusPosition.y() + offset, + kStatusWidth, + h2, + h2 / 2, + h2 / 2); + } + +private: + const style::PeerListItem &_st; + +}; + +template +object_ptr CreateLoadingElementWidget( not_null parent, - const style::FlatLabel &st, int lines, - rpl::producer rtl) { + rpl::producer rtl, + ElementArgs &&...args) { auto widget = object_ptr(parent); const auto raw = widget.data(); @@ -84,10 +134,12 @@ object_ptr CreateLoadingTextWidget( state->rtl = std::move(rtl); state->rtl.value( ) | rpl::start_with_next([=] { raw->update(); }, raw->lifetime()); - raw->resize(raw->width(), LoadingText(st).height() * lines); + raw->resize( + raw->width(), + Element(std::forward(args)...).height() * lines); const auto draw = [=](QPainter &p) { - auto loading = LoadingText(st); + auto loading = Element(std::forward(args)...); const auto countRows = lines; for (auto i = 0; i < countRows; i++) { const auto w = (i == countRows - 1) @@ -139,4 +191,29 @@ object_ptr CreateLoadingTextWidget( return widget; } +} // namespace + +object_ptr CreateLoadingTextWidget( + not_null parent, + const style::FlatLabel &st, + int lines, + rpl::producer rtl) { + return CreateLoadingElementWidget( + parent, + lines, + std::move(rtl), + st); +} + +object_ptr CreateLoadingPeerListItemWidget( + not_null parent, + const style::PeerListItem &st, + int lines) { + return CreateLoadingElementWidget( + parent, + lines, + rpl::single(false), + st); +} + } // namespace Ui diff --git a/Telegram/SourceFiles/ui/effects/loading_element.h b/Telegram/SourceFiles/ui/effects/loading_element.h index ec2264859..ab3b0d17e 100644 --- a/Telegram/SourceFiles/ui/effects/loading_element.h +++ b/Telegram/SourceFiles/ui/effects/loading_element.h @@ -12,6 +12,7 @@ class object_ptr; namespace style { struct FlatLabel; +struct PeerListItem; } // namespace style namespace Ui { @@ -24,4 +25,9 @@ object_ptr CreateLoadingTextWidget( int lines, rpl::producer rtl); +object_ptr CreateLoadingPeerListItemWidget( + not_null parent, + const style::PeerListItem &st, + int lines); + } // namespace Ui