Automatic applying of sticker height change

This commit is contained in:
Eric Kotato 2019-10-11 02:39:38 +03:00
parent 7393cb5221
commit 4caedcbf49
8 changed files with 37 additions and 10 deletions

View file

@ -160,7 +160,7 @@ bool Manager::readCustomFile() {
if (settingsStickerHeightIt != settings.constEnd()) { if (settingsStickerHeightIt != settings.constEnd()) {
const auto settingsStickerHeight = (*settingsStickerHeightIt).toInt(); const auto settingsStickerHeight = (*settingsStickerHeightIt).toInt();
if (settingsStickerHeight >= 128 || settingsStickerHeight <= 256) { if (settingsStickerHeight >= 128 || settingsStickerHeight <= 256) {
cSetStickerHeight(settingsStickerHeight); SetStickerHeight(settingsStickerHeight);
} }
} }
@ -246,7 +246,7 @@ void Manager::writeDefaultFile() {
settings.insert(qsl("fonts"), settingsFonts); settings.insert(qsl("fonts"), settingsFonts);
settings.insert(qsl("sticker_height"), cStickerHeight()); settings.insert(qsl("sticker_height"), StickerHeight());
settings.insert(qsl("big_emoji_outline"), BigEmojiOutline()); settings.insert(qsl("big_emoji_outline"), BigEmojiOutline());
settings.insert(qsl("always_show_scheduled"), cAlwaysShowScheduled()); settings.insert(qsl("always_show_scheduled"), cAlwaysShowScheduled());
settings.insert(qsl("show_chat_id"), cShowChatId()); settings.insert(qsl("show_chat_id"), cShowChatId());

View file

@ -511,6 +511,13 @@ HistoryWidget::HistoryWidget(
}); });
}, lifetime()); }, lifetime());
StickerHeightChanges(
) | rpl::start_with_next([=] {
crl::on_main(this, [=] {
updateHistoryGeometry();
});
}, lifetime());
session().data().animationPlayInlineRequest( session().data().animationPlayInlineRequest(
) | rpl::start_with_next([=](not_null<HistoryItem*> item) { ) | rpl::start_with_next([=](not_null<HistoryItem*> item) {
if (const auto view = item->mainView()) { if (const auto view = item->mainView()) {

View file

@ -10,8 +10,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "history/view/media/history_view_media_common.h" #include "history/view/media/history_view_media_common.h"
#include "history/view/history_view_element.h" #include "history/view/history_view_element.h"
#include "history/view/history_view_cursor_state.h" #include "history/view/history_view_cursor_state.h"
#include "history/history.h"
#include "history/history_item.h" #include "history/history_item.h"
#include "history/history_item_components.h" #include "history/history_item_components.h"
#include "data/data_session.h"
#include "layout.h" #include "layout.h"
#include "facades.h" #include "facades.h"
#include "app.h" #include "app.h"
@ -26,13 +28,17 @@ UnwrappedMedia::UnwrappedMedia(
std::unique_ptr<Content> content) std::unique_ptr<Content> content)
: Media(parent) : Media(parent)
, _content(std::move(content)) { , _content(std::move(content)) {
StickerHeightChanges(
) | rpl::start_with_next([=] {
history()->owner().requestItemViewRefresh(_parent->data());
}, _lifetime);
} }
QSize UnwrappedMedia::countOptimalSize() { QSize UnwrappedMedia::countOptimalSize() {
_content->refreshLink(); _content->refreshLink();
_contentSize = NonEmptySize(DownscaledSize( _contentSize = NonEmptySize(DownscaledSize(
_content->size(), _content->size(),
{ st::maxStickerSize, cStickerHeight() })); { st::maxStickerSize, StickerHeight() }));
auto maxWidth = _contentSize.width(); auto maxWidth = _contentSize.width();
const auto minimal = st::largeEmojiSize + 2 * st::largeEmojiOutline; const auto minimal = st::largeEmojiSize + 2 * st::largeEmojiOutline;
auto minHeight = std::max(_contentSize.height(), minimal); auto minHeight = std::max(_contentSize.height(), minimal);

View file

@ -111,6 +111,8 @@ private:
std::unique_ptr<Content> _content; std::unique_ptr<Content> _content;
QSize _contentSize; QSize _contentSize;
rpl::lifetime _lifetime;
}; };
} // namespace HistoryView } // namespace HistoryView

View file

@ -60,13 +60,13 @@ QSize Sticker::size() {
constexpr auto kIdealStickerSize = 512; constexpr auto kIdealStickerSize = 512;
const auto zoom = GetEmojiStickerZoom(&_document->session()); const auto zoom = GetEmojiStickerZoom(&_document->session());
const auto convert = [&](int size) { const auto convert = [&](int size) {
return int(size * cStickerHeight() * zoom / kIdealStickerSize); return int(size * StickerHeight() * zoom / kIdealStickerSize);
}; };
_size = QSize(convert(_size.width()), convert(_size.height())); _size = QSize(convert(_size.width()), convert(_size.height()));
} else { } else {
_size = DownscaledSize( _size = DownscaledSize(
_size, _size,
{ st::maxStickerSize, cStickerHeight() }); { st::maxStickerSize, StickerHeight() });
} }
return _size; return _size;
} }

View file

@ -210,7 +210,16 @@ rpl::producer<> UpdatedRecentEmoji() {
QString gMainFont, gSemiboldFont, gMonospaceFont; QString gMainFont, gSemiboldFont, gMonospaceFont;
bool gSemiboldFontIsBold = false; bool gSemiboldFontIsBold = false;
int gStickerHeight = 128; rpl::variable<int> gStickerHeight = 128;
void SetStickerHeight(int height) {
gStickerHeight = height;
}
int StickerHeight() {
return gStickerHeight.current();
}
rpl::producer<int> StickerHeightChanges() {
return gStickerHeight.changes();
}
rpl::variable<bool> gBigEmojiOutline = false; rpl::variable<bool> gBigEmojiOutline = false;
void SetBigEmojiOutline(bool enabled) { void SetBigEmojiOutline(bool enabled) {

View file

@ -188,7 +188,10 @@ void SetBigEmojiOutline(bool enabled);
[[nodiscard]] bool BigEmojiOutline(); [[nodiscard]] bool BigEmojiOutline();
[[nodiscard]] rpl::producer<bool> BigEmojiOutlineChanges(); [[nodiscard]] rpl::producer<bool> BigEmojiOutlineChanges();
DeclareSetting(int, StickerHeight); void SetStickerHeight(int height);
[[nodiscard]] int StickerHeight();
[[nodiscard]] rpl::producer<int> StickerHeightChanges();
DeclareSetting(bool, AlwaysShowScheduled); DeclareSetting(bool, AlwaysShowScheduled);
DeclareSetting(bool, ShowChatId); DeclareSetting(bool, ShowChatId);

View file

@ -56,15 +56,15 @@ void SetupKotatoChats(not_null<Ui::VerticalLayout*> container) {
}; };
const auto updateStickerHeight = [=](int value) { const auto updateStickerHeight = [=](int value) {
updateStickerHeightLabel(value); updateStickerHeightLabel(value);
cSetStickerHeight(value); SetStickerHeight(value);
}; };
stickerHeightSlider->resize(st::settingsAudioVolumeSlider.seekSize); stickerHeightSlider->resize(st::settingsAudioVolumeSlider.seekSize);
stickerHeightSlider->setPseudoDiscrete( stickerHeightSlider->setPseudoDiscrete(
129, 129,
[](int val) { return val + 128; }, [](int val) { return val + 128; },
cStickerHeight(), StickerHeight(),
updateStickerHeight); updateStickerHeight);
updateStickerHeightLabel(cStickerHeight()); updateStickerHeightLabel(StickerHeight());
AddButton( AddButton(
container, container,