mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-08-31 14:38:15 +00:00
Show empty / placeholder in chats search.
This commit is contained in:
82
Telegram/SourceFiles/dialogs/ui/chat_search_empty.cpp
Normal file
82
Telegram/SourceFiles/dialogs/ui/chat_search_empty.cpp
Normal file
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
This file is part of Telegram Desktop,
|
||||
the official desktop application for the Telegram messaging service.
|
||||
|
||||
For license and copyright information please follow this link:
|
||||
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
*/
|
||||
#include "dialogs/ui/chat_search_empty.h"
|
||||
|
||||
#include "base/object_ptr.h"
|
||||
#include "lottie/lottie_icon.h"
|
||||
#include "settings/settings_common.h"
|
||||
#include "ui/widgets/labels.h"
|
||||
#include "styles/style_dialogs.h"
|
||||
|
||||
namespace Dialogs {
|
||||
|
||||
SearchEmpty::SearchEmpty(
|
||||
QWidget *parent,
|
||||
Icon icon,
|
||||
rpl::producer<TextWithEntities> text)
|
||||
: RpWidget(parent) {
|
||||
setup(icon, std::move(text));
|
||||
}
|
||||
|
||||
void SearchEmpty::setMinimalHeight(int minimalHeight) {
|
||||
const auto minimal = st::recentPeersEmptyHeightMin;
|
||||
resize(width(), std::max(minimalHeight, minimal));
|
||||
}
|
||||
|
||||
void SearchEmpty::setup(Icon icon, rpl::producer<TextWithEntities> text) {
|
||||
const auto label = Ui::CreateChild<Ui::FlatLabel>(
|
||||
this,
|
||||
std::move(text),
|
||||
st::defaultPeerListAbout);
|
||||
label->setClickHandlerFilter([=](const auto &, Qt::MouseButton button) {
|
||||
if (button == Qt::LeftButton) {
|
||||
_linkClicks.fire({});
|
||||
}
|
||||
return false;
|
||||
});
|
||||
const auto size = st::recentPeersEmptySize;
|
||||
const auto animation = [&] {
|
||||
switch (icon) {
|
||||
case Icon::Search: return u"search"_q;
|
||||
case Icon::NoResults: return u"noresults"_q;
|
||||
}
|
||||
Unexpected("Icon in SearchEmpty::setup.");
|
||||
}();
|
||||
const auto [widget, animate] = Settings::CreateLottieIcon(
|
||||
this,
|
||||
{
|
||||
.name = animation,
|
||||
.sizeOverride = { size, size },
|
||||
},
|
||||
st::recentPeersEmptyMargin);
|
||||
const auto animated = widget.data();
|
||||
|
||||
sizeValue() | rpl::start_with_next([=](QSize size) {
|
||||
const auto padding = st::recentPeersEmptyMargin;
|
||||
const auto paddings = padding.left() + padding.right();
|
||||
label->resizeToWidth(size.width() - paddings);
|
||||
const auto x = (size.width() - animated->width()) / 2;
|
||||
const auto y = (size.height() - animated->height()) / 3;
|
||||
const auto top = y + animated->height() + st::recentPeersEmptySkip;
|
||||
const auto sub = std::max(top + label->height() - size.height(), 0);
|
||||
animated->move(x, y - sub);
|
||||
label->move((size.width() - label->width()) / 2, top - sub);
|
||||
}, lifetime());
|
||||
|
||||
_animate = [animate] {
|
||||
animate(anim::repeat::once);
|
||||
};
|
||||
}
|
||||
|
||||
void SearchEmpty::animate() {
|
||||
if (const auto onstack = _animate) {
|
||||
onstack();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Dialogs
|
43
Telegram/SourceFiles/dialogs/ui/chat_search_empty.h
Normal file
43
Telegram/SourceFiles/dialogs/ui/chat_search_empty.h
Normal file
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
This file is part of Telegram Desktop,
|
||||
the official desktop application for the Telegram messaging service.
|
||||
|
||||
For license and copyright information please follow this link:
|
||||
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "ui/rp_widget.h"
|
||||
|
||||
namespace Dialogs {
|
||||
|
||||
enum class SearchEmptyIcon {
|
||||
Search,
|
||||
NoResults,
|
||||
};
|
||||
|
||||
class SearchEmpty final : public Ui::RpWidget {
|
||||
public:
|
||||
using Icon = SearchEmptyIcon;
|
||||
|
||||
SearchEmpty(
|
||||
QWidget *parent,
|
||||
Icon icon,
|
||||
rpl::producer<TextWithEntities> text);
|
||||
|
||||
void setMinimalHeight(int minimalHeight);
|
||||
[[nodiscard]] rpl::producer<> linkClicks() const {
|
||||
return _linkClicks.events();
|
||||
}
|
||||
|
||||
void animate();
|
||||
|
||||
private:
|
||||
void setup(Icon icon, rpl::producer<TextWithEntities> text);
|
||||
|
||||
Fn<void()> _animate;
|
||||
rpl::event_stream<> _linkClicks;
|
||||
|
||||
};
|
||||
|
||||
} // namespace Dialogs
|
@@ -20,12 +20,13 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "data/data_peer_values.h"
|
||||
#include "data/data_session.h"
|
||||
#include "data/data_user.h"
|
||||
#include "dialogs/ui/chat_search_empty.h"
|
||||
#include "history/history.h"
|
||||
#include "lang/lang_keys.h"
|
||||
#include "lottie/lottie_icon.h"
|
||||
#include "main/main_session.h"
|
||||
#include "settings/settings_common.h"
|
||||
#include "ui/boxes/confirm_box.h"
|
||||
#include "ui/text/text_utilities.h"
|
||||
#include "ui/widgets/menu/menu_add_action_callback_factory.h"
|
||||
#include "ui/widgets/buttons.h"
|
||||
#include "ui/widgets/discrete_sliders.h"
|
||||
@@ -1360,53 +1361,30 @@ object_ptr<Ui::SlideWrap<>> Suggestions::setupRecentPeers(
|
||||
}
|
||||
|
||||
object_ptr<Ui::SlideWrap<>> Suggestions::setupEmptyRecent() {
|
||||
return setupEmpty(_chatsContent, "search", tr::lng_recent_none());
|
||||
const auto icon = SearchEmptyIcon::Search;
|
||||
return setupEmpty(_chatsContent, icon, tr::lng_recent_none());
|
||||
}
|
||||
|
||||
object_ptr<Ui::SlideWrap<>> Suggestions::setupEmptyChannels() {
|
||||
return setupEmpty(
|
||||
_channelsContent,
|
||||
"noresults",
|
||||
tr::lng_channels_none_about());
|
||||
const auto icon = SearchEmptyIcon::NoResults;
|
||||
return setupEmpty(_channelsContent, icon, tr::lng_channels_none_about());
|
||||
}
|
||||
|
||||
object_ptr<Ui::SlideWrap<>> Suggestions::setupEmpty(
|
||||
not_null<QWidget*> parent,
|
||||
const QString &animation,
|
||||
SearchEmptyIcon icon,
|
||||
rpl::producer<QString> text) {
|
||||
auto content = object_ptr<Ui::RpWidget>(parent);
|
||||
auto content = object_ptr<SearchEmpty>(
|
||||
parent,
|
||||
icon,
|
||||
std::move(text) | Ui::Text::ToWithEntities());
|
||||
|
||||
const auto raw = content.data();
|
||||
|
||||
const auto label = Ui::CreateChild<Ui::FlatLabel>(
|
||||
raw,
|
||||
std::move(text),
|
||||
st::defaultPeerListAbout);
|
||||
const auto size = st::recentPeersEmptySize;
|
||||
const auto [widget, animate] = Settings::CreateLottieIcon(
|
||||
raw,
|
||||
{
|
||||
.name = animation,
|
||||
.sizeOverride = { size, size },
|
||||
},
|
||||
st::recentPeersEmptyMargin);
|
||||
const auto icon = widget.data();
|
||||
|
||||
rpl::combine(
|
||||
_chatsScroll->heightValue(),
|
||||
_topPeersWrap->heightValue()
|
||||
) | rpl::start_with_next([=](int height, int top) {
|
||||
raw->resize(
|
||||
raw->width(),
|
||||
std::max(height - top, st::recentPeersEmptyHeightMin));
|
||||
}, raw->lifetime());
|
||||
|
||||
raw->sizeValue() | rpl::start_with_next([=](QSize size) {
|
||||
const auto x = (size.width() - icon->width()) / 2;
|
||||
const auto y = (size.height() - icon->height()) / 3;
|
||||
icon->move(x, y);
|
||||
label->move(
|
||||
(size.width() - label->width()) / 2,
|
||||
y + icon->height() + st::recentPeersEmptySkip);
|
||||
raw->setMinimalHeight(height - top);
|
||||
}, raw->lifetime());
|
||||
|
||||
auto result = object_ptr<Ui::SlideWrap<>>(
|
||||
@@ -1417,7 +1395,7 @@ object_ptr<Ui::SlideWrap<>> Suggestions::setupEmpty(
|
||||
result->toggledValue() | rpl::filter([=](bool shown) {
|
||||
return shown && _controller->session().data().chatsListLoaded();
|
||||
}) | rpl::start_with_next([=] {
|
||||
animate(anim::repeat::once);
|
||||
raw->animate();
|
||||
}, raw->lifetime());
|
||||
|
||||
return result;
|
||||
|
@@ -34,6 +34,8 @@ class SessionController;
|
||||
|
||||
namespace Dialogs {
|
||||
|
||||
enum class SearchEmptyIcon;
|
||||
|
||||
struct RecentPeersList {
|
||||
std::vector<not_null<PeerData*>> list;
|
||||
};
|
||||
@@ -112,7 +114,7 @@ private:
|
||||
-> object_ptr<Ui::SlideWrap<Ui::RpWidget>>;
|
||||
[[nodiscard]] object_ptr<Ui::SlideWrap<Ui::RpWidget>> setupEmpty(
|
||||
not_null<QWidget*> parent,
|
||||
const QString &animation,
|
||||
SearchEmptyIcon icon,
|
||||
rpl::producer<QString> text);
|
||||
|
||||
void switchTab(Tab tab);
|
||||
|
Reference in New Issue
Block a user