提交 94fdde3a 编写于 作者: N niulihua 提交者: Gitee

!61 UITimePicker增加设置循环接口

Merge pull request !61 from wangtiantian/MyMaster_timepicker
......@@ -452,6 +452,7 @@ void UIPicker::SetHeight(int16_t height)
void UIPicker::SetLoopState(bool state)
{
list_.SetLoopState(state);
Refresh();
}
void UIPicker::SetDirect(UITextLanguageDirect direct)
......
......@@ -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();
}
}
......@@ -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 <b>UITimePicker</b> 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_;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册