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()) {
const auto settingsStickerHeight = (*settingsStickerHeightIt).toInt();
if (settingsStickerHeight >= 128 || settingsStickerHeight <= 256) {
cSetStickerHeight(settingsStickerHeight);
SetStickerHeight(settingsStickerHeight);
}
}
@ -246,7 +246,7 @@ void Manager::writeDefaultFile() {
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("always_show_scheduled"), cAlwaysShowScheduled());
settings.insert(qsl("show_chat_id"), cShowChatId());

View file

@ -511,6 +511,13 @@ HistoryWidget::HistoryWidget(
});
}, lifetime());
StickerHeightChanges(
) | rpl::start_with_next([=] {
crl::on_main(this, [=] {
updateHistoryGeometry();
});
}, lifetime());
session().data().animationPlayInlineRequest(
) | rpl::start_with_next([=](not_null<HistoryItem*> item) {
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/history_view_element.h"
#include "history/view/history_view_cursor_state.h"
#include "history/history.h"
#include "history/history_item.h"
#include "history/history_item_components.h"
#include "data/data_session.h"
#include "layout.h"
#include "facades.h"
#include "app.h"
@ -26,13 +28,17 @@ UnwrappedMedia::UnwrappedMedia(
std::unique_ptr<Content> content)
: Media(parent)
, _content(std::move(content)) {
StickerHeightChanges(
) | rpl::start_with_next([=] {
history()->owner().requestItemViewRefresh(_parent->data());
}, _lifetime);
}
QSize UnwrappedMedia::countOptimalSize() {
_content->refreshLink();
_contentSize = NonEmptySize(DownscaledSize(
_content->size(),
{ st::maxStickerSize, cStickerHeight() }));
{ st::maxStickerSize, StickerHeight() }));
auto maxWidth = _contentSize.width();
const auto minimal = st::largeEmojiSize + 2 * st::largeEmojiOutline;
auto minHeight = std::max(_contentSize.height(), minimal);

View file

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

View file

@ -60,13 +60,13 @@ QSize Sticker::size() {
constexpr auto kIdealStickerSize = 512;
const auto zoom = GetEmojiStickerZoom(&_document->session());
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()));
} else {
_size = DownscaledSize(
_size,
{ st::maxStickerSize, cStickerHeight() });
{ st::maxStickerSize, StickerHeight() });
}
return _size;
}

View file

@ -210,7 +210,16 @@ rpl::producer<> UpdatedRecentEmoji() {
QString gMainFont, gSemiboldFont, gMonospaceFont;
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;
void SetBigEmojiOutline(bool enabled) {

View file

@ -188,7 +188,10 @@ void SetBigEmojiOutline(bool enabled);
[[nodiscard]] bool BigEmojiOutline();
[[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, ShowChatId);

View file

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