From 497adc06b98d22a841b12c92ac07fe6692cda0d5 Mon Sep 17 00:00:00 2001 From: wangtiantian Date: Tue, 30 Mar 2021 15:36:35 +0800 Subject: [PATCH] IssueNo:#I3E63S Description:UITimePicker add SetLoopState interface Sig:graphic Feature or Bugfix:Bugfix Binary Source:No --- frameworks/components/ui_picker.cpp | 1 + frameworks/components/ui_time_picker.cpp | 28 +++++++++++++++++++++ interfaces/kits/components/ui_time_picker.h | 25 ++++++++++++++++++ 3 files changed, 54 insertions(+) diff --git a/frameworks/components/ui_picker.cpp b/frameworks/components/ui_picker.cpp index 2afe0d0..2f94ffa 100755 --- a/frameworks/components/ui_picker.cpp +++ b/frameworks/components/ui_picker.cpp @@ -452,6 +452,7 @@ void UIPicker::SetHeight(int16_t height) void UIPicker::SetLoopState(bool state) { list_.SetLoopState(state); + Refresh(); } void UIPicker::SetDirect(UITextLanguageDirect direct) diff --git a/frameworks/components/ui_time_picker.cpp b/frameworks/components/ui_time_picker.cpp index 89e7a2e..7246420 100755 --- a/frameworks/components/ui_time_picker.cpp +++ b/frameworks/components/ui_time_picker.cpp @@ -28,6 +28,7 @@ UITimePicker::UITimePicker() selectedMinute_{0}, selectedSecond_{0}, secVisible_(false), + loopState_{false}, setSelectedTime_(nullptr), pickerWidth_(0), itemsHeight_(0), @@ -84,12 +85,21 @@ void UITimePicker::InitTimePicker() InitPicker(minutePicker_, TIME_START, MIN_END); xPos_ *= (SEC_VISIBLE_COUNT - 1); InitPicker(secondPicker_, TIME_START, SEC_END); + if (secondPicker_ != nullptr) { + secondPicker_->SetLoopState(loopState_[PICKER_SEC]); + } } else { pickerWidth_ = GetWidth() / SEC_INVISIBLE_COUNT; InitPicker(hourPicker_, TIME_START, HOUR_END); xPos_ = pickerWidth_; InitPicker(minutePicker_, TIME_START, MIN_END); } + if (hourPicker_ != nullptr) { + hourPicker_->SetLoopState(loopState_[PICKER_HOUR]); + } + if (minutePicker_ != nullptr) { + minutePicker_->SetLoopState(loopState_[PICKER_MIN]); + } if (setSelectedTime_ == nullptr) { const char* curTime = secVisible_ ? "00:00:00" : "00:00"; @@ -288,4 +298,22 @@ void UITimePicker::SetHeight(int16_t height) UIView::SetHeight(height); RefreshTimePicker(); } + +void UITimePicker::SetLoopState(const uint8_t pickerType, bool state) +{ + switch (pickerType) { + case PICKER_HOUR: + loopState_[PICKER_HOUR] = state; + break; + case PICKER_MIN: + loopState_[PICKER_MIN] = state; + break; + case PICKER_SEC: + loopState_[PICKER_SEC] = state; + break; + default: + return; + } + RefreshTimePicker(); +} } diff --git a/interfaces/kits/components/ui_time_picker.h b/interfaces/kits/components/ui_time_picker.h index 91cf392..88f8a7e 100755 --- a/interfaces/kits/components/ui_time_picker.h +++ b/interfaces/kits/components/ui_time_picker.h @@ -52,6 +52,19 @@ public: static constexpr const char* MIN_LIST_NAME = "minute"; static constexpr const char* SEC_LIST_NAME = "second"; #endif + /** + * 枚举Picker类型 + */ + enum PickerType : uint8_t { + /* 时 */ + PICKER_HOUR = 0, + /* 分 */ + PICKER_MIN, + /* 秒 */ + PICKER_SEC, + /* 最大值 */ + PICKER_MAX, + }; /** * @brief A constructor used to create a UITimePicker instance. * @@ -223,6 +236,17 @@ public: */ void SetHeight(int16_t height) override; + /** + * @brief 设置是否开启循环 + * + * @param pickerType Picker类型 + * @param state 状态 + * + * @since 3.0 + * @version 5.0 + */ + void SetLoopState(const uint8_t pickerType, bool state); + /** * @brief Defines the listener used by the time picker. This listener is triggered when an item is selected * after sliding stops. @@ -315,6 +339,7 @@ private: char selectedMinute_[BUF_SIZE]; char selectedSecond_[BUF_SIZE]; bool secVisible_; + bool loopState_[PICKER_MAX]; const char* setSelectedTime_; uint16_t pickerWidth_; uint16_t itemsHeight_; -- GitLab