Moved out setup of top and bottom scroll shadows to separated file.

This commit is contained in:
23rd 2022-04-13 13:22:10 +03:00
parent dad2ad2eb8
commit 2f8efb5ce6
12 changed files with 84 additions and 136 deletions

View File

@ -37,13 +37,13 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/chat/attach/attach_single_file_preview.h"
#include "ui/chat/attach/attach_single_media_preview.h"
#include "ui/controls/emoji_button.h"
#include "ui/effects/scroll_content_shadow.h"
#include "ui/image/image.h"
#include "ui/toast/toast.h"
#include "ui/ui_utility.h"
#include "ui/widgets/checkbox.h"
#include "ui/widgets/input_fields.h"
#include "ui/widgets/scroll_area.h"
#include "ui/wrap/fade_wrap.h"
#include "ui/wrap/slide_wrap.h"
#include "ui/wrap/vertical_layout.h"
#include "window/window_session_controller.h"
@ -125,9 +125,7 @@ EditCaptionBox::EditCaptionBox(
PrepareEditText(item)))
, _emojiToggle(base::make_unique_q<Ui::EmojiButton>(
this,
st::boxAttachEmoji))
, _topShadow(base::make_unique_q<Ui::FadeShadow>(this))
, _bottomShadow(base::make_unique_q<Ui::FadeShadow>(this)) {
st::boxAttachEmoji)) {
Expects(item->media() != nullptr);
Expects(item->media()->allowsEditCaption());
@ -151,7 +149,7 @@ void EditCaptionBox::prepare() {
rebuildPreview();
setupEditEventHandler();
setupShadows();
SetupShadowsToScrollContent(this, _scroll, _contentHeight.events());
setupControls();
setupPhotoEditorEventHandler();
@ -282,31 +280,6 @@ void EditCaptionBox::setupField() {
_field->setTextCursor(cursor);
}
void EditCaptionBox::setupShadows() {
using namespace rpl::mappers;
const auto _topShadow = Ui::CreateChild<Ui::FadeShadow>(this);
const auto _bottomShadow = Ui::CreateChild<Ui::FadeShadow>(this);
_scroll->geometryValue(
) | rpl::start_with_next([=](const QRect &geometry) {
_topShadow->resizeToWidth(geometry.width());
_topShadow->move(
geometry.x(),
geometry.y());
_bottomShadow->resizeToWidth(geometry.width());
_bottomShadow->move(
geometry.x(),
geometry.y() + geometry.height() - st::lineWidth);
}, _topShadow->lifetime());
_topShadow->toggleOn(_scroll->scrollTopValue() | rpl::map(_1 > 0));
_bottomShadow->toggleOn(rpl::combine(
_scroll->scrollTopValue(),
_scroll->heightValue(),
_contentHeight.events(),
_1 + _2 < _3));
}
void EditCaptionBox::setupControls() {
auto hintLabelToggleOn = _previewRebuilds.events_starting_with(
{}

View File

@ -27,7 +27,6 @@ class AbstractSinglePreview;
class InputField;
class EmojiButton;
class VerticalLayout;
class FadeShadow;
enum class AlbumType;
} // namespace Ui
@ -51,7 +50,6 @@ private:
void rebuildPreview();
void setupEditEventHandler();
void setupPhotoEditorEventHandler();
void setupShadows();
void setupField();
void setupControls();
@ -81,7 +79,6 @@ private:
const base::unique_qptr<Ui::ScrollArea> _scroll;
const base::unique_qptr<Ui::InputField> _field;
const base::unique_qptr<Ui::EmojiButton> _emojiToggle;
const base::unique_qptr<Ui::FadeShadow> _topShadow, _bottomShadow;
base::unique_qptr<Ui::AbstractSinglePreview> _content;
base::unique_qptr<ChatHelpers::TabbedPanel> _emojiPanel;

View File

@ -23,11 +23,11 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "settings/settings_common.h"
#include "ui/chat/chat_style.h"
#include "ui/chat/chat_theme.h"
#include "ui/effects/scroll_content_shadow.h"
#include "ui/layers/generic_box.h"
#include "ui/widgets/buttons.h"
#include "ui/widgets/labels.h"
#include "ui/widgets/scroll_area.h"
#include "ui/wrap/fade_wrap.h"
#include "ui/wrap/vertical_layout.h"
#include "window/section_widget.h"
#include "window/window_session_controller.h"
@ -373,37 +373,6 @@ void AddMessage(
}, widget->lifetime());
}
void SetupShadows(
not_null<Ui::RpWidget*> parent,
not_null<Ui::ScrollArea*> scroll,
not_null<Ui::RpWidget*> inner) {
using namespace rpl::mappers;
const auto topShadow = Ui::CreateChild<Ui::FadeShadow>(parent.get());
const auto bottomShadow = Ui::CreateChild<Ui::FadeShadow>(parent.get());
scroll->geometryValue(
) | rpl::start_with_next_done([=](const QRect &geometry) {
topShadow->resizeToWidth(geometry.width());
topShadow->move(
geometry.x(),
geometry.y());
bottomShadow->resizeToWidth(geometry.width());
bottomShadow->move(
geometry.x(),
geometry.y() + geometry.height() - st::lineWidth);
}, [t = Ui::MakeWeak(topShadow), b = Ui::MakeWeak(bottomShadow)] {
Ui::DestroyChild(t.data());
Ui::DestroyChild(b.data());
}, topShadow->lifetime());
topShadow->toggleOn(scroll->scrollTopValue() | rpl::map(_1 > 0));
bottomShadow->toggleOn(rpl::combine(
scroll->scrollTopValue(),
scroll->heightValue(),
inner->heightValue(),
_1 + _2 < _3));
}
} // namespace
void ReactionsSettingsBox(
@ -503,7 +472,10 @@ void ReactionsSettingsBox(
}
check->raise();
SetupShadows(scrollContainer, scroll, buttonsContainer);
Ui::SetupShadowsToScrollContent(
scrollContainer,
scroll,
buttonsContainer->heightValue());
box->setTitle(tr::lng_settings_chat_reactions_title());
box->setWidth(st::boxWideWidth);

View File

@ -26,11 +26,11 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "core/mime_type.h"
#include "base/event_filter.h"
#include "ui/effects/animations.h"
#include "ui/effects/scroll_content_shadow.h"
#include "ui/widgets/checkbox.h"
#include "ui/widgets/buttons.h"
#include "ui/widgets/input_fields.h"
#include "ui/widgets/scroll_area.h"
#include "ui/wrap/fade_wrap.h"
#include "ui/wrap/vertical_layout.h"
#include "ui/chat/attach/attach_prepare.h"
#include "ui/chat/attach/attach_send_files_way.h"
@ -312,34 +312,6 @@ void SendFilesBox::enqueueNextPrepare() {
});
}
void SendFilesBox::setupShadows() {
using namespace rpl::mappers;
const auto topShadow = Ui::CreateChild<Ui::FadeShadow>(this);
const auto bottomShadow = Ui::CreateChild<Ui::FadeShadow>(this);
_scroll->geometryValue(
) | rpl::start_with_next_done([=](const QRect &geometry) {
topShadow->resizeToWidth(geometry.width());
topShadow->move(
geometry.x(),
geometry.y());
bottomShadow->resizeToWidth(geometry.width());
bottomShadow->move(
geometry.x(),
geometry.y() + geometry.height() - st::lineWidth);
}, [t = Ui::MakeWeak(topShadow), b = Ui::MakeWeak(bottomShadow)] {
Ui::DestroyChild(t.data());
Ui::DestroyChild(b.data());
}, topShadow->lifetime());
topShadow->toggleOn(_scroll->scrollTopValue() | rpl::map(_1 > 0));
bottomShadow->toggleOn(rpl::combine(
_scroll->scrollTopValue(),
_scroll->heightValue(),
_inner->heightValue(),
_1 + _2 < _3));
}
void SendFilesBox::prepare() {
_send = addButton(
(_sendType == Api::SendType::Normal
@ -359,7 +331,7 @@ void SendFilesBox::prepare() {
setupSendWayControls();
preparePreview();
initPreview();
setupShadows();
SetupShadowsToScrollContent(this, _scroll, _inner->heightValue());
boxClosing() | rpl::start_with_next([=] {
if (!_confirmed && _cancelledCallback) {

View File

@ -123,7 +123,6 @@ private:
void refreshControls();
void setupSendWayControls();
void setupCaption();
void setupShadows();
void setupEmojiPanel();
void updateSendWayControlsVisibility();

View File

@ -10,11 +10,11 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "passport/passport_panel_controller.h"
#include "passport/passport_panel_edit_scans.h"
#include "passport/ui/passport_details_row.h"
#include "ui/effects/scroll_content_shadow.h"
#include "ui/widgets/input_fields.h"
#include "ui/widgets/scroll_area.h"
#include "ui/widgets/labels.h"
#include "ui/widgets/buttons.h"
#include "ui/widgets/shadow.h"
#include "ui/widgets/checkbox.h"
#include "ui/wrap/vertical_layout.h"
#include "ui/wrap/fade_wrap.h"
@ -219,8 +219,6 @@ PanelEditDocument::PanelEditDocument(
: _controller(controller)
, _scheme(std::move(scheme))
, _scroll(this, st::passportPanelScroll)
, _topShadow(this)
, _bottomShadow(this)
, _done(
this,
tr::lng_passport_save_value(),
@ -247,8 +245,6 @@ PanelEditDocument::PanelEditDocument(
: _controller(controller)
, _scheme(std::move(scheme))
, _scroll(this, st::passportPanelScroll)
, _topShadow(this)
, _bottomShadow(this)
, _done(
this,
tr::lng_passport_save_value(),
@ -272,8 +268,6 @@ PanelEditDocument::PanelEditDocument(
: _controller(controller)
, _scheme(std::move(scheme))
, _scroll(this, st::passportPanelScroll)
, _topShadow(this)
, _bottomShadow(this)
, _done(
this,
tr::lng_passport_save_value(),
@ -289,7 +283,7 @@ void PanelEditDocument::setupControls(
ScanListData &&scans,
std::optional<ScanListData> &&translations,
std::map<FileType, ScanInfo> &&specialFiles) {
setupContent(
const auto inner = setupContent(
error,
data,
scansError,
@ -298,10 +292,8 @@ void PanelEditDocument::setupControls(
std::move(translations),
std::move(specialFiles));
using namespace rpl::mappers;
Ui::SetupShadowsToScrollContent(this, _scroll, inner->heightValue());
_topShadow->toggleOn(
_scroll->scrollTopValue() | rpl::map(_1 > 0));
_done->addClickHandler([=] {
crl::on_main(this, [=] {
save();
@ -604,10 +596,6 @@ bool PanelEditDocument::hasUnsavedChanges() const {
void PanelEditDocument::updateControlsGeometry() {
const auto submitTop = height() - _done->height();
_scroll->setGeometry(0, 0, width(), submitTop);
_topShadow->resizeToWidth(width());
_topShadow->moveToLeft(0, 0);
_bottomShadow->resizeToWidth(width());
_bottomShadow->moveToLeft(0, submitTop - st::lineWidth);
_done->resizeToWidth(width());
_done->moveToLeft(0, submitTop);

View File

@ -13,8 +13,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
namespace Ui {
class InputField;
class ScrollArea;
class FadeShadow;
class PlainShadow;
class FlatLabel;
class RoundButton;
class VerticalLayout;
@ -157,8 +155,6 @@ private:
Scheme _scheme;
object_ptr<Ui::ScrollArea> _scroll;
object_ptr<Ui::FadeShadow> _topShadow;
object_ptr<Ui::PlainShadow> _bottomShadow;
QPointer<EditScans> _editScans;
QPointer<Ui::SlideWrap<Ui::FlatLabel>> _commonError;

View File

@ -14,13 +14,12 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "core/click_handler_types.h"
#include "data/data_user.h"
#include "ui/effects/animations.h"
#include "ui/widgets/shadow.h"
#include "ui/effects/scroll_content_shadow.h"
#include "ui/widgets/buttons.h"
#include "ui/widgets/scroll_area.h"
#include "ui/widgets/labels.h"
#include "ui/widgets/box_content_divider.h"
#include "ui/wrap/vertical_layout.h"
#include "ui/wrap/fade_wrap.h"
#include "ui/wrap/padding_wrap.h"
#include "ui/text/text_utilities.h"
#include "ui/text/text_options.h"
@ -37,8 +36,6 @@ PanelForm::PanelForm(
: RpWidget(parent)
, _controller(controller)
, _scroll(this, st::passportPanelScroll)
, _topShadow(this)
, _bottomShadow(this)
, _submit(
this,
tr::lng_passport_authorize(),
@ -53,15 +50,7 @@ void PanelForm::setupControls() {
_controller->submitForm();
});
using namespace rpl::mappers;
_topShadow->toggleOn(
_scroll->scrollTopValue() | rpl::map(_1 > 0));
_bottomShadow->toggleOn(rpl::combine(
_scroll->scrollTopValue(),
_scroll->heightValue(),
inner->heightValue(),
_1 + _2 < _3));
SetupShadowsToScrollContent(this, _scroll, inner->heightValue());
}
not_null<Ui::RpWidget*> PanelForm::setupContent() {
@ -188,10 +177,6 @@ void PanelForm::resizeEvent(QResizeEvent *e) {
void PanelForm::updateControlsGeometry() {
const auto submitTop = height() - _submit->height();
_scroll->setGeometry(0, 0, width(), submitTop);
_topShadow->resizeToWidth(width());
_topShadow->moveToLeft(0, 0);
_bottomShadow->resizeToWidth(width());
_bottomShadow->moveToLeft(0, submitTop - st::lineWidth);
_submit->setFullWidth(width());
_submit->moveToLeft(0, submitTop);

View File

@ -13,7 +13,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
namespace Ui {
class BoxContentDivider;
class ScrollArea;
class FadeShadow;
class RoundButton;
class FlatLabel;
class UserpicButton;
@ -47,8 +46,6 @@ private:
not_null<PanelController*> _controller;
object_ptr<Ui::ScrollArea> _scroll;
object_ptr<Ui::FadeShadow> _topShadow;
object_ptr<Ui::FadeShadow> _bottomShadow;
object_ptr<Ui::RoundButton> _submit;
QPointer<Ui::UserpicButton> _userpic;

View File

@ -0,0 +1,47 @@
/*
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 "ui/effects/scroll_content_shadow.h"
#include "ui/rp_widget.h"
#include "ui/widgets/scroll_area.h"
#include "ui/wrap/fade_wrap.h"
namespace Ui {
void SetupShadowsToScrollContent(
not_null<Ui::RpWidget*> parent,
not_null<Ui::ScrollArea*> scroll,
rpl::producer<int> &&innerHeightValue) {
using namespace rpl::mappers;
const auto topShadow = Ui::CreateChild<Ui::FadeShadow>(parent.get());
const auto bottomShadow = Ui::CreateChild<Ui::FadeShadow>(parent.get());
scroll->geometryValue(
) | rpl::start_with_next_done([=](const QRect &geometry) {
topShadow->resizeToWidth(geometry.width());
topShadow->move(
geometry.x(),
geometry.y());
bottomShadow->resizeToWidth(geometry.width());
bottomShadow->move(
geometry.x(),
geometry.y() + geometry.height() - st::lineWidth);
}, [t = Ui::MakeWeak(topShadow), b = Ui::MakeWeak(bottomShadow)] {
Ui::DestroyChild(t.data());
Ui::DestroyChild(b.data());
}, topShadow->lifetime());
topShadow->toggleOn(scroll->scrollTopValue() | rpl::map(_1 > 0));
bottomShadow->toggleOn(rpl::combine(
scroll->scrollTopValue(),
scroll->heightValue(),
std::move(innerHeightValue),
_1 + _2 < _3));
}
} // namespace Ui

View File

@ -0,0 +1,20 @@
/*
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
namespace Ui {
class RpWidget;
class ScrollArea;
void SetupShadowsToScrollContent(
not_null<Ui::RpWidget*> parent,
not_null<Ui::ScrollArea*> scroll,
rpl::producer<int> &&innerHeightValue);
} // namespace Ui

View File

@ -223,6 +223,8 @@ PRIVATE
ui/controls/who_reacted_context_action.h
ui/controls/window_outdated_bar.cpp
ui/controls/window_outdated_bar.h
ui/effects/scroll_content_shadow.cpp
ui/effects/scroll_content_shadow.h
ui/text/format_song_name.cpp
ui/text/format_song_name.h
ui/text/format_values.cpp