Fix glitch in Settings > Premium layer scroll-to-bottom.

This commit is contained in:
John Preston 2022-05-23 12:04:31 +04:00
parent 3c5267f307
commit e72ca712ec
10 changed files with 73 additions and 17 deletions

View file

@ -113,7 +113,7 @@ private:
style::color _bg; style::color _bg;
rpl::variable<int> _scrollTopSkip = -1; rpl::variable<int> _scrollTopSkip = -1;
rpl::variable<int> _scrollBottomSkip = -1; rpl::variable<int> _scrollBottomSkip = 0;
rpl::event_stream<int> _scrollTillBottomChanges; rpl::event_stream<int> _scrollTillBottomChanges;
object_ptr<Ui::ScrollArea> _scroll; object_ptr<Ui::ScrollArea> _scroll;
Ui::PaddingWrap<Ui::RpWidget> *_innerWrap = nullptr; Ui::PaddingWrap<Ui::RpWidget> *_innerWrap = nullptr;

View file

@ -299,9 +299,13 @@ QRect LayerWidget::countGeometry(int newWidth) {
contentHeight += additionalScroll; contentHeight += additionalScroll;
_tillBottom = (newTop + desiredHeight >= windowHeight); _tillBottom = (newTop + desiredHeight >= windowHeight);
if (_tillBottom) { if (_tillBottom) {
contentHeight += contentBottom;
additionalScroll += contentBottom; additionalScroll += contentBottom;
} }
_contentTillBottom = _tillBottom && !_content->scrollBottomSkip();
if (_contentTillBottom) {
contentHeight += contentBottom;
}
const auto bottomPadding = _tillBottom ? 0 : contentBottom;
_content->updateGeometry({ _content->updateGeometry({
contentLeft, contentLeft,
contentTop, contentTop,
@ -328,6 +332,8 @@ void LayerWidget::paintEvent(QPaintEvent *e) {
if (clip.intersects({ 0, height() - radius, width(), radius })) { if (clip.intersects({ 0, height() - radius, width(), radius })) {
parts |= RectPart::FullBottom; parts |= RectPart::FullBottom;
} }
} else if (!_contentTillBottom) {
p.fillRect(0, height() - radius, width(), radius, st::boxBg);
} }
if (_content->animatingShow()) { if (_content->animatingShow()) {
if (clip.intersects({ 0, 0, width(), radius })) { if (clip.intersects({ 0, 0, width(), radius })) {

View file

@ -83,6 +83,7 @@ private:
bool _inResize = false; bool _inResize = false;
bool _pendingResize = false; bool _pendingResize = false;
bool _tillBottom = false; bool _tillBottom = false;
bool _contentTillBottom = false;
bool _floatPlayerDelegateRestored = false; bool _floatPlayerDelegateRestored = false;

View file

@ -16,6 +16,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "info/info_layer_widget.h" #include "info/info_layer_widget.h"
#include "info/info_memento.h" #include "info/info_memento.h"
#include "info/info_controller.h" #include "info/info_controller.h"
#include "styles/style_layers.h"
namespace Info { namespace Info {
@ -42,11 +43,15 @@ SectionWidget::SectionWidget(
void SectionWidget::init() { void SectionWidget::init() {
Expects(_connecting == nullptr); Expects(_connecting == nullptr);
sizeValue( rpl::combine(
) | rpl::start_with_next([wrap = _content.data()](QSize size) { sizeValue(),
_content->desiredHeightValue()
) | rpl::start_with_next([wrap = _content.data()](QSize size, int) {
const auto expanding = false; const auto expanding = false;
auto wrapGeometry = QRect{ { 0, 0 }, size }; const auto additionalScroll = st::boxRadius;
auto additionalScroll = 0; const auto full = !wrap->scrollBottomSkip();
const auto height = size.height() - (full ? 0 : st::boxRadius);
const auto wrapGeometry = QRect{ 0, 0, size.width(), height };
wrap->updateGeometry(wrapGeometry, expanding, additionalScroll); wrap->updateGeometry(wrapGeometry, expanding, additionalScroll);
}, _content->lifetime()); }, _content->lifetime());
@ -88,6 +93,13 @@ void SectionWidget::showAnimatedHook(
_topBarSurrogate = _content->createTopBarSurrogate(this); _topBarSurrogate = _content->createTopBarSurrogate(this);
} }
void SectionWidget::paintEvent(QPaintEvent *e) {
Window::SectionWidget::paintEvent(e);
if (!animatingShow()) {
QPainter(this).fillRect(e->rect(), st::windowBg);
}
}
bool SectionWidget::showInternal( bool SectionWidget::showInternal(
not_null<Window::SectionMemento*> memento, not_null<Window::SectionMemento*> memento,
const Window::SectionShow &params) { const Window::SectionShow &params) {

View file

@ -63,6 +63,7 @@ protected:
void showAnimatedHook( void showAnimatedHook(
const Window::SectionSlideParams &params) override; const Window::SectionSlideParams &params) override;
void paintEvent(QPaintEvent *e) override;
private: private:
void init(); void init();

View file

@ -645,8 +645,8 @@ void WrapWidget::showContent(object_ptr<ContentWidget> content) {
old->setParent(nullptr); old->setParent(nullptr);
old.destroy(); old.destroy();
} }
_content->show();
_additionalScroll = 0; _additionalScroll = 0;
_content->show();
//_anotherTabMemento = nullptr; //_anotherTabMemento = nullptr;
finishShowContent(); finishShowContent();
} }
@ -1098,6 +1098,10 @@ int WrapWidget::scrollTillBottom(int forHeight) const {
return _content->scrollTillBottom(forHeight - topWidget()->height()); return _content->scrollTillBottom(forHeight - topWidget()->height());
} }
int WrapWidget::scrollBottomSkip() const {
return _content->scrollBottomSkip();
}
rpl::producer<int> WrapWidget::scrollTillBottomChanges() const { rpl::producer<int> WrapWidget::scrollTillBottomChanges() const {
return _scrollTillBottomChanges.events_starting_with( return _scrollTillBottomChanges.events_starting_with(
_content->scrollTillBottomChanges() _content->scrollTillBottomChanges()

View file

@ -125,6 +125,7 @@ public:
QRect newGeometry, QRect newGeometry,
bool expanding, bool expanding,
int additionalScroll); int additionalScroll);
[[nodiscard]] int scrollBottomSkip() const;
[[nodiscard]] int scrollTillBottom(int forHeight) const; [[nodiscard]] int scrollTillBottom(int forHeight) const;
[[nodiscard]] rpl::producer<int> scrollTillBottomChanges() const; [[nodiscard]] rpl::producer<int> scrollTillBottomChanges() const;
[[nodiscard]] rpl::producer<bool> grabbingForExpanding() const; [[nodiscard]] rpl::producer<bool> grabbingForExpanding() const;

View file

@ -422,5 +422,5 @@ notifyPreviewChecksSkip: 12px;
notifyPreviewBottomSkip: 9px; notifyPreviewBottomSkip: 9px;
settingsPremiumDescriptionSkip: 3px; settingsPremiumDescriptionSkip: 3px;
settingsPremiumButtonPadding: margins(11px, 11px, 11px, 11px); settingsPremiumButtonPadding: margins(11px, 11px, 11px, 3px);

View file

@ -12,7 +12,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "settings/settings_premium.h" #include "settings/settings_premium.h"
#include "core/application.h" #include "core/application.h"
#include "ui/abstract_button.h" #include "ui/abstract_button.h"
#include "ui/basic_click_handlers.h"
#include "ui/effects/gradient.h" #include "ui/effects/gradient.h"
#include "ui/effects/premium_graphics.h"
#include "ui/text/text_utilities.h" #include "ui/text/text_utilities.h"
#include "ui/widgets/gradient_round_button.h" #include "ui/widgets/gradient_round_button.h"
#include "ui/widgets/labels.h" #include "ui/widgets/labels.h"
@ -21,6 +23,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "window/window_session_controller.h" #include "window/window_session_controller.h"
#include "window/window_controller.h" #include "window/window_controller.h"
#include "main/main_session.h" #include "main/main_session.h"
#include "main/main_account.h"
#include "main/main_app_config.h"
#include "styles/style_boxes.h" #include "styles/style_boxes.h"
#include "styles/style_chat_helpers.h" #include "styles/style_chat_helpers.h"
#include "styles/style_layers.h" #include "styles/style_layers.h"
@ -41,22 +45,25 @@ public:
not_null<Ui::RpWidget*> parent) override; not_null<Ui::RpWidget*> parent) override;
private: private:
void setupContent(not_null<Window::SessionController*> controller); void setupContent();
const not_null<Window::SessionController*> _controller;
}; };
Premium::Premium( Premium::Premium(
QWidget *parent, QWidget *parent,
not_null<Window::SessionController*> controller) not_null<Window::SessionController*> controller)
: Section(parent) { : Section(parent)
setupContent(controller); , _controller(controller) {
setupContent();
} }
rpl::producer<QString> Premium::title() { rpl::producer<QString> Premium::title() {
return tr::lng_premium_summary_title(); return tr::lng_premium_summary_title();
} }
void Premium::setupContent(not_null<Window::SessionController*> controller) { void Premium::setupContent() {
const auto content = Ui::CreateChild<Ui::VerticalLayout>(this); const auto content = Ui::CreateChild<Ui::VerticalLayout>(this);
content->add( content->add(
@ -221,11 +228,11 @@ QPointer<Ui::RpWidget> Premium::createPinnedToBottom(
auto result = object_ptr<Ui::GradientButton>( auto result = object_ptr<Ui::GradientButton>(
content, content,
QGradientStops{ Ui::Premium::ButtonGradientStops());
{ 0., st::premiumButtonBg1->c },
{ .6, st::premiumButtonBg2->c }, result->setClickedCallback([=] {
{ 1., st::premiumButtonBg3->c }, StartPremiumPayment(_controller, "settings");
}); });
const auto &st = st::premiumPreviewBox.button; const auto &st = st::premiumPreviewBox.button;
result->resize(content->width(), st.height); result->resize(content->width(), st.height);
@ -271,4 +278,21 @@ void ShowPremium(not_null<Main::Session*> session) {
} }
} }
void StartPremiumPayment(
not_null<Window::SessionController*> controller,
const QString &ref) {
const auto account = &controller->session().account();
const auto username = account->appConfig().get<QString>(
"premium_bot_username",
QString());
const auto slug = account->appConfig().get<QString>(
"premium_invoice_slug",
QString());
if (!username.isEmpty()) {
UrlClickHandler::Open("https://t.me/" + username + "?start=" + ref);
} else if (!slug.isEmpty()) {
UrlClickHandler::Open("https://t.me/$" + slug);
}
}
} // namespace Settings } // namespace Settings

View file

@ -13,11 +13,18 @@ namespace Main {
class Session; class Session;
} // namespace Main } // namespace Main
namespace Window {
class SessionController;
} // namespace Window
namespace Settings { namespace Settings {
[[nodiscard]] Type PremiumId(); [[nodiscard]] Type PremiumId();
void ShowPremium(not_null<::Main::Session*> session); void ShowPremium(not_null<::Main::Session*> session);
void StartPremiumPayment(
not_null<Window::SessionController*> controller,
const QString &ref);
} // namespace Settings } // namespace Settings