diff --git a/frameworks/components/ui_slider.cpp b/frameworks/components/ui_slider.cpp index 863ed846f779bbb05899aa52c22dbbc248e1c938..da4537a4fd5dcd52705fa7dd7ecf97192bb2bb1a 100755 --- a/frameworks/components/ui_slider.cpp +++ b/frameworks/components/ui_slider.cpp @@ -32,7 +32,7 @@ constexpr float DEFAULT_SLIDER_ROTATE_FACTOR = -0.1; } namespace OHOS { UISlider::UISlider() - : knobWidth_(0), knobWidthSetFlag_(false), knobStyleAllocFlag_(false), knobImage_(nullptr), listener_(nullptr) + : knobWidth_(0), knobStyleAllocFlag_(false), knobImage_(nullptr), listener_(nullptr) { touchable_ = true; draggable_ = true; @@ -43,12 +43,13 @@ UISlider::UISlider() #if ENABLE_ROTATE_INPUT rotateFactor_ = DEFAULT_SLIDER_ROTATE_FACTOR; #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); + + Theme* theme = ThemeManager::GetInstance().GetCurrent(); + if (theme != nullptr) { + knobStyle_ = &(theme->GetSliderKnobStyle()); + } else { + knobStyle_ = &(StyleDefault::GetSliderKnobStyle()); + } } UISlider::~UISlider() @@ -101,39 +102,22 @@ int64_t UISlider::GetKnobStyle(uint8_t key) const return knobStyle_->GetStyle(key); } -int16_t UISlider::GetKnobWidth() -{ - 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) +void UISlider::SetKnobImage(const ImageInfo* knobImage) { if (!InitImage()) { return; } - backgroundImage_->SetSrc(backgroundImage); - foregroundImage_->SetSrc(foregroundImage); knobImage_->SetSrc(knobImage); } -void UISlider::SetImage(const char* backgroundImage, const char* foregroundImage, const char* knobImage) +void UISlider::SetKnobImage(const char* knobImage) { if (!InitImage()) { return; } - backgroundImage_->SetSrc(backgroundImage); - foregroundImage_->SetSrc(foregroundImage); knobImage_->SetSrc(knobImage); } -#if ENABLE_SLIDER_KNOB void UISlider::DrawKnob(BufferInfo& gfxDstBuffer, const Rect& invalidatedArea, const Rect& foregroundRect) { int16_t halfKnobWidth = GetKnobWidth() >> 1; @@ -143,25 +127,25 @@ void UISlider::DrawKnob(BufferInfo& gfxDstBuffer, const Rect& invalidatedArea, c case Direction::DIR_LEFT_TO_RIGHT: { offset = (knobWidth_ - progressHeight_) >> 1; knobBar.SetRect(foregroundRect.GetRight() - halfKnobWidth, foregroundRect.GetTop() - offset, - foregroundRect.GetRight() + halfKnobWidth, foregroundRect.GetBottom() + offset); + foregroundRect.GetRight() + halfKnobWidth, foregroundRect.GetBottom() + offset); break; } case Direction::DIR_RIGHT_TO_LEFT: { offset = (knobWidth_ - progressHeight_) >> 1; knobBar.SetRect(foregroundRect.GetLeft() - halfKnobWidth, foregroundRect.GetTop() - offset, - foregroundRect.GetLeft() + halfKnobWidth, foregroundRect.GetBottom() + offset); + foregroundRect.GetLeft() + halfKnobWidth, foregroundRect.GetBottom() + offset); break; } case Direction::DIR_BOTTOM_TO_TOP: { offset = (knobWidth_ - progressWidth_) >> 1; knobBar.SetRect(foregroundRect.GetLeft() - offset, foregroundRect.GetTop() - halfKnobWidth, - foregroundRect.GetRight() + offset, foregroundRect.GetTop() + halfKnobWidth); + foregroundRect.GetRight() + offset, foregroundRect.GetTop() + halfKnobWidth); break; } case Direction::DIR_TOP_TO_BOTTOM: { offset = (knobWidth_ - progressWidth_) >> 1; knobBar.SetRect(foregroundRect.GetLeft() - offset, foregroundRect.GetBottom() - halfKnobWidth, - foregroundRect.GetRight() + offset, foregroundRect.GetBottom() + halfKnobWidth); + foregroundRect.GetRight() + offset, foregroundRect.GetBottom() + halfKnobWidth); break; } default: { @@ -185,7 +169,7 @@ bool UISlider::InitImage() } return true; } -#else + void UISlider::SetImage(const ImageInfo* backgroundImage, const ImageInfo* foregroundImage) { if (!InitImage()) { @@ -204,14 +188,6 @@ void UISlider::SetImage(const char* backgroundImage, const char* foregroundImage foregroundImage_->SetSrc(foregroundImage); } -bool UISlider::InitImage() -{ - if (!UIAbstractProgress::InitImage()) { - return false; - } - return true; -} - void UISlider::DrawForeground(BufferInfo& gfxDstBuffer, const Rect& invalidatedArea, Rect& coords) { Point startPoint; @@ -224,48 +200,48 @@ void UISlider::DrawForeground(BufferInfo& gfxDstBuffer, const Rect& invalidatedA int16_t right; int16_t top; int16_t bottom; - Rect rect; int16_t length; + Rect foregroundRect; switch (direction_) { case Direction::DIR_LEFT_TO_RIGHT: { length = GetCurrentPos(progressWidth_ + 1); - coords.SetRect(startPoint.x, startPoint.y, startPoint.x + progressWidth - 1, - startPoint.y + progressHeight_ - 1); + foregroundRect.SetRect(startPoint.x, startPoint.y, startPoint.x + progressWidth - 1, + startPoint.y + progressHeight_ - 1); left = startPoint.x - radius - 1; right = left + length; - rect = Rect(left, startPoint.y, right, startPoint.y + progressHeight_ - 1); + coords.SetRect(left, startPoint.y, right, startPoint.y + progressHeight_ - 1); break; } case Direction::DIR_RIGHT_TO_LEFT: { length = GetCurrentPos(progressWidth_ + 1); - coords.SetRect(startPoint.x, startPoint.y, startPoint.x + progressWidth - 1, - startPoint.y + progressHeight_ - 1); + foregroundRect.SetRect(startPoint.x, startPoint.y, startPoint.x + progressWidth - 1, + startPoint.y + progressHeight_ - 1); right = startPoint.x + progressWidth + radius + 1; left = right - length; - rect = Rect(left, startPoint.y, right, startPoint.y + progressHeight_ - 1); + coords.SetRect(left, startPoint.y, right, startPoint.y + progressHeight_ - 1); break; } case Direction::DIR_TOP_TO_BOTTOM: { length = GetCurrentPos(progressHeight_ + 1); - coords.SetRect(startPoint.x, startPoint.y, startPoint.x + progressWidth_ - 1, - startPoint.y + progressHeight - 1); + foregroundRect.SetRect(startPoint.x, startPoint.y, startPoint.x + progressWidth_ - 1, + startPoint.y + progressHeight - 1); top = startPoint.y - radius - 1; bottom = top + length; - rect = Rect(startPoint.x, top, startPoint.x + progressWidth_ - 1, bottom); + coords.SetRect(startPoint.x, top, startPoint.x + progressWidth_ - 1, bottom); break; } case Direction::DIR_BOTTOM_TO_TOP: { length = GetCurrentPos(progressHeight_ + 1); - coords.SetRect(startPoint.x, startPoint.y, startPoint.x + progressWidth_ - 1, - startPoint.y + progressHeight - 1); + foregroundRect.SetRect(startPoint.x, startPoint.y, startPoint.x + progressWidth_ - 1, + startPoint.y + progressHeight - 1); bottom = startPoint.y + progressHeight + radius + 1; top = bottom - length; - rect = Rect(startPoint.x, top, startPoint.x + progressWidth_ - 1, bottom); + coords.SetRect(startPoint.x, top, startPoint.x + progressWidth_ - 1, bottom); break; } default: { @@ -273,12 +249,10 @@ void UISlider::DrawForeground(BufferInfo& gfxDstBuffer, const Rect& invalidatedA return; } } - - if (rect.Intersect(rect, invalidatedArea)) { - DrawValidRect(gfxDstBuffer, foregroundImage_, coords, rect, *foregroundStyle_, radius); + if (coords.Intersect(coords, invalidatedArea)) { + DrawValidRect(gfxDstBuffer, foregroundImage_, foregroundRect, coords, *foregroundStyle_, radius); } } -#endif void UISlider::OnDraw(BufferInfo& gfxDstBuffer, const Rect& invalidatedArea) { @@ -289,9 +263,7 @@ void UISlider::OnDraw(BufferInfo& gfxDstBuffer, const Rect& invalidatedArea) DrawBackground(gfxDstBuffer, trunc); Rect foregroundRect; DrawForeground(gfxDstBuffer, trunc, foregroundRect); -#if ENABLE_SLIDER_KNOB DrawKnob(gfxDstBuffer, trunc, foregroundRect); -#endif } } diff --git a/frameworks/components/ui_video.cpp b/frameworks/components/ui_video.cpp index 063bb73b9f35b5b8531b31f16232e96d11193b40..99a26b16b36807f22dd0fa2667abf6bce67746a7 100755 --- a/frameworks/components/ui_video.cpp +++ b/frameworks/components/ui_video.cpp @@ -501,11 +501,10 @@ void UIVideo::InitControllerSlider() playSlider_->SetValidWidth(DEFAULT_VIEW_WIDTH * 5 / 6); // 5:multiply, 6:divide playSlider_->SetRange(100, 0); // 100:range max playSlider_->SetValue(0); -#if ENABLE_SLIDER_KNOB 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); -#endif // ENABLE_SLIDER_KNOB playSlider_->SetBackgroundStyle(STYLE_BACKGROUND_COLOR, 0x1A888888); // 0x1A888888:slider background color playSlider_->SetBackgroundStyle(STYLE_BACKGROUND_OPA, 90); // 90:background opa playSlider_->SetDirection(UISlider::Direction::DIR_LEFT_TO_RIGHT); diff --git a/interfaces/kits/components/ui_slider.h b/interfaces/kits/components/ui_slider.h index bec6b42027b3850c0aec10f08ca1bc2fa54ee242..e7efec873bca4e97575094c4834448212a9719ec 100755 --- a/interfaces/kits/components/ui_slider.h +++ b/interfaces/kits/components/ui_slider.h @@ -93,7 +93,6 @@ public: void SetKnobWidth(int16_t width) { knobWidth_ = width; - knobWidthSetFlag_ = true; } /** @@ -104,59 +103,46 @@ public: * @since 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. - * @since 1.0 - * @version 1.0 + * @since 6 */ - 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. - * @since 1.0 - * @version 1.0 + * @since 6 */ - 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. - * @since 1.0 - * @version 1.0 + * @since 6 */ - 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); } /** - * @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. - * @since 1.0 - * @version 1.0 + * @since 6 */ - 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); } @@ -200,7 +186,7 @@ public: 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 foregroundImage Indicates the foreground image to set. @@ -210,7 +196,7 @@ public: 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 foregroundImage Indicates the foreground image to set. @@ -220,7 +206,7 @@ public: 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 foregroundColor Indicates the foreground color to set. @@ -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 foregroundRadius Indicates the foreground corner radius to set. @@ -347,22 +333,15 @@ protected: bool InitImage() override; 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; -#if ENABLE_SLIDER_KNOB - void DrawKnob(BufferInfo& gfxDstBuffer, const Rect& invalidatedArea, const Rect& foregroundRect); -#else + int16_t knobWidth_; - bool knobWidthSetFlag_; bool knobStyleAllocFlag_; Style* knobStyle_; Image* knobImage_; + void DrawKnob(BufferInfo& gfxDstBuffer, const Rect& invalidatedArea, const Rect& foregroundRect); void DrawForeground(BufferInfo& gfxDstBuffer, const Rect& invalidatedArea, Rect& coords); -#endif int32_t CalculateCurrentValue(int16_t length, int16_t totalLength); int32_t UpdateCurrentValue(const Point& knobPosition); #if ENABLE_ROTATE_INPUT diff --git a/test/uitest/test_slider/ui_test_slider.cpp b/test/uitest/test_slider/ui_test_slider.cpp index de965dae2dbad5187fcfc2a9212777f895ff05d8..6e365345dc9808c227c5e469e6f71b06260d1b3d 100755 --- a/test/uitest/test_slider/ui_test_slider.cpp +++ b/test/uitest/test_slider/ui_test_slider.cpp @@ -19,12 +19,12 @@ namespace OHOS { namespace { -const int16_t LABEL_HEIGHT = 29; -const int16_t BUTTON_WIDTH = 120; -const int16_t BUTTON_HEIGHT = 40; -const int16_t DELTA_X_COORDINATE = 8; -const int16_t DELTA_Y_COORDINATE = 12; -const int16_t DELTA_Y_COORDINATE_2 = 19; +constexpr int16_t LABEL_HEIGHT = 29; +constexpr int16_t BUTTON_WIDTH = 120; +constexpr int16_t BUTTON_HEIGHT = 40; +constexpr int16_t DELTA_X_COORDINATE = 8; +constexpr int16_t DELTA_Y_COORDINATE = 12; +constexpr int16_t DELTA_Y_COORDINATE_2 = 19; static bool g_onChange = false; static bool g_onRelease = false; static bool g_onClick = false; @@ -36,6 +36,10 @@ static uint16_t g_height = 250; static int16_t g_min = 0; static int16_t g_max = 100; 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 void TestUISliderEventListener::OnChange(int32_t progress) @@ -133,9 +137,6 @@ void UITestSlider::SetUp() uiViewGroupFrame_->SetStyle(STYLE_BACKGROUND_OPA, 0); 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_->SetValidHeight(250); // 250: valid height; slider_->SetValue(20); // 20: progress bar current value @@ -187,6 +188,7 @@ const UIView* UITestSlider::GetTestView() UIKit_Slider_Test_SetOnReleaseListener_014(); UIKit_Slider_Test_SetOnClickCallback_015(); UIKit_Slider_Test_SetOnDragCallback_016(); + UIKit_Slider_Test_SetCircularStyle_017(); return container_; } @@ -366,7 +368,7 @@ void UITestSlider::UIKit_Slider_Test_SetRadius_012() radiusBtn_ = new UILabelButton(); positionX_ = 336; // 336: x-coordinate positionY_ += BUTTON_HEIGHT + DELTA_Y_COORDINATE_2; - SetUpLabel("设置lider圆角弧度:", positionX_, positionY_); + SetUpLabel("设置Slider圆角弧度:", positionX_, positionY_); positionY_ += LABEL_HEIGHT + DELTA_X_COORDINATE; SetUpButton(radiusBtn_, "圆角弧度", positionX_, positionY_); } @@ -410,6 +412,16 @@ void UITestSlider::UIKit_Slider_Test_SetOnDragCallback_016() positionY_ += LABEL_HEIGHT + DELTA_X_COORDINATE; 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) { if (&view == resetBtn_) { @@ -424,19 +436,15 @@ bool UITestSlider::OnClick(UIView& view, const ClickEvent& event) slider_->SetDirection(UISlider::Direction::DIR_BOTTOM_TO_TOP); slider_->SetValidHeight(g_height); slider_->SetValidWidth(g_width); -#if ENABLE_SLIDER_KNOB slider_->SetKnobWidth(50); // 50: knob width -#endif slider_->SetRange(g_max, g_min); slider_->SetValue(g_progress); slider_->SetStep(g_step); slider_->SetBackgroundStyle(StyleDefault::GetProgressBackgroundStyle()); slider_->SetForegroundStyle(StyleDefault::GetProgressForegroundStyle()); -#if ENABLE_SLIDER_KNOB slider_->SetKnobStyle(StyleDefault::GetSliderKnobStyle()); - slider_->SetImage(static_cast(nullptr), static_cast(nullptr), - static_cast(nullptr)); -#endif + slider_->SetImage(static_cast(nullptr), static_cast(nullptr)); + slider_->SetKnobImage(static_cast(nullptr)); slider_->EnableBackground(true); } else if (&view == incProgressBtn_) { g_progress++; @@ -517,19 +525,16 @@ bool UITestSlider::ExpandClick2(UIView& view, const ClickEvent& event) if (&view == imageBtn_) { slider_->SetValidHeight(DEFAULT_HEIGHT); slider_->SetValidWidth(5); // 5 valid width -#if ENABLE_SLIDER_KNOB slider_->SetKnobWidth(40); // 40: knob width - slider_->SetImage(SLIDER_BACKGROUND_IMAGE_PATH, SLIDER_INDICATOR_IMAGE_PATH, SLIDER_KNOB_IMAGE_PATH); -#endif + slider_->SetImage(SLIDER_BACKGROUND_IMAGE_PATH, SLIDER_INDICATOR_IMAGE_PATH); + slider_->SetKnobImage(SLIDER_KNOB_IMAGE_PATH); slider_->SetDirection(UISlider::Direction::DIR_BOTTOM_TO_TOP); } else if (&view == noImageBtn_) { slider_->SetValidHeight(g_height); slider_->SetValidWidth(g_width); -#if ENABLE_SLIDER_KNOB slider_->SetKnobWidth(g_knobWidth); - slider_->SetImage(static_cast(nullptr), static_cast(nullptr), - static_cast(nullptr)); -#endif + slider_->SetImage(static_cast(nullptr), static_cast(nullptr)); + slider_->SetKnobImage(static_cast(nullptr)); } else if (&view == setStyleBtn_) { Style style = StyleDefault::GetDefaultStyle(); style.bgColor_ = Color::Green(); @@ -537,37 +542,23 @@ bool UITestSlider::ExpandClick2(UIView& view, const ClickEvent& event) style.bgColor_ = Color::Red(); slider_->SetForegroundStyle(style); style.bgColor_ = Color::Gray(); -#if ENABLE_SLIDER_KNOB slider_->SetKnobStyle(style); -#endif } else if (&view == getStyleBtn_) { slider_->SetBackgroundStyle(STYLE_BACKGROUND_COLOR, Color::Red().full); slider_->SetForegroundStyle(STYLE_BACKGROUND_COLOR, Color::Yellow().full); -#if ENABLE_SLIDER_KNOB slider_->SetKnobStyle(STYLE_BACKGROUND_COLOR, Color::Green().full); -#endif } else if (&view == incKnobWidthBtn_) { -#if ENABLE_SLIDER_KNOB g_knobWidth++; slider_->SetKnobWidth(g_knobWidth); -#endif } else if (&view == decKnobWidthBtn_) { -#if ENABLE_SLIDER_KNOB g_knobWidth--; slider_->SetKnobWidth(g_knobWidth); -#endif } else if (&view == colorBtn_) { -#if ENABLE_SLIDER_KNOB - slider_->SetSliderColor(Color::Silver(), Color::Blue(), Color::White()); -#else slider_->SetSliderColor(Color::Silver(), Color::Blue()); -#endif + slider_->SetKnobColor(Color::White()); } else if (&view == radiusBtn_) { -#if ENABLE_SLIDER_KNOB - slider_->SetSliderRadius(DEFAULT_RADIUS, DEFAULT_RADIUS, DEFAULT_RADIUS); -#else slider_->SetSliderRadius(DEFAULT_RADIUS, DEFAULT_RADIUS); -#endif + slider_->SetKnobRadius(DEFAULT_RADIUS); } else if (&view == onChangeBtn_) { g_onChange = true; } else if (&view == onReleaseBtn_) { @@ -576,6 +567,14 @@ bool UITestSlider::ExpandClick2(UIView& view, const ClickEvent& event) g_onClick = true; } else if (&view == onDragBtn_) { 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; } diff --git a/test/uitest/test_slider/ui_test_slider.h b/test/uitest/test_slider/ui_test_slider.h index cd0625f91f33c6a811fe9694376e651a4c6891c3..1ed7d9ab653ab27c667ef27bfe67ed93ded5e355 100755 --- a/test/uitest/test_slider/ui_test_slider.h +++ b/test/uitest/test_slider/ui_test_slider.h @@ -75,6 +75,7 @@ public: void UIKit_Slider_Test_SetOnReleaseListener_014(); void UIKit_Slider_Test_SetOnClickCallback_015(); void UIKit_Slider_Test_SetOnDragCallback_016(); + void UIKit_Slider_Test_SetCircularStyle_017(); private: static constexpr int32_t DEFAULT_VALUE = 20; @@ -114,6 +115,7 @@ private: UILabelButton* onReleaseBtn_ = nullptr; UILabelButton* onClickBtn_ = nullptr; UILabelButton* onDragBtn_ = nullptr; + UILabelButton* circularStyleBtn_ = nullptr; }; } // namespace OHOS #endif // UI_TEST_SLIDER_H diff --git a/test/uitest/test_ui_dump_dom_tree/ui_test_dump_dom.cpp b/test/uitest/test_ui_dump_dom_tree/ui_test_dump_dom.cpp index 370de8ca2c31247226c3ffc31e17e79f33089436..f7b68250efc845fbf5f3023ce6095d15a24ed6ab 100755 --- a/test/uitest/test_ui_dump_dom_tree/ui_test_dump_dom.cpp +++ b/test/uitest/test_ui_dump_dom_tree/ui_test_dump_dom.cpp @@ -302,12 +302,9 @@ void UITestDumpDomTree::UIKit_TestDumpDom_003() slider->SetStep(0); 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 -#if ENABLE_SLIDER_KNOB slider->SetKnobWidth(50); // 50: knob width slider->SetKnobStyle(StyleDefault::GetSliderKnobStyle()); - slider->SetImage(static_cast(nullptr), static_cast(nullptr), - static_cast(nullptr)); -#endif + slider->SetImage(static_cast(nullptr), static_cast(nullptr)); slider->EnableBackground(true); slider->SetViewId("dump_slider"); group5->Add(slider); diff --git a/test/unittest/components/ui_slider_unit_test.cpp b/test/unittest/components/ui_slider_unit_test.cpp index 68484da786c7026301e8a53feae35e3666d95810..c95d1b6fef2ff972aac72865fd9da0fbf18dec00 100755 --- a/test/unittest/components/ui_slider_unit_test.cpp +++ b/test/unittest/components/ui_slider_unit_test.cpp @@ -57,7 +57,7 @@ HWTEST_F(UISliderTest, UISliderGetViewType_001, TestSize.Level1) } EXPECT_EQ(slider_->GetViewType(), UI_SLIDER); } -#if ENABLE_SLIDER_KNOB + /** * @tc.name:UISliderSetKnobWidth_001 * @tc.desc: Verify SetKnobWidth function, equal. @@ -91,5 +91,4 @@ HWTEST_F(UISliderTest, UISliderSetKnobStyle_001, TestSize.Level0) slider_->SetKnobStyle(STYLE_BACKGROUND_COLOR, Color::Gray().full); EXPECT_EQ(slider_->GetKnobStyle().bgColor_.full, Color::Gray().full); } -#endif // ENABLE_SLIDER_KNOB } // namespace OHOS \ No newline at end of file