Added scroll to active and not completely visible SideBarButtons.
This commit is contained in:
parent
deb76f38d7
commit
49e286b04c
|
@ -122,8 +122,10 @@ void FiltersMenu::setup() {
|
|||
const auto j = _filters.find(_activeFilterId);
|
||||
if (j != end(_filters)) {
|
||||
j->second->setActive(true);
|
||||
scrollToButton(j->second);
|
||||
} else if (!_activeFilterId) {
|
||||
_all->setActive(true);
|
||||
scrollToButton(_all);
|
||||
}
|
||||
}, _outer.lifetime());
|
||||
|
||||
|
@ -132,6 +134,32 @@ void FiltersMenu::setup() {
|
|||
});
|
||||
}
|
||||
|
||||
void FiltersMenu::scrollToButton(not_null<Ui::RpWidget*> widget) {
|
||||
const auto globalPosition = widget->mapToGlobal(QPoint(0, 0));
|
||||
const auto localTop = _scroll.mapFromGlobal(globalPosition).y();
|
||||
const auto localBottom = localTop + widget->height() - _scroll.height();
|
||||
const auto isTopEdge = (localTop < 0);
|
||||
const auto isBottomEdge = (localBottom > 0);
|
||||
if (!isTopEdge && !isBottomEdge) {
|
||||
return;
|
||||
}
|
||||
|
||||
_scrollToAnimation.stop();
|
||||
const auto scrollTop = _scroll.scrollTop();
|
||||
const auto scrollTo = scrollTop + (isBottomEdge ? localBottom : localTop);
|
||||
|
||||
auto scroll = [=] {
|
||||
_scroll.scrollToY(qRound(_scrollToAnimation.value(scrollTo)));
|
||||
};
|
||||
|
||||
_scrollToAnimation.start(
|
||||
std::move(scroll),
|
||||
scrollTop,
|
||||
scrollTo,
|
||||
st::slideDuration,
|
||||
anim::sineInOut);
|
||||
}
|
||||
|
||||
void FiltersMenu::refresh() {
|
||||
const auto filters = &_session->session().data().chatsFilters();
|
||||
if (filters->list().empty() || _ignoreRefresh) {
|
||||
|
|
|
@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
*/
|
||||
#pragma once
|
||||
|
||||
#include "ui/effects/animations.h"
|
||||
#include "ui/widgets/side_bar_button.h"
|
||||
#include "ui/widgets/scroll_area.h"
|
||||
#include "ui/wrap/vertical_layout.h"
|
||||
|
@ -49,6 +50,7 @@ private:
|
|||
void showEditBox(FilterId id);
|
||||
void showRemoveBox(FilterId id);
|
||||
void remove(FilterId id);
|
||||
void scrollToButton(not_null<Ui::RpWidget*> widget);
|
||||
|
||||
const not_null<SessionController*> _session;
|
||||
const not_null<Ui::RpWidget*> _parent;
|
||||
|
@ -68,6 +70,8 @@ private:
|
|||
|
||||
base::unique_qptr<Ui::PopupMenu> _popupMenu;
|
||||
|
||||
Ui::Animations::Simple _scrollToAnimation;
|
||||
|
||||
};
|
||||
|
||||
} // namespace Window
|
||||
|
|
Loading…
Reference in New Issue