mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Scroll to currently selected theme.
This commit is contained in:
parent
1424ea3540
commit
de2bad51d3
2 changed files with 50 additions and 20 deletions
|
@ -126,6 +126,18 @@ constexpr auto kDisableElement = "disable"_cs;
|
||||||
st::settingsThemePreviewSize * style::DevicePixelRatio(),
|
st::settingsThemePreviewSize * style::DevicePixelRatio(),
|
||||||
QImage::Format_ARGB32_Premultiplied);
|
QImage::Format_ARGB32_Premultiplied);
|
||||||
result.fill(st::settingsThemeNotSupportedBg->c);
|
result.fill(st::settingsThemeNotSupportedBg->c);
|
||||||
|
{
|
||||||
|
auto p = QPainter(&result);
|
||||||
|
p.setPen(st::menuIconFg);
|
||||||
|
p.setFont(st::semiboldFont);
|
||||||
|
const auto top = st::normalFont->height / 2;
|
||||||
|
const auto width = st::settingsThemePreviewSize.width();
|
||||||
|
const auto height = st::settingsThemePreviewSize.height() - top;
|
||||||
|
p.drawText(
|
||||||
|
QRect(0, top, width, height),
|
||||||
|
tr::lng_chat_theme_none(tr::now),
|
||||||
|
style::al_top);
|
||||||
|
}
|
||||||
Images::prepareRound(result, ImageRoundRadius::Large);
|
Images::prepareRound(result, ImageRoundRadius::Large);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -175,12 +187,12 @@ void ChooseThemeController::init(rpl::producer<QSize> outer) {
|
||||||
}, lifetime());
|
}, lifetime());
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto skip = st::normalFont->spacew * 2;
|
const auto skip = st::normalFont->spacew * 4;
|
||||||
const auto titleWrap = _wrap->insert(
|
const auto titleWrap = _wrap->insert(
|
||||||
0,
|
0,
|
||||||
object_ptr<FixedHeightWidget>(
|
object_ptr<FixedHeightWidget>(
|
||||||
_wrap.get(),
|
_wrap.get(),
|
||||||
skip + st::boxTitle.style.font->height));
|
skip + st::boxTitle.style.font->height + skip));
|
||||||
auto title = CreateChild<FlatLabel>(
|
auto title = CreateChild<FlatLabel>(
|
||||||
titleWrap,
|
titleWrap,
|
||||||
tr::lng_chat_theme_title(),
|
tr::lng_chat_theme_title(),
|
||||||
|
@ -230,7 +242,7 @@ void ChooseThemeController::initButtons() {
|
||||||
const auto skip = st::normalFont->spacew * 2;
|
const auto skip = st::normalFont->spacew * 2;
|
||||||
controls->resize(
|
controls->resize(
|
||||||
skip + cancel->width() + skip + apply->width() + skip,
|
skip + cancel->width() + skip + apply->width() + skip,
|
||||||
apply->height() + skip);
|
apply->height() + skip * 2);
|
||||||
rpl::combine(
|
rpl::combine(
|
||||||
controls->widthValue(),
|
controls->widthValue(),
|
||||||
cancel->widthValue(),
|
cancel->widthValue(),
|
||||||
|
@ -289,14 +301,13 @@ void ChooseThemeController::paintEntry(QPainter &p, const Entry &entry) {
|
||||||
|
|
||||||
const auto size = Ui::Emoji::GetSizeLarge();
|
const auto size = Ui::Emoji::GetSizeLarge();
|
||||||
const auto factor = style::DevicePixelRatio();
|
const auto factor = style::DevicePixelRatio();
|
||||||
const auto skip = st::normalFont->spacew * 2;
|
const auto emojiLeft = geometry.x()
|
||||||
Ui::Emoji::Draw(
|
+ (geometry.width() - (size / factor)) / 2;
|
||||||
p,
|
const auto emojiTop = geometry.y()
|
||||||
entry.emoji,
|
+ geometry.height()
|
||||||
size,
|
- (size / factor)
|
||||||
(geometry.x()
|
- (st::normalFont->spacew * 2);
|
||||||
+ (geometry.width() - (size / factor)) / 2),
|
Ui::Emoji::Draw(p, entry.emoji, size, emojiLeft, emojiTop);
|
||||||
(geometry.y() + geometry.height() - (size / factor) - skip));
|
|
||||||
|
|
||||||
if (entry.chosen) {
|
if (entry.chosen) {
|
||||||
auto hq = PainterHighQualityEnabler(p);
|
auto hq = PainterHighQualityEnabler(p);
|
||||||
|
@ -315,7 +326,7 @@ void ChooseThemeController::paintEntry(QPainter &p, const Entry &entry) {
|
||||||
void ChooseThemeController::initList() {
|
void ChooseThemeController::initList() {
|
||||||
_content->resize(
|
_content->resize(
|
||||||
_content->width(),
|
_content->width(),
|
||||||
4 * st::normalFont->spacew + st::settingsThemePreviewSize.height());
|
8 * st::normalFont->spacew + st::settingsThemePreviewSize.height());
|
||||||
_inner->setMouseTracking(true);
|
_inner->setMouseTracking(true);
|
||||||
|
|
||||||
_inner->paintRequest(
|
_inner->paintRequest(
|
||||||
|
@ -421,11 +432,25 @@ void ChooseThemeController::initList() {
|
||||||
rpl::combine(
|
rpl::combine(
|
||||||
_content->widthValue(),
|
_content->widthValue(),
|
||||||
_inner->widthValue()
|
_inner->widthValue()
|
||||||
) | rpl::start_with_next([=] {
|
) | rpl::start_with_next([=](int content, int inner) {
|
||||||
updateInnerLeft(_inner->x());
|
if (!content || !inner) {
|
||||||
|
return;
|
||||||
|
} else if (!_entries.empty() && !_initialInnerLeftApplied) {
|
||||||
|
applyInitialInnerLeft();
|
||||||
|
} else {
|
||||||
|
updateInnerLeft(_inner->x());
|
||||||
|
}
|
||||||
}, lifetime());
|
}, lifetime());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ChooseThemeController::applyInitialInnerLeft() {
|
||||||
|
if (const auto chosen = findChosen()) {
|
||||||
|
updateInnerLeft(
|
||||||
|
_content->width() / 2 - chosen->geometry.center().x());
|
||||||
|
}
|
||||||
|
_initialInnerLeftApplied = true;
|
||||||
|
}
|
||||||
|
|
||||||
void ChooseThemeController::updateInnerLeft(int now) {
|
void ChooseThemeController::updateInnerLeft(int now) {
|
||||||
const auto skip = _content->width() - _inner->width();
|
const auto skip = _content->width() - _inner->width();
|
||||||
const auto clamped = (skip >= 0)
|
const auto clamped = (skip >= 0)
|
||||||
|
@ -477,22 +502,21 @@ void ChooseThemeController::fill(
|
||||||
const auto count = int(themes.size()) + 1;
|
const auto count = int(themes.size()) + 1;
|
||||||
const auto single = st::settingsThemePreviewSize;
|
const auto single = st::settingsThemePreviewSize;
|
||||||
const auto skip = st::normalFont->spacew * 2;
|
const auto skip = st::normalFont->spacew * 2;
|
||||||
const auto full = single.width() * count + skip * (count + 1);
|
const auto full = single.width() * count + skip * (count + 3);
|
||||||
_inner->resize(full, skip + single.height() + skip);
|
_inner->resize(full, skip + single.height() + skip);
|
||||||
|
|
||||||
const auto initialSelected = Ui::Emoji::Find(_peer->themeEmoji());
|
const auto initial = Ui::Emoji::Find(_peer->themeEmoji());
|
||||||
|
|
||||||
_dark.value(
|
_dark.value(
|
||||||
) | rpl::start_with_next([=](bool dark) {
|
) | rpl::start_with_next([=](bool dark) {
|
||||||
clearCurrentBackgroundState();
|
clearCurrentBackgroundState();
|
||||||
const auto initialSelect = (_chosen.isEmpty() && initialSelected);
|
if (_chosen.isEmpty() && initial) {
|
||||||
if (initialSelect) {
|
_chosen = initial->text();
|
||||||
_chosen = initialSelected->text();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_cachingLifetime.destroy();
|
_cachingLifetime.destroy();
|
||||||
const auto old = base::take(_entries);
|
const auto old = base::take(_entries);
|
||||||
auto x = skip;
|
auto x = skip * 2;
|
||||||
_entries.push_back({
|
_entries.push_back({
|
||||||
.preview = GenerateEmptyPreview(),
|
.preview = GenerateEmptyPreview(),
|
||||||
.emoji = Ui::Emoji::Find(QString::fromUtf8("\xe2\x9d\x8c")),
|
.emoji = Ui::Emoji::Find(QString::fromUtf8("\xe2\x9d\x8c")),
|
||||||
|
@ -567,6 +591,10 @@ void ChooseThemeController::fill(
|
||||||
}, _cachingLifetime);
|
}, _cachingLifetime);
|
||||||
x += single.width() + skip;
|
x += single.width() + skip;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!_initialInnerLeftApplied && _content->width() > 0) {
|
||||||
|
applyInitialInnerLeft();
|
||||||
|
}
|
||||||
}, lifetime());
|
}, lifetime());
|
||||||
_shouldBeShown = true;
|
_shouldBeShown = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,6 +53,7 @@ private:
|
||||||
|
|
||||||
void clearCurrentBackgroundState();
|
void clearCurrentBackgroundState();
|
||||||
void paintEntry(QPainter &p, const Entry &entry);
|
void paintEntry(QPainter &p, const Entry &entry);
|
||||||
|
void applyInitialInnerLeft();
|
||||||
void updateInnerLeft(int now);
|
void updateInnerLeft(int now);
|
||||||
|
|
||||||
[[nodiscard]] Entry *findChosen();
|
[[nodiscard]] Entry *findChosen();
|
||||||
|
@ -71,6 +72,7 @@ private:
|
||||||
std::optional<QPoint> _pressPosition;
|
std::optional<QPoint> _pressPosition;
|
||||||
std::optional<QPoint> _dragStartPosition;
|
std::optional<QPoint> _dragStartPosition;
|
||||||
int _dragStartInnerLeft = 0;
|
int _dragStartInnerLeft = 0;
|
||||||
|
bool _initialInnerLeftApplied = false;
|
||||||
|
|
||||||
rpl::variable<bool> _shouldBeShown = false;
|
rpl::variable<bool> _shouldBeShown = false;
|
||||||
rpl::variable<bool> _forceHidden = false;
|
rpl::variable<bool> _forceHidden = false;
|
||||||
|
|
Loading…
Add table
Reference in a new issue