From 03d52727262578bee98eebe325a6cdc82c451bfe Mon Sep 17 00:00:00 2001 From: Caisking <3449750381@qq.com> Date: Tue, 8 Oct 2024 17:25:38 +0800 Subject: [PATCH] =?utf8?q?=E7=B3=BB=E7=BB=9F=EF=BC=9A=E4=BF=AE=E6=94=B9lab?= =?utf8?q?el=E8=AE=BE=E7=BD=AE=E4=B8=BA=E4=B8=8D=E5=9B=A0=E4=B8=BA?= =?utf8?q?=E9=95=BF=E5=BA=A6=E6=94=B9=E5=8F=98=E6=BB=9A=E5=8A=A8=E9=80=9F?= =?utf8?q?=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../ui/frameworks/components/ui_label.cpp | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/code/sdk/middleware/services/gui/uikit/ui/frameworks/components/ui_label.cpp b/code/sdk/middleware/services/gui/uikit/ui/frameworks/components/ui_label.cpp index 0fa53ac70..3cee7ede7 100755 --- a/code/sdk/middleware/services/gui/uikit/ui/frameworks/components/ui_label.cpp +++ b/code/sdk/middleware/services/gui/uikit/ui/frameworks/components/ui_label.cpp @@ -136,28 +136,28 @@ private: uint32_t time = HALTick::GetInstance().GetElapseTime(startTime_); float x0 = startPos_; float x1 = 1.0 * labelWidth_ - textWidth_; - float factor = 200000; // slow down the speed - float t = time * speed_ / factor; - float t1 = 1.0; - float period = 2.0; - while (t < 0) { - t += period; - } - while (t > period) { - t -= period; - } + + float factor = 1000; // 1000: slow down the speed + float v = speed_ / factor; + v = x1 - x0 > 0 ? v : -v; + float t = time; + float t1 = (x1 - x0) / v; + float period = 2.0 * t1; // 2: double + t = t - float(t / period) * period; float x = 0; - if (t >=0 && t < t1) { - x = (x1 - x0) * t / t1 + x0; + if (t < t1) { + x = v * t + x0; } else { - x = (x0 - x1) * (t - t1) / t1 + x1; + x = -v * (t - t1) + x1; } + UILabel *label = dynamic_cast(view); if (label != nullptr) { label->offsetX_ = MATH_ROUND(x); label->Invalidate(); } + // printf("offsetX: %d time %d\n", label->offsetX_, time); } static constexpr uint8_t ANIM_WAIT_COUNT = 50; -- 2.17.1