mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-07-26 07:23:02 +02:00
Scroll to active tab in subsection tabs.
This commit is contained in:
parent
7e8a152eef
commit
eccfd75a83
3 changed files with 39 additions and 1 deletions
|
@ -234,6 +234,28 @@ void SubsectionTabs::setupSlider(
|
||||||
}
|
}
|
||||||
}, slider->lifetime());
|
}, 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(
|
rpl::merge(
|
||||||
scroll->scrolls(),
|
scroll->scrolls(),
|
||||||
_scrollCheckRequests.events(),
|
_scrollCheckRequests.events(),
|
||||||
|
|
|
@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
|
|
||||||
#include "dialogs/dialogs_three_state_icon.h"
|
#include "dialogs/dialogs_three_state_icon.h"
|
||||||
#include "ui/effects/ripple_animation.h"
|
#include "ui/effects/ripple_animation.h"
|
||||||
|
#include "ui/widgets/scroll_area.h"
|
||||||
#include "ui/dynamic_image.h"
|
#include "ui/dynamic_image.h"
|
||||||
#include "ui/unread_badge_paint.h"
|
#include "ui/unread_badge_paint.h"
|
||||||
#include "styles/style_chat.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);
|
_sectionActivated.fire_copy(index);
|
||||||
if (weak) {
|
if (weak) {
|
||||||
const auto duration = st::chatTabsSlider.duration;
|
const auto duration = st::chatTabsSlider.duration;
|
||||||
_activeFrom.start(callback, was.from, now.from, duration);
|
_activeFrom.start(callback, was.from, now.from, duration);
|
||||||
_activeSize.start(callback, was.size, now.size, duration);
|
_activeSize.start(callback, was.size, now.size, duration);
|
||||||
|
_requestShown.fire_copy({ now.from, now.from + now.size });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SubsectionSlider::setActiveSectionFast(int active) {
|
void SubsectionSlider::setActiveSectionFast(int active) {
|
||||||
Expects(active < int(_tabs.size()));
|
Expects(active < int(_tabs.size()));
|
||||||
|
|
||||||
|
if (_active == active) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
_active = active;
|
_active = active;
|
||||||
_activeFrom.stop();
|
_activeFrom.stop();
|
||||||
_activeSize.stop();
|
_activeSize.stop();
|
||||||
|
const auto now = getFinalActiveRange();
|
||||||
|
_requestShown.fire({ now.from, now.from + now.size });
|
||||||
_bar->update();
|
_bar->update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rpl::producer<ScrollToRequest> SubsectionSlider::requestShown() const {
|
||||||
|
return _requestShown.events();
|
||||||
|
}
|
||||||
|
|
||||||
int SubsectionSlider::sectionsCount() const {
|
int SubsectionSlider::sectionsCount() const {
|
||||||
return int(_tabs.size());
|
return int(_tabs.size());
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,7 @@ namespace Ui {
|
||||||
class DynamicImage;
|
class DynamicImage;
|
||||||
class RippleAnimation;
|
class RippleAnimation;
|
||||||
class SubsectionButton;
|
class SubsectionButton;
|
||||||
|
struct ScrollToRequest;
|
||||||
|
|
||||||
struct SubsectionTab {
|
struct SubsectionTab {
|
||||||
TextWithEntities text;
|
TextWithEntities text;
|
||||||
|
@ -95,6 +96,8 @@ public:
|
||||||
Text::MarkedContext buttonContext() override;
|
Text::MarkedContext buttonContext() override;
|
||||||
[[nodiscard]] not_null<SubsectionButton*> buttonAt(int index);
|
[[nodiscard]] not_null<SubsectionButton*> buttonAt(int index);
|
||||||
|
|
||||||
|
[[nodiscard]] rpl::producer<ScrollToRequest> requestShown() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
struct Range {
|
struct Range {
|
||||||
int from = 0;
|
int from = 0;
|
||||||
|
@ -137,6 +140,8 @@ protected:
|
||||||
rpl::event_stream<int> _sectionContextMenu;
|
rpl::event_stream<int> _sectionContextMenu;
|
||||||
Fn<bool()> _paused;
|
Fn<bool()> _paused;
|
||||||
|
|
||||||
|
rpl::event_stream<ScrollToRequest> _requestShown;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class VerticalSlider final : public SubsectionSlider {
|
class VerticalSlider final : public SubsectionSlider {
|
||||||
|
|
Loading…
Add table
Reference in a new issue