Removed masks panel when there are no masks.

This commit is contained in:
23rd 2021-03-31 03:26:32 +03:00
parent 2a58d01927
commit b2a1c10036
5 changed files with 50 additions and 14 deletions

View file

@ -641,7 +641,7 @@ void StickersBox::refreshTabs() {
sections.push_back(tr::lng_stickers_installed_tab(tr::now).toUpper());
_tabIndices.push_back(Section::Installed);
}
if (!stickers.maskSetsOrder().isEmpty() && _masks.widget()) {
if (_masks.widget()) {
sections.push_back(tr::lng_stickers_masks_tab(tr::now).toUpper());
_tabIndices.push_back(Section::Masks);
}

View file

@ -3237,6 +3237,7 @@ void StickersListWidget::removeSet(uint64 setId) {
if (writeRecent) {
session().saveSettings();
}
session().data().stickers().notifyUpdated();
}
_removingSetId = 0;
_checkForHide.fire({});
@ -3258,6 +3259,10 @@ Data::StickersSetsOrder &StickersListWidget::defaultSetsOrderRef() {
: session().data().stickers().maskSetsOrderRef();
}
bool StickersListWidget::mySetsEmpty() const {
return _mySets.empty();
}
StickersListWidget::~StickersListWidget() = default;
} // namespace ChatHelpers

View file

@ -89,6 +89,8 @@ public:
not_null<Ui::PopupMenu*> menu,
SendMenu::Type type) override;
bool mySetsEmpty() const;
~StickersListWidget();
protected:

View file

@ -496,11 +496,19 @@ rpl::producer<> TabbedSelector::slideFinished() const {
return _slideFinished.events();
}
void TabbedSelector::resizeEvent(QResizeEvent *e) {
if (_tabsSlider) {
_tabsSlider->resizeToWidth(width());
_tabsSlider->moveToLeft(0, 0);
void TabbedSelector::updateTabsSliderGeometry() {
if (!_tabsSlider) {
return;
}
const auto w = mediaEditor() && hasMasksTab() && masks()->mySetsEmpty()
? width() / 2
: width();
_tabsSlider->resizeToWidth(w);
_tabsSlider->moveToLeft(0, 0);
}
void TabbedSelector::resizeEvent(QResizeEvent *e) {
updateTabsSliderGeometry();
if (_topShadow && _tabsSlider) {
_topShadow->setGeometry(
_tabsSlider->x(),
@ -680,9 +688,16 @@ void TabbedSelector::refreshStickers() {
}
}
if (hasMasksTab()) {
masks()->refreshStickers();
const auto masksList = masks();
masksList->refreshStickers();
if (isHidden() || _currentTabType != SelectorTab::Masks) {
masks()->preloadImages();
masksList->preloadImages();
}
fillTabsSliderSections();
updateTabsSliderGeometry();
if (hasStickersTab() && masksList->mySetsEmpty()) {
_tabsSlider->setActiveSection(indexByType(SelectorTab::Stickers));
}
}
}
@ -869,9 +884,27 @@ void TabbedSelector::setRoundRadius(int radius) {
void TabbedSelector::createTabsSlider() {
_tabsSlider.create(this, st::emojiTabs);
fillTabsSliderSections();
_tabsSlider->setActiveSectionFast(indexByType(_currentTabType));
_tabsSlider->sectionActivated(
) | rpl::start_with_next([=] {
switchTab();
}, lifetime());
}
void TabbedSelector::fillTabsSliderSections() {
if (!_tabsSlider) {
return;
}
const auto sections = ranges::views::all(
_tabs
) | ranges::views::transform([=](const Tab &tab) {
) | ranges::views::filter([&](const Tab &tab) {
return (tab.type() == SelectorTab::Masks)
? !masks()->mySetsEmpty()
: true;
}) | ranges::views::transform([&](const Tab &tab) {
return [type = tab.type()] {
switch (type) {
case SelectorTab::Emoji:
@ -886,12 +919,6 @@ void TabbedSelector::createTabsSlider() {
}()(tr::now).toUpper();
}) | ranges::to_vector;
_tabsSlider->setSections(sections);
_tabsSlider->setActiveSectionFast(indexByType(_currentTabType));
_tabsSlider->sectionActivated(
) | rpl::start_with_next([=] {
switchTab();
}, lifetime());
}
bool TabbedSelector::hasSectionIcons() const {

View file

@ -198,6 +198,8 @@ private:
bool hasSectionIcons() const;
void setWidgetToScrollArea();
void createTabsSlider();
void fillTabsSliderSections();
void updateTabsSliderGeometry();
void switchTab();
not_null<Tab*> getTab(int index);