Scroll to active tab in subsection tabs.

This commit is contained in:
John Preston 2025-07-01 15:10:21 +04:00
parent 7e8a152eef
commit eccfd75a83
3 changed files with 39 additions and 1 deletions

View file

@ -234,6 +234,28 @@ void SubsectionTabs::setupSlider(
}
}, slider->lifetime());
slider->requestShown(
) | rpl::start_with_next([=](Ui::ScrollToRequest request) {
const auto full = vertical ? scroll->height() : scroll->width();
const auto scrollValue = vertical
? scroll->scrollTop()
: scroll->scrollLeft();
if (request.ymin < scrollValue) {
if (vertical) {
scroll->scrollToY(request.ymin);
} else {
scroll->scrollToX(request.ymin);
}
} else if (request.ymax > scrollValue + full) {
const auto value = std::min(request.ymin, request.ymax - full);
if (vertical) {
scroll->scrollToY(value);
} else {
scroll->scrollToX(value);
}
}
}, slider->lifetime());
rpl::merge(
scroll->scrolls(),
_scrollCheckRequests.events(),

View file

@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "dialogs/dialogs_three_state_icon.h"
#include "ui/effects/ripple_animation.h"
#include "ui/widgets/scroll_area.h"
#include "ui/dynamic_image.h"
#include "ui/unread_badge_paint.h"
#include "styles/style_chat.h"
@ -383,24 +384,34 @@ void SubsectionSlider::activate(int index) {
}
}
};
const auto weak = Ui::MakeWeak(_bar);
const auto weak = MakeWeak(_bar);
_sectionActivated.fire_copy(index);
if (weak) {
const auto duration = st::chatTabsSlider.duration;
_activeFrom.start(callback, was.from, now.from, duration);
_activeSize.start(callback, was.size, now.size, duration);
_requestShown.fire_copy({ now.from, now.from + now.size });
}
}
void SubsectionSlider::setActiveSectionFast(int active) {
Expects(active < int(_tabs.size()));
if (_active == active) {
return;
}
_active = active;
_activeFrom.stop();
_activeSize.stop();
const auto now = getFinalActiveRange();
_requestShown.fire({ now.from, now.from + now.size });
_bar->update();
}
rpl::producer<ScrollToRequest> SubsectionSlider::requestShown() const {
return _requestShown.events();
}
int SubsectionSlider::sectionsCount() const {
return int(_tabs.size());
}

View file

@ -22,6 +22,7 @@ namespace Ui {
class DynamicImage;
class RippleAnimation;
class SubsectionButton;
struct ScrollToRequest;
struct SubsectionTab {
TextWithEntities text;
@ -95,6 +96,8 @@ public:
Text::MarkedContext buttonContext() override;
[[nodiscard]] not_null<SubsectionButton*> buttonAt(int index);
[[nodiscard]] rpl::producer<ScrollToRequest> requestShown() const;
protected:
struct Range {
int from = 0;
@ -137,6 +140,8 @@ protected:
rpl::event_stream<int> _sectionContextMenu;
Fn<bool()> _paused;
rpl::event_stream<ScrollToRequest> _requestShown;
};
class VerticalSlider final : public SubsectionSlider {