From b05041dbd07d3ab2559fa3dcc0ae411a35d81490 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9a=20Saviot?= Date: Mon, 2 Sep 2019 15:45:21 +0200 Subject: [PATCH] [apps/shared] Add display margin on top of / below constant curve --- apps/shared/interactive_curve_view_range_delegate.cpp | 6 ++++++ apps/shared/memoized_curve_view_range.h | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/apps/shared/interactive_curve_view_range_delegate.cpp b/apps/shared/interactive_curve_view_range_delegate.cpp index 0c78f3dc2..1f61f1e5d 100644 --- a/apps/shared/interactive_curve_view_range_delegate.cpp +++ b/apps/shared/interactive_curve_view_range_delegate.cpp @@ -22,6 +22,12 @@ bool InteractiveCurveViewRangeDelegate::didChangeRange(InteractiveCurveViewRange if (interactiveCurveViewRange->yMin() == addMargin(min, range, true) && interactiveCurveViewRange->yMax() == addMargin(max, range, false)) { return false; } + if (min == max) { + // Add same margin on top of / below the curve, to center it on the screen + float step = max != 0.0f ? 2.0f * interactiveCurveViewRange->defaultRangeLengthFor(max) : 1.0f; + min = min - step; + max = max + step; + } if (min == FLT_MAX && max == -FLT_MAX) { min = -1.0f; max = 1.0f; diff --git a/apps/shared/memoized_curve_view_range.h b/apps/shared/memoized_curve_view_range.h index e3a78998b..3b5ff15f9 100644 --- a/apps/shared/memoized_curve_view_range.h +++ b/apps/shared/memoized_curve_view_range.h @@ -19,9 +19,9 @@ public: virtual void setXMax(float f); virtual void setYMin(float f); virtual void setYMax(float f); + float defaultRangeLengthFor(float position) const; protected: - float defaultRangeLengthFor(float position) const; // Window bounds of the data float m_xMin; float m_xMax;