Changed range of slider in footer from chart widget.

This commit is contained in:
23rd 2023-09-25 22:50:19 +03:00 committed by John Preston
parent d2578e9e47
commit 65ccb4059e
2 changed files with 21 additions and 9 deletions

View file

@ -223,6 +223,9 @@ private:
Ui::Animations::Simple _moveCenterAnimation; Ui::Animations::Simple _moveCenterAnimation;
bool _draggedAfterPress = false; bool _draggedAfterPress = false;
float64 _width = 0.;
float64 _widthBetweenSides = 0.;
PaintCallback _paintChartCallback; PaintCallback _paintChartCallback;
QImage _frame; QImage _frame;
@ -240,6 +243,9 @@ ChartWidget::Footer::Footer(not_null<Ui::RpWidget*> parent)
: RpMouseWidget(parent) { : RpMouseWidget(parent) {
sizeValue( sizeValue(
) | rpl::start_with_next([=](const QSize &s) { ) | rpl::start_with_next([=](const QSize &s) {
const auto w = float64(st::statisticsChartFooterSideWidth);
_width = s.width() - w;
_widthBetweenSides = s.width() - w * 2.;
_mask = Ui::RippleAnimation::RoundRectMask( _mask = Ui::RippleAnimation::RoundRectMask(
s - QSize(0, st::statisticsChartLineWidth * 2), s - QSize(0, st::statisticsChartLineWidth * 2),
st::boxRadius); st::boxRadius);
@ -278,7 +284,9 @@ ChartWidget::Footer::Footer(not_null<Ui::RpWidget*> parent)
} else if (_dragArea == DragArea::Left) { } else if (_dragArea == DragArea::Left) {
moveSide(true, resultX); moveSide(true, resultX);
} else if (_dragArea == DragArea::Middle) { } else if (_dragArea == DragArea::Middle) {
const auto toLeft = posX <= start().x(); const auto toLeft = (posX
- _diffBetweenStartAndSide
- _leftSide.min) <= 0;
moveCenter(toLeft, posX, _diffBetweenStartAndSide); moveCenter(toLeft, posX, _diffBetweenStartAndSide);
} }
fire(); fire();
@ -332,8 +340,9 @@ ChartWidget::Footer::Footer(not_null<Ui::RpWidget*> parent)
Limits ChartWidget::Footer::xPercentageLimits() const { Limits ChartWidget::Footer::xPercentageLimits() const {
return { return {
.min = _leftSide.min / float64(width()), .min = _leftSide.min / _widthBetweenSides,
.max = _rightSide.max / float64(width()), .max = (_rightSide.min - st::statisticsChartFooterSideWidth)
/ _widthBetweenSides,
}; };
} }
@ -346,7 +355,9 @@ void ChartWidget::Footer::moveCenter(
float64 x, float64 x,
float64 diffBetweenStartAndLeft) { float64 diffBetweenStartAndLeft) {
const auto resultX = x - diffBetweenStartAndLeft; const auto resultX = x - diffBetweenStartAndLeft;
const auto diffBetweenSides = _rightSide.min - _leftSide.min; const auto diffBetweenSides = std::max(
_rightSide.min - _leftSide.min,
float64(st::statisticsChartFooterBetweenSide));
if (isDirectionToLeft) { if (isDirectionToLeft) {
moveSide(true, resultX); moveSide(true, resultX);
moveSide(false, _leftSide.min + diffBetweenSides); moveSide(false, _leftSide.min + diffBetweenSides);
@ -358,11 +369,12 @@ void ChartWidget::Footer::moveCenter(
void ChartWidget::Footer::moveSide(bool left, float64 x) { void ChartWidget::Footer::moveSide(bool left, float64 x) {
const auto w = float64(st::statisticsChartFooterSideWidth); const auto w = float64(st::statisticsChartFooterSideWidth);
const auto mid = float64(st::statisticsChartFooterBetweenSide);
if (left) { if (left) {
const auto min = std::clamp(x, 0., _rightSide.min - w); const auto min = std::clamp(x, 0., _rightSide.min - w - mid);
_leftSide = Limits{ .min = min, .max = min + w }; _leftSide = Limits{ .min = min, .max = min + w };
} else if (!left) { } else if (!left) {
const auto min = std::clamp(x, _leftSide.max, width() - w); const auto min = std::clamp(x, _leftSide.max + mid, _width);
_rightSide = Limits{ .min = min, .max = min + w }; _rightSide = Limits{ .min = min, .max = min + w };
} }
} }
@ -467,8 +479,7 @@ void ChartWidget::Footer::paintEvent(QPaintEvent *e) {
void ChartWidget::Footer::setXPercentageLimits(const Limits &xLimits) { void ChartWidget::Footer::setXPercentageLimits(const Limits &xLimits) {
const auto left = xLimits.min * width(); const auto left = xLimits.min * width();
const auto w = float64(st::statisticsChartFooterSideWidth); const auto right = xLimits.max * _width;
const auto right = xLimits.max * width() - w;
moveSide(true, left); moveSide(true, left);
moveSide(false, right); moveSide(false, right);
fire(); fire();

View file

@ -20,7 +20,8 @@ statisticsDetailsPopupMidLineSpace: 4px;
statisticsDetailsDotRadius: 4px; statisticsDetailsDotRadius: 4px;
statisticsChartLineWidth: 2px; statisticsChartLineWidth: 2px;
statisticsChartFooterSideWidth: 22px; statisticsChartFooterBetweenSide: 5px;
statisticsChartFooterSideWidth: 10px;
statisticsChartFooterArrowSize: size(10px, 30px); statisticsChartFooterArrowSize: size(10px, 30px);
statisticsChartHorizontalLineCaptionSkip: 4px; statisticsChartHorizontalLineCaptionSkip: 4px;