提交 1d5e643d 编写于 作者: Y YueBiang

fix slider bugs

上级 6441b10a
...@@ -107,31 +107,71 @@ void UIBoxProgress::DrawRoundCap(const Image* image, const Point& imgPos, const ...@@ -107,31 +107,71 @@ void UIBoxProgress::DrawRoundCap(const Image* image, const Point& imgPos, const
Style capStyle = style; Style capStyle = style;
capStyle.lineWidth_ = radius; capStyle.lineWidth_ = radius;
capStyle.lineColor_ = style.bgColor_; capStyle.lineColor_ = style.bgColor_;
capStyle.lineOpa_ = style.bgOpa_; if ((image != nullptr) && (image->GetSrcType() != IMG_SRC_UNKNOWN)) {
capStyle.lineOpa_ = style.imageOpa_;
} else {
capStyle.lineOpa_ = style.bgOpa_;
}
ArcInfo arcInfo = {{0}}; ArcInfo arcInfo = {{0}};
arcInfo.radius = radius; arcInfo.radius = radius;
arcInfo.imgPos = imgPos; arcInfo.imgPos = imgPos;
arcInfo.imgSrc = image; arcInfo.imgSrc = image;
arcInfo.center = leftTop; if (rect.GetWidth() % 2 == 0) { // 2: determine the odd or even number of the width
arcInfo.startAngle = THREE_QUARTER_IN_DEGREE; arcInfo.center = leftTop;
arcInfo.endAngle = 0; arcInfo.startAngle = THREE_QUARTER_IN_DEGREE;
DrawArc::GetInstance()->Draw(arcInfo, invalidatedArea, capStyle, opaScale_, CapType::CAP_NONE); arcInfo.endAngle = 0;
DrawArc::GetInstance()->Draw(arcInfo, invalidatedArea, capStyle, opaScale_, CapType::CAP_NONE);
arcInfo.center = leftBottom;
arcInfo.startAngle = SEMICIRCLE_IN_DEGREE; arcInfo.center = leftBottom;
arcInfo.endAngle = THREE_QUARTER_IN_DEGREE; arcInfo.startAngle = SEMICIRCLE_IN_DEGREE;
DrawArc::GetInstance()->Draw(arcInfo, invalidatedArea, capStyle, opaScale_, CapType::CAP_NONE); arcInfo.endAngle = THREE_QUARTER_IN_DEGREE;
DrawArc::GetInstance()->Draw(arcInfo, invalidatedArea, capStyle, opaScale_, CapType::CAP_NONE);
arcInfo.center = rightTop;
arcInfo.startAngle = 0; arcInfo.center = rightTop;
arcInfo.endAngle = THREE_QUARTER_IN_DEGREE; arcInfo.startAngle = 0;
DrawArc::GetInstance()->Draw(arcInfo, invalidatedArea, capStyle, opaScale_, CapType::CAP_NONE); arcInfo.endAngle = QUARTER_IN_DEGREE;
DrawArc::GetInstance()->Draw(arcInfo, invalidatedArea, capStyle, opaScale_, CapType::CAP_NONE);
arcInfo.center = rightBottom;
arcInfo.startAngle = THREE_QUARTER_IN_DEGREE; arcInfo.center = rightBottom;
arcInfo.endAngle = SEMICIRCLE_IN_DEGREE; arcInfo.startAngle = QUARTER_IN_DEGREE;
DrawArc::GetInstance()->Draw(arcInfo, invalidatedArea, capStyle, opaScale_, CapType::CAP_NONE); arcInfo.endAngle = SEMICIRCLE_IN_DEGREE;
DrawArc::GetInstance()->Draw(arcInfo, invalidatedArea, capStyle, opaScale_, CapType::CAP_NONE);
} else {
switch (direction_) {
case Direction::DIR_LEFT_TO_RIGHT:
case Direction::DIR_RIGHT_TO_LEFT: {
arcInfo.center = leftTop;
arcInfo.startAngle = SEMICIRCLE_IN_DEGREE;
arcInfo.endAngle = 0;
DrawArc::GetInstance()->Draw(arcInfo, invalidatedArea, capStyle, opaScale_, CapType::CAP_NONE);
arcInfo.center = leftBottom;
arcInfo.startAngle = 0;
arcInfo.endAngle = SEMICIRCLE_IN_DEGREE;
DrawArc::GetInstance()->Draw(arcInfo, invalidatedArea, capStyle, opaScale_, CapType::CAP_NONE);
break;
}
case Direction::DIR_TOP_TO_BOTTOM:
case Direction::DIR_BOTTOM_TO_TOP: {
arcInfo.center = leftTop;
arcInfo.startAngle = THREE_QUARTER_IN_DEGREE;
arcInfo.endAngle = QUARTER_IN_DEGREE;
DrawArc::GetInstance()->Draw(arcInfo, invalidatedArea, capStyle, opaScale_, CapType::CAP_NONE);
arcInfo.center = leftBottom;
arcInfo.startAngle = QUARTER_IN_DEGREE;
arcInfo.endAngle = THREE_QUARTER_IN_DEGREE;
DrawArc::GetInstance()->Draw(arcInfo, invalidatedArea, capStyle, opaScale_, CapType::CAP_NONE);
break;
}
default:
GRAPHIC_LOGE("UIBoxProgress: DrawRoundCap direction Err!\n");
break;
}
}
} }
void UIBoxProgress::GetBackgroundParam(Point& startPoint, int16_t& width, int16_t& height, uint16_t& radius, void UIBoxProgress::GetBackgroundParam(Point& startPoint, int16_t& width, int16_t& height, uint16_t& radius,
......
...@@ -30,16 +30,16 @@ UISlider::UISlider() ...@@ -30,16 +30,16 @@ UISlider::UISlider()
touchable_ = true; touchable_ = true;
draggable_ = true; draggable_ = true;
dragParentInstead_ = false; dragParentInstead_ = false;
SetCapType(CapType::CAP_ROUND);
Theme* theme = ThemeManager::GetInstance().GetCurrent();
if (theme != nullptr) {
knobStyle_ = &(theme->GetSliderKnobStyle());
} else {
knobStyle_ = &(StyleDefault::GetSliderKnobStyle());
}
#if ENABLE_FOCUS_MANAGER #if ENABLE_FOCUS_MANAGER
focusable_ = true; focusable_ = true;
#endif #endif
SetBackgroundStyle(STYLE_LINE_CAP, CapType::CAP_ROUND);
SetBackgroundStyle(STYLE_BACKGROUND_OPA, BACKGROUND_OPA);
SetBackgroundStyle(STYLE_BACKGROUND_COLOR, Color::Black().full);
SetForegroundStyle(STYLE_LINE_CAP, CapType::CAP_ROUND);
SetForegroundStyle(STYLE_BACKGROUND_COLOR,
Color::GetColorFromRGB(FOREGROUND_COLOR_R, FOREGROUND_COLOR_G, FOREGROUND_COLOR_B).full);
} }
UISlider::~UISlider() UISlider::~UISlider()
...@@ -220,7 +220,7 @@ void UISlider::DrawForeground(const Rect& invalidatedArea, Rect& coords) ...@@ -220,7 +220,7 @@ void UISlider::DrawForeground(const Rect& invalidatedArea, Rect& coords)
switch (direction_) { switch (direction_) {
case Direction::DIR_LEFT_TO_RIGHT: { case Direction::DIR_LEFT_TO_RIGHT: {
length = GetCurrentPos(progressWidth_ - 1); length = GetCurrentPos(progressWidth_ + 1);
coords.SetRect(startPoint.x, startPoint.y, startPoint.x + progressWidth - 1, coords.SetRect(startPoint.x, startPoint.y, startPoint.x + progressWidth - 1,
startPoint.y + progressHeight_ - 1); startPoint.y + progressHeight_ - 1);
...@@ -230,7 +230,7 @@ void UISlider::DrawForeground(const Rect& invalidatedArea, Rect& coords) ...@@ -230,7 +230,7 @@ void UISlider::DrawForeground(const Rect& invalidatedArea, Rect& coords)
break; break;
} }
case Direction::DIR_RIGHT_TO_LEFT: { case Direction::DIR_RIGHT_TO_LEFT: {
length = GetCurrentPos(progressWidth_ - 1); length = GetCurrentPos(progressWidth_ + 1);
coords.SetRect(startPoint.x, startPoint.y, startPoint.x + progressWidth - 1, coords.SetRect(startPoint.x, startPoint.y, startPoint.x + progressWidth - 1,
startPoint.y + progressHeight_ - 1); startPoint.y + progressHeight_ - 1);
...@@ -240,17 +240,17 @@ void UISlider::DrawForeground(const Rect& invalidatedArea, Rect& coords) ...@@ -240,17 +240,17 @@ void UISlider::DrawForeground(const Rect& invalidatedArea, Rect& coords)
break; break;
} }
case Direction::DIR_TOP_TO_BOTTOM: { case Direction::DIR_TOP_TO_BOTTOM: {
length = GetCurrentPos(progressHeight_ - 1); length = GetCurrentPos(progressHeight_ + 1);
coords.SetRect(startPoint.x, startPoint.y, startPoint.x + progressWidth_ - 1, coords.SetRect(startPoint.x, startPoint.y, startPoint.x + progressWidth_ - 1,
startPoint.y + progressHeight - 1); startPoint.y + progressHeight - 1);
top = startPoint.y - radius + 1; top = startPoint.y - radius - 1;
bottom = top + length; bottom = top + length;
rect = Rect(startPoint.x, top, startPoint.x + progressWidth_ - 1, bottom); rect = Rect(startPoint.x, top, startPoint.x + progressWidth_ - 1, bottom);
break; break;
} }
case Direction::DIR_BOTTOM_TO_TOP: { case Direction::DIR_BOTTOM_TO_TOP: {
length = GetCurrentPos(progressHeight_ - 1); length = GetCurrentPos(progressHeight_ + 1);
coords.SetRect(startPoint.x, startPoint.y, startPoint.x + progressWidth_ - 1, coords.SetRect(startPoint.x, startPoint.y, startPoint.x + progressWidth_ - 1,
startPoint.y + progressHeight - 1); startPoint.y + progressHeight - 1);
......
...@@ -343,6 +343,10 @@ protected: ...@@ -343,6 +343,10 @@ protected:
bool InitImage() override; bool InitImage() override;
private: private:
static constexpr int8_t BACKGROUND_OPA = 38;
static constexpr uint8_t FOREGROUND_COLOR_R = 0x1f;
static constexpr uint8_t FOREGROUND_COLOR_G = 0x71;
static constexpr uint8_t FOREGROUND_COLOR_B = 0xff;
#if ENABLE_SLIDER_KNOB #if ENABLE_SLIDER_KNOB
void DrawKnob(const Rect& invalidatedArea, const Rect& foregroundRect); void DrawKnob(const Rect& invalidatedArea, const Rect& foregroundRect);
#else #else
......
...@@ -479,30 +479,33 @@ bool UITestSlider::ExpandClick1(UIView& view, const ClickEvent& event) ...@@ -479,30 +479,33 @@ bool UITestSlider::ExpandClick1(UIView& view, const ClickEvent& event)
g_height = DEFAULT_WIDTH; g_height = DEFAULT_WIDTH;
slider_->SetValidHeight(g_height); slider_->SetValidHeight(g_height);
slider_->SetValidWidth(g_width); slider_->SetValidWidth(g_width);
slider_->LayoutCenterOfParent();
slider_->Resize(g_width, g_height); slider_->Resize(g_width, g_height);
slider_->SetDirection(UISlider::Direction::DIR_LEFT_TO_RIGHT); slider_->SetDirection(UISlider::Direction::DIR_LEFT_TO_RIGHT);
slider_->LayoutCenterOfParent();
} else if (&view == dirR2LBtn_) { } else if (&view == dirR2LBtn_) {
g_width = DEFAULT_HEIGHT; g_width = DEFAULT_HEIGHT;
g_height = DEFAULT_WIDTH; g_height = DEFAULT_WIDTH;
slider_->SetValidHeight(g_height); slider_->SetValidHeight(g_height);
slider_->SetValidWidth(g_width); slider_->SetValidWidth(g_width);
slider_->LayoutCenterOfParent();
slider_->Resize(g_width, g_height); slider_->Resize(g_width, g_height);
slider_->SetDirection(UISlider::Direction::DIR_RIGHT_TO_LEFT); slider_->SetDirection(UISlider::Direction::DIR_RIGHT_TO_LEFT);
slider_->LayoutCenterOfParent();
} else if (&view == dirT2BBtn_) { } else if (&view == dirT2BBtn_) {
g_width = DEFAULT_WIDTH; g_width = DEFAULT_WIDTH;
g_height = DEFAULT_HEIGHT; g_height = DEFAULT_HEIGHT;
slider_->SetValidHeight(g_height);
slider_->SetValidWidth(g_width);
slider_->Resize(g_width, g_height); slider_->Resize(g_width, g_height);
slider_->SetDirection(UISlider::Direction::DIR_TOP_TO_BOTTOM); slider_->SetDirection(UISlider::Direction::DIR_TOP_TO_BOTTOM);
slider_->LayoutCenterOfParent();
} else if (&view == dirB2TBtn_) { } else if (&view == dirB2TBtn_) {
g_width = DEFAULT_WIDTH; g_width = DEFAULT_WIDTH;
g_height = DEFAULT_HEIGHT; g_height = DEFAULT_HEIGHT;
slider_->SetValidHeight(g_height); slider_->SetValidHeight(g_height);
slider_->SetValidWidth(g_width); slider_->SetValidWidth(g_width);
slider_->LayoutCenterOfParent();
slider_->Resize(g_width, g_height); slider_->Resize(g_width, g_height);
slider_->SetDirection(UISlider::Direction::DIR_BOTTOM_TO_TOP); slider_->SetDirection(UISlider::Direction::DIR_BOTTOM_TO_TOP);
slider_->LayoutCenterOfParent();
} else { } else {
ExpandClick2(view, event); ExpandClick2(view, event);
} }
...@@ -529,9 +532,9 @@ bool UITestSlider::ExpandClick2(UIView& view, const ClickEvent& event) ...@@ -529,9 +532,9 @@ bool UITestSlider::ExpandClick2(UIView& view, const ClickEvent& event)
#endif #endif
} else if (&view == setStyleBtn_) { } else if (&view == setStyleBtn_) {
Style style = StyleDefault::GetDefaultStyle(); Style style = StyleDefault::GetDefaultStyle();
style.bgColor_ = Color::White(); style.bgColor_ = Color::Green();
slider_->SetBackgroundStyle(style); slider_->SetBackgroundStyle(style);
style.bgColor_ = Color::Blue(); style.bgColor_ = Color::Red();
slider_->SetForegroundStyle(style); slider_->SetForegroundStyle(style);
style.bgColor_ = Color::Gray(); style.bgColor_ = Color::Gray();
#if ENABLE_SLIDER_KNOB #if ENABLE_SLIDER_KNOB
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册