mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-03 21:54:05 +02:00
Added ability to switch tabs in dialogs suggestions with swipe.
This commit is contained in:
parent
4e4c69993c
commit
9a439e1941
2 changed files with 78 additions and 0 deletions
|
@ -36,6 +36,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "settings/settings_common.h"
|
||||
#include "storage/storage_shared_media.h"
|
||||
#include "ui/boxes/confirm_box.h"
|
||||
#include "ui/controls/swipe_handler.h"
|
||||
#include "ui/effects/ripple_animation.h"
|
||||
#include "ui/text/text_utilities.h"
|
||||
#include "ui/widgets/menu/menu_add_action_callback_factory.h"
|
||||
|
@ -1552,6 +1553,61 @@ void Suggestions::setupApps() {
|
|||
});
|
||||
}
|
||||
|
||||
Ui::Controls::SwipeHandlerArgs Suggestions::generateIncompleteSwipeArgs() {
|
||||
_swipeLifetime.destroy();
|
||||
|
||||
auto update = [=](Ui::Controls::SwipeContextData data) {
|
||||
if (data.translation != 0) {
|
||||
if (!_swipeBackData.callback) {
|
||||
_swipeBackData = Ui::Controls::SetupSwipeBack(
|
||||
this,
|
||||
[=]() -> std::pair<QColor, QColor> {
|
||||
return {
|
||||
st::historyForwardChooseBg->c,
|
||||
st::historyForwardChooseFg->c,
|
||||
};
|
||||
},
|
||||
data.translation < 0);
|
||||
}
|
||||
_swipeBackData.callback(data);
|
||||
return;
|
||||
} else if (_swipeBackData.lifetime) {
|
||||
_swipeBackData = {};
|
||||
}
|
||||
};
|
||||
auto init = [=](int, Qt::LayoutDirection direction) {
|
||||
if (!_tabs) {
|
||||
return Ui::Controls::SwipeHandlerFinishData();
|
||||
}
|
||||
const auto activeSection = _tabs->activeSection();
|
||||
const auto isToLeft = direction == Qt::RightToLeft;
|
||||
if ((isToLeft && activeSection > 0)
|
||||
|| (!isToLeft && activeSection < _tabKeys.size() - 1)) {
|
||||
return Ui::Controls::DefaultSwipeBackHandlerFinishData([=] {
|
||||
if (_tabs
|
||||
&& _tabs->activeSection() == activeSection) {
|
||||
_swipeBackData = {};
|
||||
_tabs->setActiveSection(isToLeft
|
||||
? activeSection - 1
|
||||
: activeSection + 1);
|
||||
}
|
||||
});
|
||||
}
|
||||
return Ui::Controls::SwipeHandlerFinishData();
|
||||
};
|
||||
return { .widget = this, .update = update, .init = init };
|
||||
}
|
||||
|
||||
void Suggestions::reinstallSwipe(not_null<Ui::ElasticScroll*> scroll) {
|
||||
_swipeLifetime.destroy();
|
||||
|
||||
auto args = generateIncompleteSwipeArgs();
|
||||
args.scroll = scroll;
|
||||
args.onLifetime = &_swipeLifetime;
|
||||
|
||||
Ui::Controls::SetupSwipeHandler(std::move(args));
|
||||
}
|
||||
|
||||
void Suggestions::selectJump(Qt::Key direction, int pageSize) {
|
||||
switch (_key.current().tab) {
|
||||
case Tab::Chats: selectJumpChats(direction, pageSize); return;
|
||||
|
@ -1977,6 +2033,18 @@ void Suggestions::finishShow() {
|
|||
_appsScroll->setVisible(key == Key{ Tab::Apps });
|
||||
for (const auto &[mediaKey, list] : _mediaLists) {
|
||||
list.wrap->setVisible(key == mediaKey);
|
||||
if (key == mediaKey) {
|
||||
_swipeLifetime.destroy();
|
||||
auto incomplete = generateIncompleteSwipeArgs();
|
||||
list.wrap->replaceSwipeHandler(&incomplete);
|
||||
}
|
||||
}
|
||||
if (key == Key{ Tab::Chats }) {
|
||||
reinstallSwipe(_chatsScroll.get());
|
||||
} else if (key == Key{ Tab::Channels }) {
|
||||
reinstallSwipe(_channelsScroll.get());
|
||||
} else if (key == Key{ Tab::Apps }) {
|
||||
reinstallSwipe(_appsScroll.get());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "base/object_ptr.h"
|
||||
#include "base/timer.h"
|
||||
#include "dialogs/ui/top_peers_strip.h"
|
||||
#include "ui/controls/swipe_handler_data.h"
|
||||
#include "ui/effects/animations.h"
|
||||
#include "ui/rp_widget.h"
|
||||
|
||||
|
@ -32,6 +33,9 @@ enum class SharedMediaType : signed char;
|
|||
} // namespace Storage
|
||||
|
||||
namespace Ui {
|
||||
namespace Controls {
|
||||
struct SwipeHandlerArgs;
|
||||
} // namespace Controls
|
||||
class BoxContent;
|
||||
class ScrollArea;
|
||||
class ElasticScroll;
|
||||
|
@ -157,6 +161,9 @@ private:
|
|||
void setupChats();
|
||||
void setupChannels();
|
||||
void setupApps();
|
||||
void reinstallSwipe(not_null<Ui::ElasticScroll*>);
|
||||
[[nodiscard]] auto generateIncompleteSwipeArgs()
|
||||
-> Ui::Controls::SwipeHandlerArgs;
|
||||
|
||||
void selectJumpChats(Qt::Key direction, int pageSize);
|
||||
void selectJumpChannels(Qt::Key direction, int pageSize);
|
||||
|
@ -253,6 +260,9 @@ private:
|
|||
QPixmap _slideLeft;
|
||||
QPixmap _slideRight;
|
||||
|
||||
Ui::Controls::SwipeBackResult _swipeBackData;
|
||||
rpl::lifetime _swipeLifetime;
|
||||
|
||||
int _slideLeftTop = 0;
|
||||
int _slideRightTop = 0;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue