Change *[Fast|Animated] to anim::type in SlideWrap.

This commit is contained in:
John Preston 2017-10-01 11:15:40 +03:00
parent 83850d9b86
commit f0ad78d808
15 changed files with 129 additions and 111 deletions

View File

@ -316,13 +316,21 @@ void EditPrivacyBox::createWidgets() {
_optionGroup->setChangedCallback([this](Option value) {
_option = value;
_alwaysLink->toggleAnimated(showExceptionLink(Exception::Always));
_neverLink->toggleAnimated(showExceptionLink(Exception::Never));
_alwaysLink->toggle(
showExceptionLink(Exception::Always),
anim::type::normal);
_neverLink->toggle(
showExceptionLink(Exception::Never),
anim::type::normal);
});
showChildren();
_alwaysLink->toggleFast(showExceptionLink(Exception::Always));
_neverLink->toggleFast(showExceptionLink(Exception::Never));
_alwaysLink->toggle(
showExceptionLink(Exception::Always),
anim::type::instant);
_neverLink->toggle(
showExceptionLink(Exception::Never),
anim::type::instant);
setDimensions(st::boxWideWidth, resizeGetHeight(st::boxWideWidth));
}

View File

@ -156,7 +156,7 @@ void PeerListBox::paintEvent(QPaintEvent *e) {
}
void PeerListBox::setInnerFocus() {
if (!_select || _select->isHiddenOrHiding()) {
if (!_select || !_select->toggled()) {
content()->setFocus();
} else {
_select->entity()->setInnerFocus();
@ -191,10 +191,10 @@ void PeerListBox::peerListSetSearchMode(PeerListSearchMode mode) {
auto selectVisible = (mode != PeerListSearchMode::Disabled);
if (selectVisible && !_select) {
createMultiSelect();
_select->toggleFast(!selectVisible);
_select->toggle(!selectVisible, anim::type::instant);
}
if (_select) {
_select->toggleAnimated(selectVisible);
_select->toggle(selectVisible, anim::type::normal);
_scrollBottomFixed = false;
setInnerFocus();
}
@ -256,7 +256,7 @@ void PeerListController::setSearchNoResultsText(const QString &text) {
void PeerListBox::addSelectItem(not_null<PeerData*> peer, PeerListRow::SetStyle style) {
if (!_select) {
createMultiSelect();
_select->toggleFast(false);
_select->hide(anim::type::instant);
}
if (style == PeerListRow::SetStyle::Fast) {
_select->entity()->addItemInBunch(peer->id, peer->shortName(), st::activeButtonBg, PaintUserpicCallback(peer));

View File

@ -47,7 +47,7 @@ object_ptr<Ui::SlideWrap<Ui::VerticalLayout>> CreateTextWithLabel(
| rpl::before_next([slide = result.data()](
const TextWithEntities &value) {
if (value.text.isEmpty()) {
slide->hideAnimated();
slide->hide(anim::type::normal);
}
})
| rpl::filter([](const TextWithEntities &value) {
@ -55,7 +55,7 @@ object_ptr<Ui::SlideWrap<Ui::VerticalLayout>> CreateTextWithLabel(
})
| rpl::after_next([slide = result.data()](
const TextWithEntities &value) {
slide->showAnimated();
slide->show(anim::type::normal);
});
auto labeled = layout->add(object_ptr<Ui::FlatLabel>(
layout,

View File

@ -244,7 +244,7 @@ rpl::producer<bool> MultiLineTracker::atLeastOneShownValue() const {
auto shown = std::vector<rpl::producer<bool>>();
shown.reserve(_widgets.size());
for (auto &widget : _widgets) {
shown.push_back(widget->shownValue());
shown.push_back(widget->toggledValue());
}
return rpl::combine(
std::move(shown),

View File

@ -1793,7 +1793,7 @@ void MainWidget::switchToPanelPlayer() {
if (_playerUsingPanel) return;
_playerUsingPanel = true;
_player->hideAnimated();
_player->hide(anim::type::normal);
_playerVolume.destroyDelayed();
_playerPlaylist->hideIgnoringEnterEvents();
@ -1807,7 +1807,7 @@ void MainWidget::switchToFixedPlayer() {
if (!_player) {
createPlayer();
} else {
_player->showAnimated();
_player->show(anim::type::normal);
if (!_playerVolume) {
_playerVolume.create(this);
_player->entity()->volumeWidgetCreated(_playerVolume);
@ -1824,7 +1824,7 @@ void MainWidget::closeBothPlayers() {
_playerUsingPanel = false;
_player.destroyDelayed();
} else {
_player->hideAnimated();
_player->hide(anim::type::normal);
}
_playerVolume.destroyDelayed();
@ -1852,16 +1852,16 @@ void MainWidget::createPlayer() {
_player->entity()->volumeWidgetCreated(_playerVolume);
orderWidgets();
if (_a_show.animating()) {
_player->showFast();
_player->hide();
_player->show(anim::type::instant);
_player->setVisible(false);
Shortcuts::enableMediaShortcuts();
} else {
_player->hideFast();
_player->hide(anim::type::instant);
}
}
if (_player && _player->isHiddenOrHiding()) {
if (_player && !_player->toggled()) {
if (!_a_show.animating()) {
_player->showAnimated();
_player->show(anim::type::normal);
_playerHeight = _contentScrollAddToY = _player->contentHeight();
updateControlsGeometry();
Shortcuts::enableMediaShortcuts();
@ -1910,11 +1910,11 @@ void MainWidget::createCallTopBar() {
}, lifetime());
orderWidgets();
if (_a_show.animating()) {
_callTopBar->showFast();
_callTopBar->hide();
_callTopBar->show(anim::type::instant);
_callTopBar->setVisible(false);
} else {
_callTopBar->hideFast();
_callTopBar->showAnimated();
_callTopBar->hide(anim::type::instant);
_callTopBar->show(anim::type::normal);
_callTopBarHeight = _contentScrollAddToY = _callTopBar->height();
updateControlsGeometry();
}
@ -1922,7 +1922,7 @@ void MainWidget::createCallTopBar() {
void MainWidget::destroyCallTopBar() {
if (_callTopBar) {
_callTopBar->hideAnimated();
_callTopBar->hide(anim::type::normal);
}
}
@ -3342,7 +3342,7 @@ void MainWidget::hideAll() {
_thirdShadow->hide();
}
if (_player) {
_player->hide();
_player->setVisible(false);
_playerHeight = 0;
}
for (auto &instance : _playerFloats) {
@ -3421,7 +3421,7 @@ void MainWidget::showAll() {
}
}
if (_player) {
_player->show();
_player->setVisible(true);
_playerHeight = _player->contentHeight();
}
updateControlsGeometry();

View File

@ -76,11 +76,11 @@ void AdvancedWidget::createControls() {
style::margins slidedPadding(0, marginLarge.bottom() / 2, 0, marginLarge.bottom() - (marginLarge.bottom() / 2));
createChildRow(_useDefaultTheme, marginLarge, slidedPadding, lang(lng_settings_bg_use_default), SLOT(onUseDefaultTheme()));
if (!Window::Theme::IsNonDefaultUsed()) {
_useDefaultTheme->hideFast();
_useDefaultTheme->hide(anim::type::instant);
}
createChildRow(_toggleNightTheme, marginLarge, slidedPadding, getNightThemeToggleText(), SLOT(onToggleNightTheme()));
if (Window::Theme::IsNonDefaultUsed()) {
_toggleNightTheme->hideFast();
_toggleNightTheme->hide(anim::type::instant);
}
}
createChildRow(_telegramFAQ, marginLarge, lang(lng_settings_faq), SLOT(onTelegramFAQ()));
@ -92,9 +92,13 @@ void AdvancedWidget::createControls() {
void AdvancedWidget::checkNonDefaultTheme() {
if (self()) return;
_useDefaultTheme->toggleAnimated(Window::Theme::IsNonDefaultUsed());
_useDefaultTheme->toggle(
Window::Theme::IsNonDefaultUsed(),
anim::type::normal);
_toggleNightTheme->entity()->setText(getNightThemeToggleText());
_toggleNightTheme->toggleAnimated(!Window::Theme::IsNonDefaultUsed());
_toggleNightTheme->toggle(
!Window::Theme::IsNonDefaultUsed(),
anim::type::normal);
}
void AdvancedWidget::onManageLocalStorage() {

View File

@ -208,7 +208,9 @@ BackgroundWidget::BackgroundWidget(QWidget *parent, UserData *self) : BlockWidge
}
});
subscribe(Adaptive::Changed(), [this]() {
_adaptive->toggleAnimated(Global::AdaptiveChatLayout() == Adaptive::ChatLayout::Wide);
_adaptive->toggle(
(Global::AdaptiveChatLayout() == Adaptive::ChatLayout::Wide),
anim::type::normal);
});
}
@ -225,7 +227,7 @@ void BackgroundWidget::createControls() {
createChildRow(_tile, margin, lang(lng_settings_bg_tile), [this](bool) { onTile(); }, Window::Theme::Background()->tile());
createChildRow(_adaptive, margin, slidedPadding, lang(lng_settings_adaptive_wide), [this](bool) { onAdaptive(); }, Global::AdaptiveForWide());
if (Global::AdaptiveChatLayout() != Adaptive::ChatLayout::Wide) {
_adaptive->hideFast();
_adaptive->hide(anim::type::instant);
}
}

View File

@ -166,7 +166,7 @@ void ChatSettingsWidget::createControls() {
style::margins marginPath(st::defaultCheck.diameter + st::defaultBoxCheckbox.textPosition.x(), 0, 0, st::settingsSkip);
createChildRow(_downloadPath, marginPath, slidedPadding);
if (Global::AskDownloadPath()) {
_downloadPath->hideFast();
_downloadPath->hide(anim::type::instant);
}
#endif // OS_WIN_STORE
@ -190,7 +190,9 @@ void ChatSettingsWidget::onDontAskDownloadPath() {
Global::SetAskDownloadPath(!_dontAskDownloadPath->checked());
Local::writeUserSettings();
#ifndef OS_WIN_STORE
_downloadPath->toggleAnimated(_dontAskDownloadPath->checked());
_downloadPath->toggle(
_dontAskDownloadPath->checked(),
anim::type::normal);
#endif // OS_WIN_STORE
}

View File

@ -180,7 +180,7 @@ void GeneralWidget::refreshControls() {
createChildRow(_updateRow, marginLink, slidedPadding);
connect(_updateRow->entity(), SIGNAL(restart()), this, SLOT(onRestart()));
if (!cAutoUpdate()) {
_updateRow->hideFast();
_updateRow->hide(anim::type::instant);
}
#endif // !TDESKTOP_DISABLE_AUTOUPDATE
@ -197,7 +197,7 @@ void GeneralWidget::refreshControls() {
_startMinimized->entity()->setChecked(cStartMinimized() && !Global::LocalPasscode());
});
if (!cAutoStart()) {
_startMinimized->hideFast();
_startMinimized->hide(anim::type::instant);
}
createChildRow(_addInSendTo, marginSmall, lang(lng_settings_add_sendto), [this](bool) { onAddInSendTo(); }, cSendToMenu());
#endif // OS_WIN_STORE
@ -234,7 +234,9 @@ void GeneralWidget::onRestart() {
void GeneralWidget::onUpdateAutomatically() {
cSetAutoUpdate(_updateAutomatically->checked());
Local::writeSettings();
_updateRow->toggleAnimated(cAutoUpdate());
_updateRow->toggle(
cAutoUpdate(),
anim::type::normal);
if (cAutoUpdate()) {
Sandbox::startUpdateCheck();
} else {
@ -282,7 +284,7 @@ void GeneralWidget::onAutoStart() {
Local::writeSettings();
}
}
_startMinimized->toggleAnimated(cAutoStart());
_startMinimized->toggle(cAutoStart(), anim::type::normal);
}
void GeneralWidget::onStartMinimized() {

View File

@ -143,7 +143,7 @@ void InfoWidget::setLabeledText(
copyText,
width());
}
row->toggleAnimated(nonEmptyText);
row->toggle(nonEmptyText, anim::type::normal);
}
InfoWidget::LabeledWidget::LabeledWidget(QWidget *parent, const style::FlatLabel &valueSt) : RpWidget(parent)

View File

@ -60,11 +60,11 @@ void NotificationsWidget::createControls() {
createChildRow(_showSenderName, margin, slidedPadding, lang(lng_settings_show_name), [this](bool) { onShowSenderName(); }, Global::NotifyView() <= dbinvShowName);
createChildRow(_showMessagePreview, margin, slidedPadding, lang(lng_settings_show_preview), [this](bool) { onShowMessagePreview(); }, Global::NotifyView() <= dbinvShowPreview);
if (!_showSenderName->entity()->checked()) {
_showMessagePreview->hideFast();
_showMessagePreview->hide(anim::type::instant);
}
if (!_desktopNotifications->checked()) {
_showSenderName->hideFast();
_showMessagePreview->hideFast();
_showSenderName->hide(anim::type::instant);
_showMessagePreview->hide(anim::type::instant);
}
createChildRow(_playSound, margin, lang(lng_settings_sound_notify), [this](bool) { onPlaySound(); }, Global::SoundNotify());
createChildRow(_includeMuted, margin, lang(lng_settings_include_muted), [this](bool) { onIncludeMuted(); }, Global::IncludeMuted());
@ -91,7 +91,7 @@ void NotificationsWidget::createNotificationsControls() {
}
createChildRow(_advanced, margin, slidedPadding, lang(lng_settings_advanced_notifications), SLOT(onAdvanced()));
if (!nativeNotificationsLabel.isEmpty() && Global::NativeNotifications()) {
_advanced->hideFast();
_advanced->hide(anim::type::instant);
}
}
@ -106,8 +106,13 @@ void NotificationsWidget::onDesktopNotifications() {
void NotificationsWidget::desktopEnabledUpdated() {
_desktopNotifications->setChecked(Global::DesktopNotify());
_showSenderName->toggleAnimated(Global::DesktopNotify());
_showMessagePreview->toggleAnimated(Global::DesktopNotify() && _showSenderName->entity()->checked());
_showSenderName->toggle(
Global::DesktopNotify(),
anim::type::normal);
_showMessagePreview->toggle(
Global::DesktopNotify()
&& _showSenderName->entity()->checked(),
anim::type::normal);
}
void NotificationsWidget::onShowSenderName() {
@ -146,7 +151,9 @@ void NotificationsWidget::onShowMessagePreview() {
}
void NotificationsWidget::viewParamUpdated() {
_showMessagePreview->toggleAnimated(_showSenderName->entity()->checked());
_showMessagePreview->toggle(
_showSenderName->entity()->checked(),
anim::type::normal);
}
void NotificationsWidget::onNativeNotifications() {
@ -159,7 +166,9 @@ void NotificationsWidget::onNativeNotifications() {
Auth().notifications().createManager();
_advanced->toggleAnimated(!Global::NativeNotifications());
_advanced->toggle(
!Global::NativeNotifications(),
anim::type::normal);
}
void NotificationsWidget::onAdvanced() {

View File

@ -191,7 +191,7 @@ void PrivacyWidget::createControls() {
auto value = GetAutoLockText();
createChildRow(_autoLock, marginSmall, slidedPadding, label, value, LabeledLink::Type::Primary, SLOT(onAutoLock()));
if (!Global::LocalPasscode()) {
_autoLock->hideFast();
_autoLock->hide(anim::type::instant);
}
createChildRow(_cloudPasswordState, marginSmall);
createChildRow(_showAllSessions, marginSmall, lang(lng_settings_show_sessions), SLOT(onShowSessions()));
@ -204,7 +204,9 @@ void PrivacyWidget::autoLockUpdated() {
_autoLock->entity()->link()->setText(value);
resizeToWidth(width());
}
_autoLock->toggleAnimated(Global::LocalPasscode());
_autoLock->toggle(
Global::LocalPasscode(),
anim::type::normal);
}
void PrivacyWidget::onBlockedUsers() {

View File

@ -41,7 +41,7 @@ FadeWrap<RpWidget> *FadeWrap<RpWidget>::setDuration(int duration) {
FadeWrap<RpWidget> *FadeWrap<RpWidget>::toggle(
bool shown,
anim::type animated) {
auto updated = (shown != _animation.visible());
auto changed = (shown != _animation.visible());
if (shown) {
if (animated == anim::type::normal) {
_animation.fadeIn(_duration);
@ -55,7 +55,7 @@ FadeWrap<RpWidget> *FadeWrap<RpWidget>::toggle(
_animation.hide();
}
}
if (updated) {
if (changed) {
_toggledChanged.fire_copy(shown);
}
return this;

View File

@ -55,24 +55,29 @@ SlideWrap<RpWidget> *SlideWrap<RpWidget>::setDuration(int duration) {
return this;
}
SlideWrap<RpWidget> *SlideWrap<RpWidget>::toggleAnimated(
bool shown) {
if (_shown != shown) {
setShown(shown);
_animation.start(
[this] { animationStep(); },
_shown ? 0. : 1.,
_shown ? 1. : 0.,
_duration,
anim::linear);
SlideWrap<RpWidget> *SlideWrap<RpWidget>::toggle(
bool shown,
anim::type animated) {
auto changed = (_toggled != shown);
if (changed) {
_toggled = shown;
if (animated == anim::type::normal) {
_animation.start(
[this] { animationStep(); },
_toggled ? 0. : 1.,
_toggled ? 1. : 0.,
_duration,
anim::linear);
}
}
if (animated == anim::type::normal) {
animationStep();
} else {
finishAnimating();
}
if (changed) {
_toggledChanged.fire_copy(_toggled);
}
animationStep();
return this;
}
SlideWrap<RpWidget> *SlideWrap<RpWidget>::toggleFast(bool shown) {
setShown(shown);
finishAnimating();
return this;
}
@ -86,7 +91,7 @@ SlideWrap<RpWidget> *SlideWrap<RpWidget>::toggleOn(
rpl::producer<bool> &&shown) {
std::move(shown)
| rpl::start_with_next([this](bool shown) {
toggleAnimated(shown);
toggle(shown, anim::type::normal);
}, lifetime());
finishAnimating();
return this;
@ -99,16 +104,16 @@ void SlideWrap<RpWidget>::animationStep() {
weak->moveToLeft(margins.left(), margins.top());
newWidth = weak->width();
}
auto current = _animation.current(_shown ? 1. : 0.);
auto current = _animation.current(_toggled ? 1. : 0.);
auto newHeight = wrapped()
? (_animation.animating()
? anim::interpolate(0, wrapped()->heightNoMargins(), current)
: (_shown ? wrapped()->height() : 0))
: (_toggled ? wrapped()->height() : 0))
: 0;
if (newWidth != width() || newHeight != height()) {
resize(newWidth, newHeight);
}
auto shouldBeHidden = !_shown && !_animation.animating();
auto shouldBeHidden = !_toggled && !_animation.animating();
if (shouldBeHidden != isHidden()) {
setVisible(!shouldBeHidden);
if (shouldBeHidden) {
@ -117,14 +122,9 @@ void SlideWrap<RpWidget>::animationStep() {
}
}
void SlideWrap<RpWidget>::setShown(bool shown) {
_shown = shown;
_shownUpdated.fire_copy(_shown);
}
QMargins SlideWrap<RpWidget>::getMargins() const {
auto result = wrapped()->getMargins();
return (animating() || !_shown)
return (animating() || !_toggled)
? QMargins(result.left(), 0, result.right(), 0)
: result;
}
@ -139,7 +139,7 @@ int SlideWrap<RpWidget>::resizeGetHeight(int newWidth) {
void SlideWrap<RpWidget>::wrappedSizeUpdated(QSize size) {
if (_animation.animating()) {
animationStep();
} else if (_shown) {
} else if (_toggled) {
resize(size);
}
}

View File

@ -44,39 +44,37 @@ public:
const style::margins &padding);
SlideWrap *setDuration(int duration);
SlideWrap *toggleAnimated(bool shown);
SlideWrap *toggleFast(bool shown);
SlideWrap *showAnimated() { return toggleAnimated(true); }
SlideWrap *hideAnimated() { return toggleAnimated(false); }
SlideWrap *showFast() { return toggleFast(true); }
SlideWrap *hideFast() { return toggleFast(false); }
SlideWrap *toggle(bool shown, anim::type animated);
SlideWrap *show(anim::type animated) {
return toggle(true, animated);
}
SlideWrap *hide(anim::type animated) {
return toggle(false, animated);
}
SlideWrap *finishAnimating();
SlideWrap *toggleOn(rpl::producer<bool> &&shown);
bool animating() const {
return _animation.animating();
}
bool toggled() const {
return _toggled;
}
auto toggledValue() const {
return _toggledChanged.events_starting_with_copy(_toggled);
}
QMargins getMargins() const override;
bool isHiddenOrHiding() const {
return !_shown;
}
auto shownValue() const {
return _shownUpdated.events_starting_with_copy(_shown);
}
protected:
int resizeGetHeight(int newWidth) override;
void wrappedSizeUpdated(QSize size) override;
private:
void animationStep();
void setShown(bool shown);
bool _shown = true;
rpl::event_stream<bool> _shownUpdated;
bool _toggled = true;
rpl::event_stream<bool> _toggledChanged;
Animation _animation;
int _duration = 0;
@ -107,23 +105,14 @@ public:
SlideWrap *setDuration(int duration) {
return chain(Parent::setDuration(duration));
}
SlideWrap *toggleAnimated(bool shown) {
return chain(Parent::toggleAnimated(shown));
SlideWrap *toggle(bool shown, anim::type animated) {
return chain(Parent::toggle(shown, animated));
}
SlideWrap *toggleFast(bool shown) {
return chain(Parent::toggleFast(shown));
SlideWrap *show(anim::type animated) {
return chain(Parent::show(animated));
}
SlideWrap *showAnimated() {
return chain(Parent::showAnimated());
}
SlideWrap *hideAnimated() {
return chain(Parent::hideAnimated());
}
SlideWrap *showFast() {
return chain(Parent::showFast());
}
SlideWrap *hideFast() {
return chain(Parent::hideFast());
SlideWrap *hide(anim::type animated) {
return chain(Parent::hide(animated));
}
SlideWrap *finishAnimating() {
return chain(Parent::finishAnimating());