提交 12ed1ba1 编写于 作者: Y YueBiang

fix slider bugs

Signed-off-by: NYueBiang <suyue7@huawei.com>
上级 f6b28f28
...@@ -32,7 +32,7 @@ constexpr float DEFAULT_SLIDER_ROTATE_FACTOR = -0.1; ...@@ -32,7 +32,7 @@ constexpr float DEFAULT_SLIDER_ROTATE_FACTOR = -0.1;
} }
namespace OHOS { namespace OHOS {
UISlider::UISlider() UISlider::UISlider()
: knobWidth_(0), knobWidthSetFlag_(false), knobStyleAllocFlag_(false), knobImage_(nullptr), listener_(nullptr) : knobWidth_(0), knobStyleAllocFlag_(false), knobImage_(nullptr), listener_(nullptr)
{ {
touchable_ = true; touchable_ = true;
draggable_ = true; draggable_ = true;
...@@ -43,12 +43,13 @@ UISlider::UISlider() ...@@ -43,12 +43,13 @@ UISlider::UISlider()
#if ENABLE_ROTATE_INPUT #if ENABLE_ROTATE_INPUT
rotateFactor_ = DEFAULT_SLIDER_ROTATE_FACTOR; rotateFactor_ = DEFAULT_SLIDER_ROTATE_FACTOR;
#endif #endif
SetBackgroundStyle(STYLE_LINE_CAP, CapType::CAP_ROUND);
SetBackgroundStyle(STYLE_BACKGROUND_OPA, BACKGROUND_OPA); Theme* theme = ThemeManager::GetInstance().GetCurrent();
SetBackgroundStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); if (theme != nullptr) {
SetForegroundStyle(STYLE_LINE_CAP, CapType::CAP_ROUND); knobStyle_ = &(theme->GetSliderKnobStyle());
SetForegroundStyle(STYLE_BACKGROUND_COLOR, } else {
Color::GetColorFromRGB(FOREGROUND_COLOR_R, FOREGROUND_COLOR_G, FOREGROUND_COLOR_B).full); knobStyle_ = &(StyleDefault::GetSliderKnobStyle());
}
} }
UISlider::~UISlider() UISlider::~UISlider()
...@@ -101,39 +102,22 @@ int64_t UISlider::GetKnobStyle(uint8_t key) const ...@@ -101,39 +102,22 @@ int64_t UISlider::GetKnobStyle(uint8_t key) const
return knobStyle_->GetStyle(key); return knobStyle_->GetStyle(key);
} }
int16_t UISlider::GetKnobWidth() void UISlider::SetKnobImage(const ImageInfo* knobImage)
{
if (!knobWidthSetFlag_) {
if ((direction_ == Direction::DIR_LEFT_TO_RIGHT) || (direction_ == Direction::DIR_RIGHT_TO_LEFT)) {
knobWidth_ = progressHeight_;
} else {
knobWidth_ = progressWidth_;
}
}
return knobWidth_;
}
void UISlider::SetImage(const ImageInfo* backgroundImage, const ImageInfo* foregroundImage, const ImageInfo* knobImage)
{ {
if (!InitImage()) { if (!InitImage()) {
return; return;
} }
backgroundImage_->SetSrc(backgroundImage);
foregroundImage_->SetSrc(foregroundImage);
knobImage_->SetSrc(knobImage); knobImage_->SetSrc(knobImage);
} }
void UISlider::SetImage(const char* backgroundImage, const char* foregroundImage, const char* knobImage) void UISlider::SetKnobImage(const char* knobImage)
{ {
if (!InitImage()) { if (!InitImage()) {
return; return;
} }
backgroundImage_->SetSrc(backgroundImage);
foregroundImage_->SetSrc(foregroundImage);
knobImage_->SetSrc(knobImage); knobImage_->SetSrc(knobImage);
} }
#if ENABLE_SLIDER_KNOB
void UISlider::DrawKnob(BufferInfo& gfxDstBuffer, const Rect& invalidatedArea, const Rect& foregroundRect) void UISlider::DrawKnob(BufferInfo& gfxDstBuffer, const Rect& invalidatedArea, const Rect& foregroundRect)
{ {
int16_t halfKnobWidth = GetKnobWidth() >> 1; int16_t halfKnobWidth = GetKnobWidth() >> 1;
...@@ -143,25 +127,25 @@ void UISlider::DrawKnob(BufferInfo& gfxDstBuffer, const Rect& invalidatedArea, c ...@@ -143,25 +127,25 @@ void UISlider::DrawKnob(BufferInfo& gfxDstBuffer, const Rect& invalidatedArea, c
case Direction::DIR_LEFT_TO_RIGHT: { case Direction::DIR_LEFT_TO_RIGHT: {
offset = (knobWidth_ - progressHeight_) >> 1; offset = (knobWidth_ - progressHeight_) >> 1;
knobBar.SetRect(foregroundRect.GetRight() - halfKnobWidth, foregroundRect.GetTop() - offset, knobBar.SetRect(foregroundRect.GetRight() - halfKnobWidth, foregroundRect.GetTop() - offset,
foregroundRect.GetRight() + halfKnobWidth, foregroundRect.GetBottom() + offset); foregroundRect.GetRight() + halfKnobWidth, foregroundRect.GetBottom() + offset);
break; break;
} }
case Direction::DIR_RIGHT_TO_LEFT: { case Direction::DIR_RIGHT_TO_LEFT: {
offset = (knobWidth_ - progressHeight_) >> 1; offset = (knobWidth_ - progressHeight_) >> 1;
knobBar.SetRect(foregroundRect.GetLeft() - halfKnobWidth, foregroundRect.GetTop() - offset, knobBar.SetRect(foregroundRect.GetLeft() - halfKnobWidth, foregroundRect.GetTop() - offset,
foregroundRect.GetLeft() + halfKnobWidth, foregroundRect.GetBottom() + offset); foregroundRect.GetLeft() + halfKnobWidth, foregroundRect.GetBottom() + offset);
break; break;
} }
case Direction::DIR_BOTTOM_TO_TOP: { case Direction::DIR_BOTTOM_TO_TOP: {
offset = (knobWidth_ - progressWidth_) >> 1; offset = (knobWidth_ - progressWidth_) >> 1;
knobBar.SetRect(foregroundRect.GetLeft() - offset, foregroundRect.GetTop() - halfKnobWidth, knobBar.SetRect(foregroundRect.GetLeft() - offset, foregroundRect.GetTop() - halfKnobWidth,
foregroundRect.GetRight() + offset, foregroundRect.GetTop() + halfKnobWidth); foregroundRect.GetRight() + offset, foregroundRect.GetTop() + halfKnobWidth);
break; break;
} }
case Direction::DIR_TOP_TO_BOTTOM: { case Direction::DIR_TOP_TO_BOTTOM: {
offset = (knobWidth_ - progressWidth_) >> 1; offset = (knobWidth_ - progressWidth_) >> 1;
knobBar.SetRect(foregroundRect.GetLeft() - offset, foregroundRect.GetBottom() - halfKnobWidth, knobBar.SetRect(foregroundRect.GetLeft() - offset, foregroundRect.GetBottom() - halfKnobWidth,
foregroundRect.GetRight() + offset, foregroundRect.GetBottom() + halfKnobWidth); foregroundRect.GetRight() + offset, foregroundRect.GetBottom() + halfKnobWidth);
break; break;
} }
default: { default: {
...@@ -185,7 +169,7 @@ bool UISlider::InitImage() ...@@ -185,7 +169,7 @@ bool UISlider::InitImage()
} }
return true; return true;
} }
#else
void UISlider::SetImage(const ImageInfo* backgroundImage, const ImageInfo* foregroundImage) void UISlider::SetImage(const ImageInfo* backgroundImage, const ImageInfo* foregroundImage)
{ {
if (!InitImage()) { if (!InitImage()) {
...@@ -204,14 +188,6 @@ void UISlider::SetImage(const char* backgroundImage, const char* foregroundImage ...@@ -204,14 +188,6 @@ void UISlider::SetImage(const char* backgroundImage, const char* foregroundImage
foregroundImage_->SetSrc(foregroundImage); foregroundImage_->SetSrc(foregroundImage);
} }
bool UISlider::InitImage()
{
if (!UIAbstractProgress::InitImage()) {
return false;
}
return true;
}
void UISlider::DrawForeground(BufferInfo& gfxDstBuffer, const Rect& invalidatedArea, Rect& coords) void UISlider::DrawForeground(BufferInfo& gfxDstBuffer, const Rect& invalidatedArea, Rect& coords)
{ {
Point startPoint; Point startPoint;
...@@ -224,48 +200,48 @@ void UISlider::DrawForeground(BufferInfo& gfxDstBuffer, const Rect& invalidatedA ...@@ -224,48 +200,48 @@ void UISlider::DrawForeground(BufferInfo& gfxDstBuffer, const Rect& invalidatedA
int16_t right; int16_t right;
int16_t top; int16_t top;
int16_t bottom; int16_t bottom;
Rect rect;
int16_t length; int16_t length;
Rect foregroundRect;
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, foregroundRect.SetRect(startPoint.x, startPoint.y, startPoint.x + progressWidth - 1,
startPoint.y + progressHeight_ - 1); startPoint.y + progressHeight_ - 1);
left = startPoint.x - radius - 1; left = startPoint.x - radius - 1;
right = left + length; right = left + length;
rect = Rect(left, startPoint.y, right, startPoint.y + progressHeight_ - 1); coords.SetRect(left, startPoint.y, right, startPoint.y + progressHeight_ - 1);
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, foregroundRect.SetRect(startPoint.x, startPoint.y, startPoint.x + progressWidth - 1,
startPoint.y + progressHeight_ - 1); startPoint.y + progressHeight_ - 1);
right = startPoint.x + progressWidth + radius + 1; right = startPoint.x + progressWidth + radius + 1;
left = right - length; left = right - length;
rect = Rect(left, startPoint.y, right, startPoint.y + progressHeight_ - 1); coords.SetRect(left, startPoint.y, right, startPoint.y + progressHeight_ - 1);
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, foregroundRect.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); coords.SetRect(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, foregroundRect.SetRect(startPoint.x, startPoint.y, startPoint.x + progressWidth_ - 1,
startPoint.y + progressHeight - 1); startPoint.y + progressHeight - 1);
bottom = startPoint.y + progressHeight + radius + 1; bottom = startPoint.y + progressHeight + radius + 1;
top = bottom - length; top = bottom - length;
rect = Rect(startPoint.x, top, startPoint.x + progressWidth_ - 1, bottom); coords.SetRect(startPoint.x, top, startPoint.x + progressWidth_ - 1, bottom);
break; break;
} }
default: { default: {
...@@ -273,12 +249,10 @@ void UISlider::DrawForeground(BufferInfo& gfxDstBuffer, const Rect& invalidatedA ...@@ -273,12 +249,10 @@ void UISlider::DrawForeground(BufferInfo& gfxDstBuffer, const Rect& invalidatedA
return; return;
} }
} }
if (coords.Intersect(coords, invalidatedArea)) {
if (rect.Intersect(rect, invalidatedArea)) { DrawValidRect(gfxDstBuffer, foregroundImage_, foregroundRect, coords, *foregroundStyle_, radius);
DrawValidRect(gfxDstBuffer, foregroundImage_, coords, rect, *foregroundStyle_, radius);
} }
} }
#endif
void UISlider::OnDraw(BufferInfo& gfxDstBuffer, const Rect& invalidatedArea) void UISlider::OnDraw(BufferInfo& gfxDstBuffer, const Rect& invalidatedArea)
{ {
...@@ -289,9 +263,7 @@ void UISlider::OnDraw(BufferInfo& gfxDstBuffer, const Rect& invalidatedArea) ...@@ -289,9 +263,7 @@ void UISlider::OnDraw(BufferInfo& gfxDstBuffer, const Rect& invalidatedArea)
DrawBackground(gfxDstBuffer, trunc); DrawBackground(gfxDstBuffer, trunc);
Rect foregroundRect; Rect foregroundRect;
DrawForeground(gfxDstBuffer, trunc, foregroundRect); DrawForeground(gfxDstBuffer, trunc, foregroundRect);
#if ENABLE_SLIDER_KNOB
DrawKnob(gfxDstBuffer, trunc, foregroundRect); DrawKnob(gfxDstBuffer, trunc, foregroundRect);
#endif
} }
} }
......
...@@ -501,11 +501,10 @@ void UIVideo::InitControllerSlider() ...@@ -501,11 +501,10 @@ void UIVideo::InitControllerSlider()
playSlider_->SetValidWidth(DEFAULT_VIEW_WIDTH * 5 / 6); // 5:multiply, 6:divide playSlider_->SetValidWidth(DEFAULT_VIEW_WIDTH * 5 / 6); // 5:multiply, 6:divide
playSlider_->SetRange(100, 0); // 100:range max playSlider_->SetRange(100, 0); // 100:range max
playSlider_->SetValue(0); playSlider_->SetValue(0);
#if ENABLE_SLIDER_KNOB
playSlider_->SetKnobWidth(KNOB_WIDTH); playSlider_->SetKnobWidth(KNOB_WIDTH);
playSlider_->SetSliderRadius(5, 5, KNOB_WIDTH / 2); // 5:background radius, 5:foreground radius, 2:half playSlider_->SetSliderRadius(5, 5); // 5:background radius, 5:foreground radius
playSlider_->SetKnobRadius(KNOB_WIDTH / 2); // 2:half
playSlider_->SetKnobStyle(STYLE_BACKGROUND_COLOR, Color::White().full); playSlider_->SetKnobStyle(STYLE_BACKGROUND_COLOR, Color::White().full);
#endif // ENABLE_SLIDER_KNOB
playSlider_->SetBackgroundStyle(STYLE_BACKGROUND_COLOR, 0x1A888888); // 0x1A888888:slider background color playSlider_->SetBackgroundStyle(STYLE_BACKGROUND_COLOR, 0x1A888888); // 0x1A888888:slider background color
playSlider_->SetBackgroundStyle(STYLE_BACKGROUND_OPA, 90); // 90:background opa playSlider_->SetBackgroundStyle(STYLE_BACKGROUND_OPA, 90); // 90:background opa
playSlider_->SetDirection(UISlider::Direction::DIR_LEFT_TO_RIGHT); playSlider_->SetDirection(UISlider::Direction::DIR_LEFT_TO_RIGHT);
......
...@@ -93,7 +93,6 @@ public: ...@@ -93,7 +93,6 @@ public:
void SetKnobWidth(int16_t width) void SetKnobWidth(int16_t width)
{ {
knobWidth_ = width; knobWidth_ = width;
knobWidthSetFlag_ = true;
} }
/** /**
...@@ -104,59 +103,46 @@ public: ...@@ -104,59 +103,46 @@ public:
* @since 1.0 * @since 1.0
* @version 1.0 * @version 1.0
*/ */
int16_t GetKnobWidth(); int16_t GetKnobWidth()
{
return knobWidth_;
}
/** /**
* @brief Sets the images as pixel maps for this slider, including the background, foreground, and knob images. * @brief Sets the image as pixel maps for this slider's knob.
* *
* @param backgroundImage Indicates the background image to set.
* @param foregroundImage Indicates the foreground image to set.
* @param knobImage Indicates the knob image to set. * @param knobImage Indicates the knob image to set.
* @since 1.0 * @since 6
* @version 1.0
*/ */
void SetImage(const ImageInfo* backgroundImage, const ImageInfo* foregroundImage, const ImageInfo* knobImage); void SetKnobImage(const ImageInfo* knobImage);
/** /**
* @brief Sets the images for this slider, including the background, foreground, and knob images. * @brief Sets the image for this slider's knob.
* *
* @param backgroundImage Indicates the background image to set.
* @param foregroundImage Indicates the foreground image to set.
* @param knobImage Indicates the knob image to set. * @param knobImage Indicates the knob image to set.
* @since 1.0 * @since 6
* @version 1.0
*/ */
void SetImage(const char* backgroundImage, const char* foregroundImage, const char* knobImage); void SetKnobImage(const char* knobImage);
/** /**
* @brief Sets the colors for this slider, including the background, foreground, and knob colors. * @brief Sets the color for this slider's knob.
* *
* @param backgroundColor Indicates the background color to set.
* @param foregroundColor Indicates the foreground color to set.
* @param knobColor Indicates the knob color to set. * @param knobColor Indicates the knob color to set.
* @since 1.0 * @since 6
* @version 1.0
*/ */
void SetSliderColor(const ColorType backgroundColor, const ColorType foregroundColor, const ColorType knobColor) void SetKnobColor(const ColorType knobColor)
{ {
SetBackgroundStyle(STYLE_BACKGROUND_COLOR, backgroundColor.full);
SetForegroundStyle(STYLE_BACKGROUND_COLOR, foregroundColor.full);
SetKnobStyle(STYLE_BACKGROUND_COLOR, knobColor.full); SetKnobStyle(STYLE_BACKGROUND_COLOR, knobColor.full);
} }
/** /**
* @brief Sets the corner radiuses for this slider, including the background, foreground, and knob corner radiuses. * @brief Sets the corner radius for this slider's knob.
* *
* @param backgroundRadius Indicates the background corner radius to set.
* @param foregroundRadius Indicates the foreground corner radius to set.
* @param knobRadius Indicates the knob corner radius to set. * @param knobRadius Indicates the knob corner radius to set.
* @since 1.0 * @since 6
* @version 1.0
*/ */
void SetSliderRadius(int16_t backgroundRadius, int16_t foregroundRadius, int16_t knobRadius) void SetKnobRadius(int16_t knobRadius)
{ {
SetBackgroundStyle(STYLE_BORDER_RADIUS, backgroundRadius);
SetForegroundStyle(STYLE_BORDER_RADIUS, foregroundRadius);
SetKnobStyle(STYLE_BORDER_RADIUS, knobRadius); SetKnobStyle(STYLE_BORDER_RADIUS, knobRadius);
} }
...@@ -200,7 +186,7 @@ public: ...@@ -200,7 +186,7 @@ public:
int64_t GetKnobStyle(uint8_t key) const; int64_t GetKnobStyle(uint8_t key) const;
/** /**
* @brief Sets the images as pixel maps for this slider, including the background, foreground, and knob images. * @brief Sets the images as pixel maps for this slider, including the background, foreground images.
* *
* @param backgroundImage Indicates the background image to set. * @param backgroundImage Indicates the background image to set.
* @param foregroundImage Indicates the foreground image to set. * @param foregroundImage Indicates the foreground image to set.
...@@ -210,7 +196,7 @@ public: ...@@ -210,7 +196,7 @@ public:
void SetImage(const ImageInfo* backgroundImage, const ImageInfo* foregroundImage); void SetImage(const ImageInfo* backgroundImage, const ImageInfo* foregroundImage);
/** /**
* @brief Sets the images for this slider, including the background, foreground, and knob images. * @brief Sets the images for this slider, including the background, foreground images.
* *
* @param backgroundImage Indicates the background image to set. * @param backgroundImage Indicates the background image to set.
* @param foregroundImage Indicates the foreground image to set. * @param foregroundImage Indicates the foreground image to set.
...@@ -220,7 +206,7 @@ public: ...@@ -220,7 +206,7 @@ public:
void SetImage(const char* backgroundImage, const char* foregroundImage); void SetImage(const char* backgroundImage, const char* foregroundImage);
/** /**
* @brief Sets the colors for this slider, including the background, foreground, and knob colors. * @brief Sets the colors for this slider, including the background, foreground colors.
* *
* @param backgroundColor Indicates the background color to set. * @param backgroundColor Indicates the background color to set.
* @param foregroundColor Indicates the foreground color to set. * @param foregroundColor Indicates the foreground color to set.
...@@ -234,7 +220,7 @@ public: ...@@ -234,7 +220,7 @@ public:
} }
/** /**
* @brief Sets the corner radiuses for this slider, including the background, foreground, and knob corner radiuses. * @brief Sets the corner radiuses for this slider, including the background, foreground corner radiuses.
* *
* @param backgroundRadius Indicates the background corner radius to set. * @param backgroundRadius Indicates the background corner radius to set.
* @param foregroundRadius Indicates the foreground corner radius to set. * @param foregroundRadius Indicates the foreground corner radius to set.
...@@ -347,22 +333,15 @@ protected: ...@@ -347,22 +333,15 @@ 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;
static constexpr uint8_t MAX_ROTATE_FACTOR = 128; static constexpr uint8_t MAX_ROTATE_FACTOR = 128;
#if ENABLE_SLIDER_KNOB
void DrawKnob(BufferInfo& gfxDstBuffer, const Rect& invalidatedArea, const Rect& foregroundRect);
#else
int16_t knobWidth_; int16_t knobWidth_;
bool knobWidthSetFlag_;
bool knobStyleAllocFlag_; bool knobStyleAllocFlag_;
Style* knobStyle_; Style* knobStyle_;
Image* knobImage_; Image* knobImage_;
void DrawKnob(BufferInfo& gfxDstBuffer, const Rect& invalidatedArea, const Rect& foregroundRect);
void DrawForeground(BufferInfo& gfxDstBuffer, const Rect& invalidatedArea, Rect& coords); void DrawForeground(BufferInfo& gfxDstBuffer, const Rect& invalidatedArea, Rect& coords);
#endif
int32_t CalculateCurrentValue(int16_t length, int16_t totalLength); int32_t CalculateCurrentValue(int16_t length, int16_t totalLength);
int32_t UpdateCurrentValue(const Point& knobPosition); int32_t UpdateCurrentValue(const Point& knobPosition);
#if ENABLE_ROTATE_INPUT #if ENABLE_ROTATE_INPUT
......
...@@ -19,12 +19,12 @@ ...@@ -19,12 +19,12 @@
namespace OHOS { namespace OHOS {
namespace { namespace {
const int16_t LABEL_HEIGHT = 29; constexpr int16_t LABEL_HEIGHT = 29;
const int16_t BUTTON_WIDTH = 120; constexpr int16_t BUTTON_WIDTH = 120;
const int16_t BUTTON_HEIGHT = 40; constexpr int16_t BUTTON_HEIGHT = 40;
const int16_t DELTA_X_COORDINATE = 8; constexpr int16_t DELTA_X_COORDINATE = 8;
const int16_t DELTA_Y_COORDINATE = 12; constexpr int16_t DELTA_Y_COORDINATE = 12;
const int16_t DELTA_Y_COORDINATE_2 = 19; constexpr int16_t DELTA_Y_COORDINATE_2 = 19;
static bool g_onChange = false; static bool g_onChange = false;
static bool g_onRelease = false; static bool g_onRelease = false;
static bool g_onClick = false; static bool g_onClick = false;
...@@ -36,6 +36,10 @@ static uint16_t g_height = 250; ...@@ -36,6 +36,10 @@ static uint16_t g_height = 250;
static int16_t g_min = 0; static int16_t g_min = 0;
static int16_t g_max = 100; static int16_t g_max = 100;
static int16_t g_knobWidth = 50; static int16_t g_knobWidth = 50;
constexpr int8_t BACKGROUND_OPA = 38;
constexpr uint8_t FOREGROUND_COLOR_R = 0x1f;
constexpr uint8_t FOREGROUND_COLOR_G = 0x71;
constexpr uint8_t FOREGROUND_COLOR_B = 0xff;
} // namespace } // namespace
void TestUISliderEventListener::OnChange(int32_t progress) void TestUISliderEventListener::OnChange(int32_t progress)
...@@ -133,9 +137,6 @@ void UITestSlider::SetUp() ...@@ -133,9 +137,6 @@ void UITestSlider::SetUp()
uiViewGroupFrame_->SetStyle(STYLE_BACKGROUND_OPA, 0); uiViewGroupFrame_->SetStyle(STYLE_BACKGROUND_OPA, 0);
slider_ = new UISlider(); slider_ = new UISlider();
#if !ENABLE_SLIDER_KNOB
slider_->SetSliderColor(Color::Silver(), Color::Blue());
#endif
slider_->SetPosition(10, 10, 50, 300); // 10:position x; 10: position y; 50: width; 300: height slider_->SetPosition(10, 10, 50, 300); // 10:position x; 10: position y; 50: width; 300: height
slider_->SetValidHeight(250); // 250: valid height; slider_->SetValidHeight(250); // 250: valid height;
slider_->SetValue(20); // 20: progress bar current value slider_->SetValue(20); // 20: progress bar current value
...@@ -187,6 +188,7 @@ const UIView* UITestSlider::GetTestView() ...@@ -187,6 +188,7 @@ const UIView* UITestSlider::GetTestView()
UIKit_Slider_Test_SetOnReleaseListener_014(); UIKit_Slider_Test_SetOnReleaseListener_014();
UIKit_Slider_Test_SetOnClickCallback_015(); UIKit_Slider_Test_SetOnClickCallback_015();
UIKit_Slider_Test_SetOnDragCallback_016(); UIKit_Slider_Test_SetOnDragCallback_016();
UIKit_Slider_Test_SetCircularStyle_017();
return container_; return container_;
} }
...@@ -366,7 +368,7 @@ void UITestSlider::UIKit_Slider_Test_SetRadius_012() ...@@ -366,7 +368,7 @@ void UITestSlider::UIKit_Slider_Test_SetRadius_012()
radiusBtn_ = new UILabelButton(); radiusBtn_ = new UILabelButton();
positionX_ = 336; // 336: x-coordinate positionX_ = 336; // 336: x-coordinate
positionY_ += BUTTON_HEIGHT + DELTA_Y_COORDINATE_2; positionY_ += BUTTON_HEIGHT + DELTA_Y_COORDINATE_2;
SetUpLabel("设置lider圆角弧度:", positionX_, positionY_); SetUpLabel("设置Slider圆角弧度:", positionX_, positionY_);
positionY_ += LABEL_HEIGHT + DELTA_X_COORDINATE; positionY_ += LABEL_HEIGHT + DELTA_X_COORDINATE;
SetUpButton(radiusBtn_, "圆角弧度", positionX_, positionY_); SetUpButton(radiusBtn_, "圆角弧度", positionX_, positionY_);
} }
...@@ -410,6 +412,16 @@ void UITestSlider::UIKit_Slider_Test_SetOnDragCallback_016() ...@@ -410,6 +412,16 @@ void UITestSlider::UIKit_Slider_Test_SetOnDragCallback_016()
positionY_ += LABEL_HEIGHT + DELTA_X_COORDINATE; positionY_ += LABEL_HEIGHT + DELTA_X_COORDINATE;
SetUpButton(onDragBtn_, "OnDrag回调", positionX_, positionY_); SetUpButton(onDragBtn_, "OnDrag回调", positionX_, positionY_);
} }
void UITestSlider::UIKit_Slider_Test_SetCircularStyle_017()
{
circularStyleBtn_ = new UILabelButton();
positionX_ = 336; // 336: x-coordinate
positionY_ += BUTTON_HEIGHT + DELTA_Y_COORDINATE_2;
SetUpLabel("Slider设置圆角无滑块样式:", positionX_, positionY_);
positionY_ += LABEL_HEIGHT + DELTA_X_COORDINATE;
SetUpButton(circularStyleBtn_, "圆角无滑块样式", positionX_, positionY_);
}
bool UITestSlider::OnClick(UIView& view, const ClickEvent& event) bool UITestSlider::OnClick(UIView& view, const ClickEvent& event)
{ {
if (&view == resetBtn_) { if (&view == resetBtn_) {
...@@ -424,19 +436,15 @@ bool UITestSlider::OnClick(UIView& view, const ClickEvent& event) ...@@ -424,19 +436,15 @@ bool UITestSlider::OnClick(UIView& view, const ClickEvent& event)
slider_->SetDirection(UISlider::Direction::DIR_BOTTOM_TO_TOP); slider_->SetDirection(UISlider::Direction::DIR_BOTTOM_TO_TOP);
slider_->SetValidHeight(g_height); slider_->SetValidHeight(g_height);
slider_->SetValidWidth(g_width); slider_->SetValidWidth(g_width);
#if ENABLE_SLIDER_KNOB
slider_->SetKnobWidth(50); // 50: knob width slider_->SetKnobWidth(50); // 50: knob width
#endif
slider_->SetRange(g_max, g_min); slider_->SetRange(g_max, g_min);
slider_->SetValue(g_progress); slider_->SetValue(g_progress);
slider_->SetStep(g_step); slider_->SetStep(g_step);
slider_->SetBackgroundStyle(StyleDefault::GetProgressBackgroundStyle()); slider_->SetBackgroundStyle(StyleDefault::GetProgressBackgroundStyle());
slider_->SetForegroundStyle(StyleDefault::GetProgressForegroundStyle()); slider_->SetForegroundStyle(StyleDefault::GetProgressForegroundStyle());
#if ENABLE_SLIDER_KNOB
slider_->SetKnobStyle(StyleDefault::GetSliderKnobStyle()); slider_->SetKnobStyle(StyleDefault::GetSliderKnobStyle());
slider_->SetImage(static_cast<ImageInfo*>(nullptr), static_cast<ImageInfo*>(nullptr), slider_->SetImage(static_cast<ImageInfo*>(nullptr), static_cast<ImageInfo*>(nullptr));
static_cast<ImageInfo*>(nullptr)); slider_->SetKnobImage(static_cast<ImageInfo*>(nullptr));
#endif
slider_->EnableBackground(true); slider_->EnableBackground(true);
} else if (&view == incProgressBtn_) { } else if (&view == incProgressBtn_) {
g_progress++; g_progress++;
...@@ -517,19 +525,16 @@ bool UITestSlider::ExpandClick2(UIView& view, const ClickEvent& event) ...@@ -517,19 +525,16 @@ bool UITestSlider::ExpandClick2(UIView& view, const ClickEvent& event)
if (&view == imageBtn_) { if (&view == imageBtn_) {
slider_->SetValidHeight(DEFAULT_HEIGHT); slider_->SetValidHeight(DEFAULT_HEIGHT);
slider_->SetValidWidth(5); // 5 valid width slider_->SetValidWidth(5); // 5 valid width
#if ENABLE_SLIDER_KNOB
slider_->SetKnobWidth(40); // 40: knob width slider_->SetKnobWidth(40); // 40: knob width
slider_->SetImage(SLIDER_BACKGROUND_IMAGE_PATH, SLIDER_INDICATOR_IMAGE_PATH, SLIDER_KNOB_IMAGE_PATH); slider_->SetImage(SLIDER_BACKGROUND_IMAGE_PATH, SLIDER_INDICATOR_IMAGE_PATH);
#endif slider_->SetKnobImage(SLIDER_KNOB_IMAGE_PATH);
slider_->SetDirection(UISlider::Direction::DIR_BOTTOM_TO_TOP); slider_->SetDirection(UISlider::Direction::DIR_BOTTOM_TO_TOP);
} else if (&view == noImageBtn_) { } else if (&view == noImageBtn_) {
slider_->SetValidHeight(g_height); slider_->SetValidHeight(g_height);
slider_->SetValidWidth(g_width); slider_->SetValidWidth(g_width);
#if ENABLE_SLIDER_KNOB
slider_->SetKnobWidth(g_knobWidth); slider_->SetKnobWidth(g_knobWidth);
slider_->SetImage(static_cast<ImageInfo*>(nullptr), static_cast<ImageInfo*>(nullptr), slider_->SetImage(static_cast<ImageInfo*>(nullptr), static_cast<ImageInfo*>(nullptr));
static_cast<ImageInfo*>(nullptr)); slider_->SetKnobImage(static_cast<ImageInfo*>(nullptr));
#endif
} else if (&view == setStyleBtn_) { } else if (&view == setStyleBtn_) {
Style style = StyleDefault::GetDefaultStyle(); Style style = StyleDefault::GetDefaultStyle();
style.bgColor_ = Color::Green(); style.bgColor_ = Color::Green();
...@@ -537,37 +542,23 @@ bool UITestSlider::ExpandClick2(UIView& view, const ClickEvent& event) ...@@ -537,37 +542,23 @@ bool UITestSlider::ExpandClick2(UIView& view, const ClickEvent& event)
style.bgColor_ = Color::Red(); style.bgColor_ = Color::Red();
slider_->SetForegroundStyle(style); slider_->SetForegroundStyle(style);
style.bgColor_ = Color::Gray(); style.bgColor_ = Color::Gray();
#if ENABLE_SLIDER_KNOB
slider_->SetKnobStyle(style); slider_->SetKnobStyle(style);
#endif
} else if (&view == getStyleBtn_) { } else if (&view == getStyleBtn_) {
slider_->SetBackgroundStyle(STYLE_BACKGROUND_COLOR, Color::Red().full); slider_->SetBackgroundStyle(STYLE_BACKGROUND_COLOR, Color::Red().full);
slider_->SetForegroundStyle(STYLE_BACKGROUND_COLOR, Color::Yellow().full); slider_->SetForegroundStyle(STYLE_BACKGROUND_COLOR, Color::Yellow().full);
#if ENABLE_SLIDER_KNOB
slider_->SetKnobStyle(STYLE_BACKGROUND_COLOR, Color::Green().full); slider_->SetKnobStyle(STYLE_BACKGROUND_COLOR, Color::Green().full);
#endif
} else if (&view == incKnobWidthBtn_) { } else if (&view == incKnobWidthBtn_) {
#if ENABLE_SLIDER_KNOB
g_knobWidth++; g_knobWidth++;
slider_->SetKnobWidth(g_knobWidth); slider_->SetKnobWidth(g_knobWidth);
#endif
} else if (&view == decKnobWidthBtn_) { } else if (&view == decKnobWidthBtn_) {
#if ENABLE_SLIDER_KNOB
g_knobWidth--; g_knobWidth--;
slider_->SetKnobWidth(g_knobWidth); slider_->SetKnobWidth(g_knobWidth);
#endif
} else if (&view == colorBtn_) { } else if (&view == colorBtn_) {
#if ENABLE_SLIDER_KNOB
slider_->SetSliderColor(Color::Silver(), Color::Blue(), Color::White());
#else
slider_->SetSliderColor(Color::Silver(), Color::Blue()); slider_->SetSliderColor(Color::Silver(), Color::Blue());
#endif slider_->SetKnobColor(Color::White());
} else if (&view == radiusBtn_) { } else if (&view == radiusBtn_) {
#if ENABLE_SLIDER_KNOB
slider_->SetSliderRadius(DEFAULT_RADIUS, DEFAULT_RADIUS, DEFAULT_RADIUS);
#else
slider_->SetSliderRadius(DEFAULT_RADIUS, DEFAULT_RADIUS); slider_->SetSliderRadius(DEFAULT_RADIUS, DEFAULT_RADIUS);
#endif slider_->SetKnobRadius(DEFAULT_RADIUS);
} else if (&view == onChangeBtn_) { } else if (&view == onChangeBtn_) {
g_onChange = true; g_onChange = true;
} else if (&view == onReleaseBtn_) { } else if (&view == onReleaseBtn_) {
...@@ -576,6 +567,14 @@ bool UITestSlider::ExpandClick2(UIView& view, const ClickEvent& event) ...@@ -576,6 +567,14 @@ bool UITestSlider::ExpandClick2(UIView& view, const ClickEvent& event)
g_onClick = true; g_onClick = true;
} else if (&view == onDragBtn_) { } else if (&view == onDragBtn_) {
g_onDrag = true; g_onDrag = true;
} else if (&view == circularStyleBtn_) {
slider_->SetKnobWidth(0);
slider_->SetBackgroundStyle(STYLE_LINE_CAP, CapType::CAP_ROUND);
slider_->SetBackgroundStyle(STYLE_BACKGROUND_OPA, BACKGROUND_OPA);
slider_->SetBackgroundStyle(STYLE_BACKGROUND_COLOR, Color::Black().full);
slider_->SetForegroundStyle(STYLE_LINE_CAP, CapType::CAP_ROUND);
slider_->SetForegroundStyle(STYLE_BACKGROUND_COLOR,
Color::GetColorFromRGB(FOREGROUND_COLOR_R, FOREGROUND_COLOR_G, FOREGROUND_COLOR_B).full);
} }
return true; return true;
} }
......
...@@ -75,6 +75,7 @@ public: ...@@ -75,6 +75,7 @@ public:
void UIKit_Slider_Test_SetOnReleaseListener_014(); void UIKit_Slider_Test_SetOnReleaseListener_014();
void UIKit_Slider_Test_SetOnClickCallback_015(); void UIKit_Slider_Test_SetOnClickCallback_015();
void UIKit_Slider_Test_SetOnDragCallback_016(); void UIKit_Slider_Test_SetOnDragCallback_016();
void UIKit_Slider_Test_SetCircularStyle_017();
private: private:
static constexpr int32_t DEFAULT_VALUE = 20; static constexpr int32_t DEFAULT_VALUE = 20;
...@@ -114,6 +115,7 @@ private: ...@@ -114,6 +115,7 @@ private:
UILabelButton* onReleaseBtn_ = nullptr; UILabelButton* onReleaseBtn_ = nullptr;
UILabelButton* onClickBtn_ = nullptr; UILabelButton* onClickBtn_ = nullptr;
UILabelButton* onDragBtn_ = nullptr; UILabelButton* onDragBtn_ = nullptr;
UILabelButton* circularStyleBtn_ = nullptr;
}; };
} // namespace OHOS } // namespace OHOS
#endif // UI_TEST_SLIDER_H #endif // UI_TEST_SLIDER_H
...@@ -302,12 +302,9 @@ void UITestDumpDomTree::UIKit_TestDumpDom_003() ...@@ -302,12 +302,9 @@ void UITestDumpDomTree::UIKit_TestDumpDom_003()
slider->SetStep(0); slider->SetStep(0);
slider->SetBackgroundStyle(STYLE_BACKGROUND_COLOR, Color::GetColorFromRGB(0, 182, 191).full); // 182, 191: color slider->SetBackgroundStyle(STYLE_BACKGROUND_COLOR, Color::GetColorFromRGB(0, 182, 191).full); // 182, 191: color
slider->SetForegroundStyle(STYLE_BACKGROUND_COLOR, Color::GetColorFromRGB(255, 152, 0).full); // 255, 152: color slider->SetForegroundStyle(STYLE_BACKGROUND_COLOR, Color::GetColorFromRGB(255, 152, 0).full); // 255, 152: color
#if ENABLE_SLIDER_KNOB
slider->SetKnobWidth(50); // 50: knob width slider->SetKnobWidth(50); // 50: knob width
slider->SetKnobStyle(StyleDefault::GetSliderKnobStyle()); slider->SetKnobStyle(StyleDefault::GetSliderKnobStyle());
slider->SetImage(static_cast<ImageInfo*>(nullptr), static_cast<ImageInfo*>(nullptr), slider->SetImage(static_cast<ImageInfo*>(nullptr), static_cast<ImageInfo*>(nullptr));
static_cast<ImageInfo*>(nullptr));
#endif
slider->EnableBackground(true); slider->EnableBackground(true);
slider->SetViewId("dump_slider"); slider->SetViewId("dump_slider");
group5->Add(slider); group5->Add(slider);
......
...@@ -57,7 +57,7 @@ HWTEST_F(UISliderTest, UISliderGetViewType_001, TestSize.Level1) ...@@ -57,7 +57,7 @@ HWTEST_F(UISliderTest, UISliderGetViewType_001, TestSize.Level1)
} }
EXPECT_EQ(slider_->GetViewType(), UI_SLIDER); EXPECT_EQ(slider_->GetViewType(), UI_SLIDER);
} }
#if ENABLE_SLIDER_KNOB
/** /**
* @tc.name:UISliderSetKnobWidth_001 * @tc.name:UISliderSetKnobWidth_001
* @tc.desc: Verify SetKnobWidth function, equal. * @tc.desc: Verify SetKnobWidth function, equal.
...@@ -91,5 +91,4 @@ HWTEST_F(UISliderTest, UISliderSetKnobStyle_001, TestSize.Level0) ...@@ -91,5 +91,4 @@ HWTEST_F(UISliderTest, UISliderSetKnobStyle_001, TestSize.Level0)
slider_->SetKnobStyle(STYLE_BACKGROUND_COLOR, Color::Gray().full); slider_->SetKnobStyle(STYLE_BACKGROUND_COLOR, Color::Gray().full);
EXPECT_EQ(slider_->GetKnobStyle().bgColor_.full, Color::Gray().full); EXPECT_EQ(slider_->GetKnobStyle().bgColor_.full, Color::Gray().full);
} }
#endif // ENABLE_SLIDER_KNOB
} // namespace OHOS } // namespace OHOS
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册