diff --git a/frameworks/components/ui_picker.cpp b/frameworks/components/ui_picker.cpp index 2afe0d01a3f616dd254cb5e270c98a6b351bbf39..2f94ffa86fc5c04d61102c9bf4460bfd644a86bd 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 89e7a2ea42c51e0b2b71cfef45c236b908b23d64..7246420edc419b3aef5765328a2c3804a1f99ca1 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 91cf392e7eedf8c896be4b840fe09f8fb39f3db2..88f8a7ece4df9111d6e956bd813e484497596a0d 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_;