diff --git a/frameworks/components/ui_checkbox.cpp b/frameworks/components/ui_checkbox.cpp index a8acf0a43da9e2515fbec7d69afea5eddb76d74b..bfdd25a3499b0b5a70916dcbdb98a06cd00d2f74 100755 --- a/frameworks/components/ui_checkbox.cpp +++ b/frameworks/components/ui_checkbox.cpp @@ -21,27 +21,31 @@ namespace OHOS { namespace { - constexpr uint8_t DEFAULT_UNSELECT_BG_OPA = 168; // default background opacity - constexpr float DEFAULT_COEFFICIENT_START_DX = 0.22; // start point: x-cordinate offset - constexpr float DEFAULT_COEFFICIENT_START_DY = 0.5; // start point: y-cordinate offset - constexpr float DEFAULT_COEFFICIENT_MID_DX = 0.2; // middle point: y-cordinate offset - constexpr float DEFAULT_COEFFICIENT_MID_DY = 0.38; // middle point: y-cordinate offset - constexpr int16_t DEFAULT_RATIO_BORDER_RADIUS_LINE_WIDTH = 4; +constexpr uint8_t DEFAULT_UNSELECT_BG_OPA = 168; // default background opacity +constexpr float DEFAULT_COEFFICIENT_START_DX = 0.22; // start point: x-cordinate offset +constexpr float DEFAULT_COEFFICIENT_START_DY = 0.5; // start point: y-cordinate offset +constexpr float DEFAULT_COEFFICIENT_MID_DX = 0.2; // middle point: y-cordinate offset +constexpr float DEFAULT_COEFFICIENT_MID_DY = 0.38; // middle point: y-cordinate offset +constexpr int16_t DEFAULT_RATIO_BORDER_RADIUS_LINE_WIDTH = 4; #if DEFAULT_ANIMATION - constexpr int16_t DEFAULT_ANIMATOR_TIME = 200; - constexpr float BEZIER_CONTROL_POINT_X_1 = 0.33; - constexpr float BEZIER_CONTROL_POINT_X_2 = 0.67; +constexpr int16_t DEFAULT_ANIMATOR_TIME = 200; +constexpr float BEZIER_CONTROL_POINT_X_1 = 0.33; +constexpr float BEZIER_CONTROL_POINT_X_2 = 0.67; #endif -} +} // namespace UICheckBox::UICheckBox() - : state_(UNSELECTED), onStateChangeListener_(nullptr), width_(DEFAULT_HOT_WIDTH), height_(DEFAULT_HOT_HEIGHT), - borderWidth_(DEFAULT_BORDER_WIDTH), backgroundOpacity_(0) + : state_(UNSELECTED), + onStateChangeListener_(nullptr), + width_(DEFAULT_HOT_WIDTH), + height_(DEFAULT_HOT_HEIGHT), + borderWidth_(DEFAULT_BORDER_WIDTH), + backgroundOpacity_(0) { touchable_ = true; style_ = &(StyleDefault::GetBackgroundTransparentStyle()); image_[UNSELECTED].SetSrc(GetCheckBoxOffInfo()); image_[SELECTED].SetSrc(GetCheckBoxOnInfo()); - ImageHeader header = { 0 }; + ImageHeader header = {0}; image_[UNSELECTED].GetHeader(header); Resize(header.width, header.height); #if DEFAULT_ANIMATION @@ -57,19 +61,23 @@ UICheckBox::~UICheckBox() #endif } -void UICheckBox::SetState(UICheckBoxState state) +void UICheckBox::SetState(UICheckBoxState state, bool needAnimater) { if (state_ == state) { return; } state_ = state; if ((image_[SELECTED].GetSrcType() == IMG_SRC_UNKNOWN) || (image_[UNSELECTED].GetSrcType() == IMG_SRC_UNKNOWN)) { + if (needAnimater) { #if DEFAULT_ANIMATION - checkBoxAnimator_.Start(); - ResetCallback(); + checkBoxAnimator_.Start(); + ResetCallback(); #else - backgroundOpacity_ = (state_ == SELECTED) ? OPA_OPAQUE : 0; + backgroundOpacity_ = (state_ == SELECTED) ? OPA_OPAQUE : 0; #endif + } else { + backgroundOpacity_ = (state_ == SELECTED) ? OPA_OPAQUE : 0; + } } if (onStateChangeListener_ != nullptr) { onStateChangeListener_->OnChange(state); @@ -80,9 +88,9 @@ void UICheckBox::SetState(UICheckBoxState state) void UICheckBox::ReverseState() { if (state_ == SELECTED) { - SetState(UNSELECTED); + SetState(UNSELECTED, true); } else { - SetState(SELECTED); + SetState(SELECTED, true); } } @@ -115,7 +123,7 @@ void UICheckBox::CalculateSize() width_ = width; height_ = height; int16_t minValue = (width_ > height_) ? height_ : width_; - borderWidth_ = DEFAULT_BORDER_WIDTH * minValue / DEFAULT_HOT_WIDTH; + borderWidth_ = DEFAULT_BORDER_WIDTH * minValue / DEFAULT_HOT_WIDTH; } void UICheckBox::SelectedStateSoftwareDrawing(BufferInfo& gfxDstBuffer, @@ -134,35 +142,39 @@ void UICheckBox::SelectedStateSoftwareDrawing(BufferInfo& gfxDstBuffer, BaseGfxEngine::GetInstance()->DrawRect(gfxDstBuffer, rect, trunc, styleSelect, opaScale_); int16_t dx = borderWidth_ * DEFAULT_COEFFICIENT_START_DX; int16_t dy = borderWidth_ * DEFAULT_COEFFICIENT_START_DY; - Point start = { static_cast(rect.GetX() + dx), static_cast(rect.GetY() + dy) }; + Point start = {static_cast(rect.GetX() + dx), static_cast(rect.GetY() + dy)}; dx = borderWidth_ * DEFAULT_COEFFICIENT_MID_DX; - Point mid = { static_cast(start.x + dx), static_cast(start.y + dx) }; + Point mid = {static_cast(start.x + dx), static_cast(start.y + dx)}; dx = borderWidth_ * DEFAULT_COEFFICIENT_MID_DY; - Point end = { static_cast(mid.x + dx), static_cast(mid.y - dx) }; + Point end = {static_cast(mid.x + dx), static_cast(mid.y - dx)}; const int16_t half = 2; // 2 :half - ArcInfo arcInfoLeft = { - start, { 0, 0 }, static_cast(rectLineWidth), SEMICIRCLE_IN_DEGREE + QUARTER_IN_DEGREE / half, - QUARTER_IN_DEGREE / half, nullptr - }; - ArcInfo arcInfoMid = { - mid, { 0, 0 }, static_cast(rectLineWidth), SEMICIRCLE_IN_DEGREE - QUARTER_IN_DEGREE / half, - SEMICIRCLE_IN_DEGREE + QUARTER_IN_DEGREE / half, nullptr - }; - ArcInfo arcInfoRight = { - end, { 0, 0 }, static_cast(rectLineWidth), CIRCLE_IN_DEGREE - QUARTER_IN_DEGREE / half, - SEMICIRCLE_IN_DEGREE - QUARTER_IN_DEGREE / half, nullptr - }; + ArcInfo arcInfoLeft = {start, + {0, 0}, + static_cast(rectLineWidth), + SEMICIRCLE_IN_DEGREE + QUARTER_IN_DEGREE / half, + QUARTER_IN_DEGREE / half, + nullptr}; + ArcInfo arcInfoMid = {mid, + {0, 0}, + static_cast(rectLineWidth), + SEMICIRCLE_IN_DEGREE - QUARTER_IN_DEGREE / half, + SEMICIRCLE_IN_DEGREE + QUARTER_IN_DEGREE / half, + nullptr}; + ArcInfo arcInfoRight = {end, + {0, 0}, + static_cast(rectLineWidth), + CIRCLE_IN_DEGREE - QUARTER_IN_DEGREE / half, + SEMICIRCLE_IN_DEGREE - QUARTER_IN_DEGREE / half, + nullptr}; styleSelect.lineColor_ = Color::White(); styleSelect.lineOpa_ = backgroundOpacity_; uint8_t opa = DrawUtils::GetMixOpacity(opaScale_, backgroundOpacity_); BaseGfxEngine::GetInstance()->DrawArc(gfxDstBuffer, arcInfoLeft, trunc, styleSelect, opaScale_, CapType::CAP_NONE); // 2 : double - BaseGfxEngine::GetInstance()->DrawLine(gfxDstBuffer, start, mid, trunc, rectLineWidth * 2, Color::White(), - opa); + BaseGfxEngine::GetInstance()->DrawLine(gfxDstBuffer, start, mid, trunc, rectLineWidth * 2, Color::White(), opa); BaseGfxEngine::GetInstance()->DrawArc(gfxDstBuffer, arcInfoMid, trunc, styleSelect, opaScale_, CapType::CAP_NONE); // 2 : double - BaseGfxEngine::GetInstance()->DrawLine(gfxDstBuffer, mid, end, trunc, rectLineWidth * 2, Color::White(), - opa); + BaseGfxEngine::GetInstance()->DrawLine(gfxDstBuffer, mid, end, trunc, rectLineWidth * 2, Color::White(), opa); BaseGfxEngine::GetInstance()->DrawArc(gfxDstBuffer, arcInfoRight, trunc, styleSelect, opaScale_, CapType::CAP_NONE); } @@ -172,8 +184,8 @@ void UICheckBox::UnSelectedStateSoftwareDrawing(BufferInfo& gfxDstBuffer, int16_t borderRadius, int16_t rectLineWidth) { - Rect contentRect = GetContentRect(); - Style styleUnSelect = StyleDefault::GetBackgroundTransparentStyle(); + Rect contentRect = GetContentRect(); + Style styleUnSelect = StyleDefault::GetBackgroundTransparentStyle(); styleUnSelect.borderWidth_ = rectLineWidth; styleUnSelect.borderRadius_ = borderRadius; styleUnSelect.borderColor_ = Color::White(); @@ -218,7 +230,7 @@ void UICheckBox::OnDraw(BufferInfo& gfxDstBuffer, const Rect& invalidatedArea) coords.SetWidth(imgWidth); coords.SetHeight(imgHeight); BaseGfxEngine::GetInstance()->DrawRect(gfxDstBuffer, GetRect(), invalidatedArea, *style_, opaScale_); - int16_t offsetLeft = (GetWidth() - imgWidth) / 2; // 2 : half + int16_t offsetLeft = (GetWidth() - imgWidth) / 2; // 2 : half int16_t offsetTop = (GetHeight() - imgHeight) / 2; // 2 : half coords.SetX(coords.GetX() + offsetLeft); coords.SetY(coords.GetY() + offsetTop); @@ -233,11 +245,11 @@ void UICheckBox::OnDraw(BufferInfo& gfxDstBuffer, const Rect& invalidatedArea) } CalculateSize(); int16_t rectLineWidth = borderWidth_ / DEFAULT_BORDER_WIDTH; - int16_t borderRadius = rectLineWidth * DEFAULT_RATIO_BORDER_RADIUS_LINE_WIDTH; + int16_t borderRadius = rectLineWidth * DEFAULT_RATIO_BORDER_RADIUS_LINE_WIDTH; BaseGfxEngine::GetInstance()->DrawRect(gfxDstBuffer, GetRect(), invalidatedArea, *style_, opaScale_); - int16_t x = contentRect.GetX() + (width_ - borderWidth_) / 2; // 2: half + int16_t x = contentRect.GetX() + (width_ - borderWidth_) / 2; // 2: half int16_t y = contentRect.GetY() + (height_ - borderWidth_) / 2; // 2: half - Rect rect(x, y, x + borderWidth_, y + borderWidth_); + Rect rect(x, y, x + borderWidth_, y + borderWidth_); #if DEFAULT_ANIMATION UnSelectedStateSoftwareDrawing(gfxDstBuffer, rect, trunc, borderRadius, rectLineWidth); SelectedStateSoftwareDrawing(gfxDstBuffer, rect, trunc, borderRadius, rectLineWidth); diff --git a/frameworks/components/ui_radio_button.cpp b/frameworks/components/ui_radio_button.cpp index 9464007baeb95dd1f56c0ac1b26d04ff72ac29e8..e00b1092d007485f9ce51c9a8bca5e193cc49776 100755 --- a/frameworks/components/ui_radio_button.cpp +++ b/frameworks/components/ui_radio_button.cpp @@ -14,6 +14,7 @@ */ #include "components/ui_radio_button.h" + #include "common/image.h" #include "components/root_view.h" #include "components/ui_view_group.h" @@ -23,17 +24,25 @@ #include "imgdecode/cache_manager.h" #include "securec.h" +namespace { +constexpr int16_t DEFAULT_RADIUS_BIG = 11; +constexpr int16_t DEFAULT_RADIUS_SMALL = 6; +constexpr int16_t DEFAULT_LINE_WIDTH = 1; +#if DEFAULT_ANIMATION +constexpr float SCALE_BEZIER_CONTROL_POINT_X_1 = 0.33; +constexpr float SCALE_BEZIER_CONTROL_POINT_X_2 = 0.67; +constexpr float ALPHA_BEZIER_CONTROL_POINT_X_1 = 0.2; +constexpr float ALPHA_BEZIER_CONTROL_POINT_X_2 = 0.2; +#endif +} // namespace namespace OHOS { -UIRadioButton::UIRadioButton() : name_(nullptr), radiusBig_(DEFAULT_RADIUS_BIG), radiusSmall_(DEFAULT_RADIUS_SMALL), - lineWidth_(DEFAULT_LINE_WIDTH) -{ - image_[UNSELECTED].SetSrc(""); - image_[SELECTED].SetSrc(""); - Resize(width_, height_); -} - -UIRadioButton::UIRadioButton(const char* name) : name_(nullptr), radiusBig_(DEFAULT_RADIUS_BIG), - radiusSmall_(DEFAULT_RADIUS_SMALL), lineWidth_(DEFAULT_LINE_WIDTH) +UIRadioButton::UIRadioButton() : UIRadioButton(nullptr) {} +UIRadioButton::UIRadioButton(const char* name) + : name_(nullptr), + radiusBig_(DEFAULT_RADIUS_BIG), + radiusSmall_(DEFAULT_RADIUS_SMALL), + lineWidth_(DEFAULT_LINE_WIDTH), + currentRadius_(0) { SetName(name); image_[UNSELECTED].SetSrc(""); @@ -43,7 +52,7 @@ UIRadioButton::UIRadioButton(const char* name) : name_(nullptr), radiusBig_(DEFA bool UIRadioButton::OnClickEvent(const ClickEvent& event) { - SetState(SELECTED); + SetState(SELECTED, true); Invalidate(); UIView* view = this; while ((view != nullptr) && (view->GetParent() != nullptr)) { @@ -55,19 +64,21 @@ bool UIRadioButton::OnClickEvent(const ClickEvent& event) void UIRadioButton::CalculateSize() { - int16_t width = GetWidth(); - int16_t height = GetHeight(); - if ((width_ == width) && (height_ == height)) { - return; - } - width_ = width; - height_ = height; + width_ = GetWidth(); + height_ = GetHeight(); int16_t minValue = (width_ > height_) ? height_ : width_; radiusBig_ = DEFAULT_RADIUS_BIG * minValue / DEFAULT_HOT_WIDTH; radiusSmall_ = DEFAULT_RADIUS_SMALL * minValue / DEFAULT_HOT_WIDTH; if (minValue >= DEFAULT_HOT_WIDTH) { lineWidth_ = DEFAULT_LINE_WIDTH * minValue / DEFAULT_HOT_WIDTH; } +#if DEFAULT_ANIMATION + if (checkBoxAnimator_.GetState() != Animator::START) { + currentRadius_ = (state_ == SELECTED) ? radiusSmall_ : 0; + } +#else + currentRadius_ = (state_ == SELECTED) ? radiusSmall_ : 0; +#endif } void UIRadioButton::OnDraw(BufferInfo& gfxDstBuffer, const Rect& invalidatedArea) @@ -82,40 +93,26 @@ void UIRadioButton::OnDraw(BufferInfo& gfxDstBuffer, const Rect& invalidatedArea int16_t dy = height_ >> 1; int16_t x = contentRect.GetX() + dx; int16_t y = contentRect.GetY() + dy; - ArcInfo arcInfoBig = { { x, y }, { 0 }, radiusBig_, 0, CIRCLE_IN_DEGREE, nullptr }; - ArcInfo arcInfoSmall = { { x, y }, { 0 }, radiusSmall_, 0, CIRCLE_IN_DEGREE, nullptr }; + ArcInfo arcInfoBig = {{x, y}, {0}, radiusBig_, 0, CIRCLE_IN_DEGREE, nullptr}; + ArcInfo arcInfoSmall = {{x, y}, {0}, currentRadius_, 0, CIRCLE_IN_DEGREE, nullptr}; Rect trunc = invalidatedArea; bool isIntersect = trunc.Intersect(trunc, contentRect); - switch (state_) { - case SELECTED: { - Style styleSelect = StyleDefault::GetBackgroundTransparentStyle(); - styleSelect.lineWidth_ = arcInfoBig.radius; - styleSelect.lineColor_ = Color::GetColorFromRGB(0x1F, 0x71, 0xFF); - if (isIntersect) { - BaseGfxEngine::GetInstance()->DrawArc(gfxDstBuffer, arcInfoBig, trunc, styleSelect, - OPA_OPAQUE, CapType::CAP_NONE); - } - styleSelect.lineWidth_ = arcInfoSmall.radius; - styleSelect.lineColor_ = Color::White(); - if (isIntersect) { - BaseGfxEngine::GetInstance()->DrawArc(gfxDstBuffer, arcInfoSmall, trunc, styleSelect, - OPA_OPAQUE, CapType::CAP_NONE); - } - break; - } - case UNSELECTED: { - Style styleUnSelect = StyleDefault::GetBackgroundTransparentStyle(); - styleUnSelect.lineColor_ = Color::White(); - styleUnSelect.lineWidth_ = lineWidth_; - if (isIntersect) { - // 0xa8 : opacity of drawing unselected button arc edge. - BaseGfxEngine::GetInstance()->DrawArc(gfxDstBuffer, arcInfoBig, trunc, styleUnSelect, - 0xa8, CapType::CAP_NONE); - } - break; + if (isIntersect) { + Style style = StyleDefault::GetBackgroundTransparentStyle(); + if (backgroundOpacity_ != OPA_OPAQUE) { + style.lineColor_ = Color::White(); + style.lineWidth_ = lineWidth_; + // 0xa8 : opacity of drawing unselected button arc edge. + BaseGfxEngine::GetInstance()->DrawArc(gfxDstBuffer, arcInfoBig, trunc, style, 0xa8, CapType::CAP_NONE); } - default: - break; + style.lineWidth_ = arcInfoBig.radius; + style.lineColor_ = Color::GetColorFromRGB(0x1F, 0x71, 0xFF); + BaseGfxEngine::GetInstance()->DrawArc(gfxDstBuffer, arcInfoBig, trunc, style, backgroundOpacity_, + CapType::CAP_NONE); + style.lineWidth_ = arcInfoSmall.radius; + style.lineColor_ = Color::White(); + BaseGfxEngine::GetInstance()->DrawArc(gfxDstBuffer, arcInfoSmall, trunc, style, OPA_OPAQUE, + CapType::CAP_NONE); } } } @@ -160,7 +157,22 @@ void UIRadioButton::FindRadioButtonAndChangeState(UIView* view) } UIRadioButton* uiRadioButtonInfo = static_cast(view); if ((uiRadioButtonInfo->GetName() != nullptr) && (strcmp(uiRadioButtonInfo->GetName(), name_) == 0)) { - uiRadioButtonInfo->SetState(UNSELECTED); + uiRadioButtonInfo->SetState(UNSELECTED, true); } } +#if DEFAULT_ANIMATION +void UIRadioButton::Callback(UIView* view) +{ + runTime_ = checkBoxAnimator_.GetRunTime(); + float x = static_cast(runTime_) / checkBoxAnimator_.GetTime(); + float coefficient = + Interpolation::GetBezierY(x, SCALE_BEZIER_CONTROL_POINT_X_1, 0, SCALE_BEZIER_CONTROL_POINT_X_2, 1); + backgroundOpacity_ = (state_ == SELECTED) ? (static_cast(coefficient * OPA_OPAQUE)) : + (static_cast((1 - coefficient) * OPA_OPAQUE)); + coefficient = Interpolation::GetBezierY(x, ALPHA_BEZIER_CONTROL_POINT_X_1, 0, ALPHA_BEZIER_CONTROL_POINT_X_2, 1); + currentRadius_ = (state_ == SELECTED) ? (static_cast(coefficient * radiusSmall_)) : + (static_cast((1 - coefficient) * radiusSmall_)); + Invalidate(); +} +#endif } // namespace OHOS diff --git a/frameworks/components/ui_toggle_button.cpp b/frameworks/components/ui_toggle_button.cpp index 0067541587e7e9e66c9881226a3e64c2528898ae..4a1527f62ddffe573af1905d68b9e660d43a481a 100755 --- a/frameworks/components/ui_toggle_button.cpp +++ b/frameworks/components/ui_toggle_button.cpp @@ -14,16 +14,33 @@ */ #include "components/ui_toggle_button.h" + #include "common/image.h" #include "engines/gfx/gfx_engine_manager.h" #include "imgdecode/cache_manager.h" - +namespace { +constexpr int16_t TOGGLE_BTN_WIDTH = 32; +constexpr int16_t TOGGLE_BTN_CORNER_RADIUS = 11; +constexpr int16_t TOGGLE_BTN_RADIUS_DIFF = 2; +constexpr uint8_t TOGGLE_BTN_UNSELECTED_OPA = 97; +#if DEFAULT_ANIMATION +constexpr int16_t DEFAULT_ANIMATOR_TIME = 150; +constexpr float BEZIER_CONTROL_POINT_X_1 = 0.2; +constexpr float BEZIER_CONTROL_POINT_X_2 = 0.2; +#endif +} // namespace namespace OHOS { -UIToggleButton::UIToggleButton() : corner_(DEFAULT_CORNER_RADIUS), radius_(DEFAULT_CORNER_RADIUS - DEAFULT_RADIUS_DIFF), - rectWidth_(DEFAULT_WIDTH) +UIToggleButton::UIToggleButton() + : corner_(TOGGLE_BTN_CORNER_RADIUS), + radius_(TOGGLE_BTN_CORNER_RADIUS - TOGGLE_BTN_RADIUS_DIFF), + rectWidth_(TOGGLE_BTN_WIDTH) { + backgroundOpacity_ = TOGGLE_BTN_UNSELECTED_OPA; image_[UNSELECTED].SetSrc(""); image_[SELECTED].SetSrc(""); +#if DEFAULT_ANIMATION + checkBoxAnimator_.SetTime(DEFAULT_ANIMATOR_TIME); +#endif Resize(width_, height_); } @@ -39,18 +56,35 @@ void UIToggleButton::SetState(bool state) void UIToggleButton::CalculateSize() { - int16_t width = GetWidth(); - int16_t height = GetHeight(); - if ((width_ == width) && (height_ == height)) { - return; - } - width_ = width; - height_ = height; + width_ = GetWidth(); + height_ = GetHeight(); int16_t minValue = (width_ > height_) ? height_ : width_; - corner_ = DEFAULT_CORNER_RADIUS * minValue / DEFAULT_HOT_HEIGHT; - int16_t radiusDiff = DEAFULT_RADIUS_DIFF * minValue / DEFAULT_HOT_WIDTH; + corner_ = TOGGLE_BTN_CORNER_RADIUS * minValue / DEFAULT_HOT_HEIGHT; + int16_t radiusDiff = TOGGLE_BTN_RADIUS_DIFF * minValue / DEFAULT_HOT_WIDTH; radius_ = corner_ - radiusDiff; - rectWidth_ = DEFAULT_WIDTH * minValue / DEFAULT_HOT_WIDTH; + rectWidth_ = TOGGLE_BTN_WIDTH * minValue / DEFAULT_HOT_WIDTH; + + Rect contentRect = GetContentRect(); + int16_t dx = (width_ - rectWidth_) >> 1; + int16_t dy = (height_ >> 1) - corner_; + int16_t x = contentRect.GetX() + dx; + int16_t y = contentRect.GetY() + dy; + leftCenter_ = {static_cast(x + corner_), static_cast(y + corner_)}; + rightCenter_ = {static_cast(x + rectWidth_ - corner_), static_cast(y + corner_)}; +#if DEFAULT_ANIMATION + if (checkBoxAnimator_.GetState() != Animator::START) { + currentCenter_ = (state_ == SELECTED) ? rightCenter_ : leftCenter_; + backgroundOpacity_ = (state_ == SELECTED) ? OPA_OPAQUE : TOGGLE_BTN_UNSELECTED_OPA; + bgColor_ = (state_ == SELECTED) ? Color::GetColorFromRGB(DEFAULT_BG_RED, DEFAULT_BG_GREEN, DEFAULT_BG_BLUE) : + Color::White(); + } +#else + currentCenter_ = (state_ == SELECTED) ? rightCenter_ : leftCenter_; + backgroundOpacity_ = (state_ == SELECTED) ? OPA_OPAQUE : TOGGLE_BTN_UNSELECTED_OPA; + bgColor_ = (state_ == SELECTED) ? Color::GetColorFromRGB(DEFAULT_BG_RED, DEFAULT_BG_GREEN, DEFAULT_BG_BLUE) : + Color::White(); +#endif + rectMid_.SetRect(x, y, x + rectWidth_, y + (corner_ << 1) + 1); } void UIToggleButton::OnDraw(BufferInfo& gfxDstBuffer, const Rect& invalidatedArea) @@ -61,54 +95,54 @@ void UIToggleButton::OnDraw(BufferInfo& gfxDstBuffer, const Rect& invalidatedAre CalculateSize(); BaseGfxEngine::GetInstance()->DrawRect(gfxDstBuffer, GetRect(), invalidatedArea, *style_, opaScale_); Rect contentRect = GetContentRect(); - int16_t dx = (width_ - rectWidth_) >> 1; - int16_t dy = (height_ >> 1) - corner_; - int16_t x = contentRect.GetX() + dx; - int16_t y = contentRect.GetY() + dy; - Rect rectMid; - rectMid.SetRect(x, y, x + rectWidth_, y + (corner_ << 1) + 1); Rect trunc = invalidatedArea; bool isIntersect = trunc.Intersect(trunc, contentRect); if (isIntersect == false) { return; } - switch (state_) { - case SELECTED: { - Style styleSelect = StyleDefault::GetBackgroundTransparentStyle(); - styleSelect.borderRadius_ = corner_; - styleSelect.bgColor_ = Color::GetColorFromRGB(DEFAULT_BG_RED, DEFAULT_BG_GREEN, DEFAULT_BG_BLUE); - styleSelect.bgOpa_ = OPA_OPAQUE; - BaseGfxEngine::GetInstance()->DrawRect(gfxDstBuffer, rectMid, trunc, styleSelect, opaScale_); - ArcInfo arcInfoRight = { - { static_cast(x + rectWidth_ - corner_), static_cast(y + corner_) }, { 0 }, - radius_, 0, CIRCLE_IN_DEGREE, nullptr - }; - styleSelect.bgColor_ = Color::White(); - styleSelect.lineWidth_ = radius_; - styleSelect.lineColor_ = Color::White(); - BaseGfxEngine::GetInstance()->DrawArc(gfxDstBuffer, arcInfoRight, trunc, - styleSelect, OPA_OPAQUE, CapType::CAP_NONE); - break; - } - case UNSELECTED: { - Style styleUnSelect = StyleDefault::GetBackgroundTransparentStyle(); - styleUnSelect.bgColor_ = Color::White(); - styleUnSelect.bgOpa_ = DEFAULT_UNSELECTED_OPA; - styleUnSelect.borderRadius_ = corner_; - BaseGfxEngine::GetInstance()->DrawRect(gfxDstBuffer, rectMid, trunc, styleUnSelect, opaScale_); - ArcInfo arcInfoLeft = { - { static_cast(x + corner_), static_cast(y + corner_) }, { 0 }, radius_, 0, - CIRCLE_IN_DEGREE, nullptr - }; - styleUnSelect.lineColor_ = Color::White(); - styleUnSelect.lineWidth_ = radius_; - BaseGfxEngine::GetInstance()->DrawArc(gfxDstBuffer, arcInfoLeft, trunc, - styleUnSelect, OPA_OPAQUE, CapType::CAP_NONE); - break; - } - default: - break; - } + Style styleUnSelect = StyleDefault::GetBackgroundTransparentStyle(); + styleUnSelect.bgColor_ = bgColor_; + styleUnSelect.bgOpa_ = backgroundOpacity_; + styleUnSelect.borderRadius_ = corner_; + BaseGfxEngine::GetInstance()->DrawRect(gfxDstBuffer, rectMid_, trunc, styleUnSelect, opaScale_); + ArcInfo arcInfoLeft = {currentCenter_, {0}, radius_, 0, CIRCLE_IN_DEGREE, nullptr}; + styleUnSelect.lineColor_ = Color::White(); + styleUnSelect.lineWidth_ = radius_; + BaseGfxEngine::GetInstance()->DrawArc(gfxDstBuffer, arcInfoLeft, trunc, styleUnSelect, OPA_OPAQUE, + CapType::CAP_NONE); } } -} // namespace OHOS \ No newline at end of file +#if DEFAULT_ANIMATION +void UIToggleButton::Callback(UIView* view) +{ + runTime_ = checkBoxAnimator_.GetRunTime(); + float x = static_cast(runTime_) / checkBoxAnimator_.GetTime(); + float coefficient = Interpolation::GetBezierY(x, BEZIER_CONTROL_POINT_X_1, 0, BEZIER_CONTROL_POINT_X_2, 1); + if (state_ == SELECTED) { + currentCenter_.y = rightCenter_.y; + currentCenter_.x = (rightCenter_.x - leftCenter_.x) * coefficient + leftCenter_.x; + backgroundOpacity_ = TOGGLE_BTN_UNSELECTED_OPA + (OPA_OPAQUE - TOGGLE_BTN_UNSELECTED_OPA) * coefficient; + bgColor_ = Color::GetMixColor(Color::GetColorFromRGB(DEFAULT_BG_RED, DEFAULT_BG_GREEN, DEFAULT_BG_BLUE), + Color::White(), OPA_OPAQUE * coefficient); + } else { + currentCenter_.y = leftCenter_.y; + currentCenter_.x = rightCenter_.x - (rightCenter_.x - leftCenter_.x) * coefficient; + backgroundOpacity_ = OPA_OPAQUE - (OPA_OPAQUE - TOGGLE_BTN_UNSELECTED_OPA) * coefficient; + bgColor_ = Color::GetMixColor(Color::GetColorFromRGB(DEFAULT_BG_RED, DEFAULT_BG_GREEN, DEFAULT_BG_BLUE), + Color::White(), OPA_OPAQUE * (1 - coefficient)); + } + Invalidate(); +} + +void UIToggleButton::OnStop(UIView& view) +{ + if (state_ == SELECTED) { + bgColor_ = Color::GetColorFromRGB(DEFAULT_BG_RED, DEFAULT_BG_GREEN, DEFAULT_BG_BLUE); + } else { + bgColor_ = Color::White(); + } + backgroundOpacity_ = (state_ == SELECTED) ? OPA_OPAQUE : TOGGLE_BTN_UNSELECTED_OPA; + Invalidate(); +} +#endif +} // namespace OHOS \ No newline at end of file diff --git a/interfaces/kits/components/ui_checkbox.h b/interfaces/kits/components/ui_checkbox.h index cda53a8cb7a5d51436d7147b51ddc51f20806e76..387f66ec44bf5b5e449d28c2e6b61370ec564959 100755 --- a/interfaces/kits/components/ui_checkbox.h +++ b/interfaces/kits/components/ui_checkbox.h @@ -216,13 +216,15 @@ public: * @brief Sets the state for this check box. * * @param state Indicates the state of this check box. For details, see {@link UICheckBoxState}. + * @param needAnimater Whether the state change process can be animated, the setting takes effect when the + * DEFAULT_ANIMATION is 1, {@link DEFAULT_ANIMATION} * @since 1.0 * @version 1.0 */ - void SetState(UICheckBoxState state); + void SetState(UICheckBoxState state, bool needAnimater = false); protected: - virtual void ReverseState(); + void ReverseState(); virtual void CalculateSize(); void SelectedStateSoftwareDrawing(BufferInfo& gfxDstBuffer, Rect rect, diff --git a/interfaces/kits/components/ui_radio_button.h b/interfaces/kits/components/ui_radio_button.h index 1c2f5957e9f9db69015505b8c526654c146c66f8..1f79ee87443ce74cf3d7c24815400d95f01fc13b 100755 --- a/interfaces/kits/components/ui_radio_button.h +++ b/interfaces/kits/components/ui_radio_button.h @@ -134,16 +134,16 @@ public: protected: void CalculateSize() override; +#if DEFAULT_ANIMATION + void Callback(UIView* view) override; +#endif private: void FindRadioButtonAndChangeState(UIView* view); - static constexpr int16_t DEFAULT_RADIUS_BIG = 11; - static constexpr int16_t DEFAULT_RADIUS_SMALL = 6; - static constexpr int16_t DEFAULT_LINE_WIDTH = 1; - char* name_; uint16_t radiusBig_; uint16_t radiusSmall_; + uint16_t currentRadius_; int16_t lineWidth_; }; } // namespace OHOS diff --git a/interfaces/kits/components/ui_toggle_button.h b/interfaces/kits/components/ui_toggle_button.h index 346b5572cd9881659853cdeb10a80ad62f331531..b0b9413b78e013027b815c070aa6f1a2a97cb566 100755 --- a/interfaces/kits/components/ui_toggle_button.h +++ b/interfaces/kits/components/ui_toggle_button.h @@ -107,16 +107,20 @@ public: protected: void CalculateSize() override; +#if DEFAULT_ANIMATION + virtual void Callback(UIView* view) override; + void OnStop(UIView& view) override; +#endif private: - static constexpr int16_t DEFAULT_WIDTH = 32; - static constexpr int16_t DEFAULT_CORNER_RADIUS = 11; - static constexpr int16_t DEAFULT_RADIUS_DIFF = 2; - static constexpr uint8_t DEFAULT_UNSELECTED_OPA = 97; - - uint16_t corner_; - uint16_t radius_; - int16_t rectWidth_; + uint16_t corner_ = 0; + uint16_t radius_ = 0; + int16_t rectWidth_ = 0; + Point leftCenter_ = {0, 0}; + Point rightCenter_ = {0, 0}; + Point currentCenter_ = {0, 0}; + ColorType bgColor_ = Color::White(); + Rect rectMid_ = {0, 0, 0, 0}; }; // class UIToggleButton } // namespace OHOS #endif // GRAPHIC_LITE_UI_TOGGLE_BUTTON_H diff --git a/test/uitest/test_button/ui_test_button.cpp b/test/uitest/test_button/ui_test_button.cpp index de2d69c0f6a79591c21d0d08a553d188bd392636..ae95db75b431debc44bbc2bd49da95d6d9662e24 100755 --- a/test/uitest/test_button/ui_test_button.cpp +++ b/test/uitest/test_button/ui_test_button.cpp @@ -14,6 +14,7 @@ */ #include "ui_test_button.h" + #include "common/screen.h" #include "components/root_view.h" #include "components/ui_digital_clock.h" @@ -122,7 +123,7 @@ void UITestBUTTON::UIKit_Check_Box_Test_001() const UILabel* label = new UILabel(); container_->Add(label); label->SetPosition(TEXT_DISTANCE_TO_LEFT_SIDE, 5, // 5: y-coordinate - Screen::GetInstance().GetWidth(), TITLE_LABEL_DEFAULT_HEIGHT); + Screen::GetInstance().GetWidth(), TITLE_LABEL_DEFAULT_HEIGHT); label->SetText("checkbox功能"); label->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE); @@ -158,43 +159,44 @@ void UITestBUTTON::UIKit_Radio_Button_Test_001() const UIRadioButton* radioButton2 = new UIRadioButton("aaa"); radioButton2->SetPosition(50, 10); // 50: x-coordinate, 10: y-coordinate - radioButton2->SetWidth(40); // 40: width - radioButton2->SetHeight(30); // 30: height + radioButton2->SetWidth(40); // 40: width + radioButton2->SetHeight(30); // 30: height UIRadioButton* radioButton3 = new UIRadioButton("aaa"); radioButton3->SetPosition(110, 10); // 110: x-coordinate, 10: y-coordinate - radioButton3->SetWidth(80); // 80: width - radioButton3->SetHeight(60); // 60: height + radioButton3->SetWidth(80); // 80: width + radioButton3->SetHeight(60); // 60: height UIRadioButton* radioButton4 = new UIRadioButton("aaa"); radioButton4->SetPosition(10, 10); // 10: x-coordinate, 10: y-coordinate - radioButton4->SetWidth(70); // 70: width - radioButton4->SetHeight(90); // 90: width + radioButton4->SetWidth(70); // 70: width + radioButton4->SetHeight(90); // 90: width + radioButton4->SetState(UICheckBox::SELECTED); UIRadioButton* radioButton5 = new UIRadioButton("aaa"); radioButton5->SetPosition(110, 10); // 110: x-coordinate, 10: y-coordinate - radioButton5->SetWidth(-1); // -1: width - radioButton5->SetHeight(90); // 90: width + radioButton5->SetWidth(-1); // -1: width + radioButton5->SetHeight(90); // 90: width UIRadioButton* radioButton6 = new UIRadioButton("aaa"); radioButton6->SetPosition(130, 10); // 130: x-coordinate, 10: y-coordinate - radioButton6->SetWidth(0); // 0: width - radioButton6->SetHeight(0); // 0: width + radioButton6->SetWidth(0); // 0: width + radioButton6->SetHeight(0); // 0: width UIRadioButton* radioButton7 = new UIRadioButton("aaa"); radioButton7->SetPosition(140, 10); // 140: x-coordinate, 10: y-coordinate - radioButton7->SetWidth(1000); // 1000: width - radioButton7->SetHeight(50); // 50: width + radioButton7->SetWidth(1000); // 1000: width + radioButton7->SetHeight(50); // 50: width OHOS::UIViewGroup* viewGroup = new UIViewGroup(); - viewGroup->SetPosition(30, 150); // 30: x-coordinate, 150: y-coordinate - viewGroup->SetWidth(Screen::GetInstance().GetWidth() / 2); // 2: half width + viewGroup->SetPosition(30, 150); // 30: x-coordinate, 150: y-coordinate + viewGroup->SetWidth(Screen::GetInstance().GetWidth() / 2); // 2: half width viewGroup->SetHeight(Screen::GetInstance().GetHeight() / 2); // 2: half height OHOS::UIViewGroup* viewGroup2 = new UIViewGroup(); // 40, increase width, 2: half width, 150: y-coordinate viewGroup2->SetPosition(40 + Screen::GetInstance().GetWidth() / 2, 150); - viewGroup2->SetWidth(Screen::GetInstance().GetWidth() / 2); // 2: half width + viewGroup2->SetWidth(Screen::GetInstance().GetWidth() / 2); // 2: half width viewGroup2->SetHeight(Screen::GetInstance().GetHeight() / 2); // 2: half height viewGroup2->Add(radioButton4); @@ -251,22 +253,22 @@ void UITestBUTTON::UIKit_Toggle_Button_Test_001() label->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE); UIToggleButton* togglebutton = new UIToggleButton(); - togglebutton->SetPosition(20, 300); // 20: x-coordinate, 300: y-coordinate + togglebutton->SetPosition(20, 300); // 20: x-coordinate, 300: y-coordinate togglebutton->SetStyle(STYLE_BACKGROUND_OPA, 0); // 0: opacity togglebutton->SetState(false); UIToggleButton* togglebutton2 = new UIToggleButton(); - togglebutton2->SetPosition(100, 300); // 100: x-coordinate, 300: y-coordinate + togglebutton2->SetPosition(100, 300); // 100: x-coordinate, 300: y-coordinate togglebutton2->SetStyle(STYLE_BACKGROUND_OPA, 0); // 0: opacity togglebutton2->SetState(false); - togglebutton2->SetWidth(60); // 60: width + togglebutton2->SetWidth(60); // 60: width togglebutton2->SetHeight(40); // 40: height UIToggleButton* togglebutton3 = new UIToggleButton(); - togglebutton3->SetPosition(190, 300); // 190: x-coordinate, 300: y-coordinate + togglebutton3->SetPosition(190, 300); // 190: x-coordinate, 300: y-coordinate togglebutton3->SetStyle(STYLE_BACKGROUND_OPA, 0); // 0: opacity togglebutton3->SetState(false); - togglebutton3->SetWidth(50); // 50: width + togglebutton3->SetWidth(50); // 50: width togglebutton3->SetHeight(70); // 70: height UIToggleButton* togglebutton4 = new UIToggleButton(); @@ -276,27 +278,27 @@ void UITestBUTTON::UIKit_Toggle_Button_Test_001() new TestBtnOnStateChangeListener(reinterpret_cast(togglebutton4))); } togglebutton4->SetOnChangeListener(toggleChangeListener_); - togglebutton4->SetPosition(250, 300); // 250: x-coordinate, 300: y-coordinate + togglebutton4->SetPosition(250, 300); // 250: x-coordinate, 300: y-coordinate togglebutton4->SetStyle(STYLE_BACKGROUND_OPA, 0); // 0: opacity togglebutton4->SetState(false); - togglebutton4->SetWidth(80); // 80: width + togglebutton4->SetWidth(80); // 80: width togglebutton4->SetHeight(80); // 80: height togglebutton4->SetState(true); UIToggleButton* togglebutton5 = new UIToggleButton(); togglebutton5->SetPosition(340, 300); // 340: x-coordinate, 300: y-coordinate - togglebutton5->SetWidth(-1); // -1: width - togglebutton5->SetHeight(90); // 90: width + togglebutton5->SetWidth(-1); // -1: width + togglebutton5->SetHeight(90); // 90: width UIToggleButton* togglebutton6 = new UIToggleButton(); togglebutton6->SetPosition(350, 300); // 350: x-coordinate, 300: y-coordinate - togglebutton6->SetWidth(0); // 0: width - togglebutton6->SetHeight(0); // 0: width + togglebutton6->SetWidth(0); // 0: width + togglebutton6->SetHeight(0); // 0: width UIToggleButton* togglebutton7 = new UIToggleButton(); togglebutton7->SetPosition(360, 300); // 360: x-coordinate, 300: y-coordinate - togglebutton7->SetWidth(1000); // 1000: width - togglebutton7->SetHeight(50); // 50: width + togglebutton7->SetWidth(1000); // 1000: width + togglebutton7->SetHeight(50); // 50: width container_->Add(togglebutton); container_->Add(togglebutton2); @@ -320,14 +322,14 @@ void UITestBUTTON::UIKit_Check_Box_Test_002() const UICheckBox* checkbox = new UICheckBox(); checkbox->SetPosition(30, 430); // 30: x-coordinate, 430: y-coordinate - checkbox->SetWidth(130); // 130: width - checkbox->SetHeight(130); // 130: height + checkbox->SetWidth(130); // 130: width + checkbox->SetHeight(130); // 130: height checkbox->SetImages(BLUE_IMAGE_PATH, YELLOW_IMAGE_PATH); UICheckBox* checkbox2 = new UICheckBox(); checkbox2->SetPosition(200, 430); // 200: x-coordinate, 430: y-coordinate - checkbox2->SetWidth(130); // 130: width - checkbox2->SetHeight(130); // 130: height + checkbox2->SetWidth(130); // 130: width + checkbox2->SetHeight(130); // 130: height checkbox2->SetImages(GREEN_IMAGE_PATH, RED_IMAGE_PATH); container_->Add(checkbox); @@ -348,19 +350,19 @@ void UITestBUTTON::UIKit_Radio_Button_Test_002() const UIRadioButton* radioButton = new UIRadioButton("aaa"); radioButton->SetPosition(30, 10); // 30: x-coordinate, 10: y-coordinate - radioButton->SetWidth(130); // 130: width - radioButton->SetHeight(130); // 130: height + radioButton->SetWidth(130); // 130: width + radioButton->SetHeight(130); // 130: height radioButton->SetImages(BLUE_IMAGE_PATH, YELLOW_IMAGE_PATH); UIRadioButton* radioButton2 = new UIRadioButton("aaa"); radioButton2->SetPosition(200, 10); // 200: x-coordinate, 10: y-coordinate - radioButton2->SetWidth(130); // 130: width - radioButton2->SetHeight(130); // 130: height + radioButton2->SetWidth(130); // 130: width + radioButton2->SetHeight(130); // 130: height radioButton2->SetImages(GREEN_IMAGE_PATH, RED_IMAGE_PATH); OHOS::UIViewGroup* viewGroup = new UIViewGroup(); - viewGroup->SetPosition(0, 600); // 0: x-coordinate, 600: y-coordinate - viewGroup->SetWidth(Screen::GetInstance().GetWidth()); // 2: half width + viewGroup->SetPosition(0, 600); // 0: x-coordinate, 600: y-coordinate + viewGroup->SetWidth(Screen::GetInstance().GetWidth()); // 2: half width viewGroup->SetHeight(Screen::GetInstance().GetHeight() / 2); // 2: half height viewGroup->Add(radioButton); @@ -383,10 +385,10 @@ void UITestBUTTON::UIKit_Toggle_Button_Test_002() label->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE); UIToggleButton* togglebutton = new UIToggleButton(); - togglebutton->SetPosition(30, 770); // 30: x-coordinate, 770: y-coordinate + togglebutton->SetPosition(30, 770); // 30: x-coordinate, 770: y-coordinate togglebutton->SetStyle(STYLE_BACKGROUND_OPA, 0); // 0: opacity togglebutton->SetState(true); - togglebutton->SetWidth(130); // 130: width + togglebutton->SetWidth(130); // 130: width togglebutton->SetHeight(130); // 130: height togglebutton->SetImages(BLUE_IMAGE_PATH, YELLOW_IMAGE_PATH); @@ -396,10 +398,10 @@ void UITestBUTTON::UIKit_Toggle_Button_Test_002() new TestBtnOnStateChangeListener(reinterpret_cast(togglebutton2))); } togglebutton2->SetOnChangeListener(toggleChangeListener1_); - togglebutton2->SetPosition(200, 770); // 200: x-coordinate, 770: y-coordinate + togglebutton2->SetPosition(200, 770); // 200: x-coordinate, 770: y-coordinate togglebutton2->SetStyle(STYLE_BACKGROUND_OPA, 0); // 0: opacity togglebutton2->SetState(false); - togglebutton2->SetWidth(130); // 130: width + togglebutton2->SetWidth(130); // 130: width togglebutton2->SetHeight(130); // 130: height togglebutton2->SetImages(GREEN_IMAGE_PATH, RED_IMAGE_PATH); @@ -561,9 +563,8 @@ private: class TestBtnOnClickRevertToOriginStateListener : public UIView::OnClickListener { public: - explicit TestBtnOnClickRevertToOriginStateListener(UIView* uiView) : uiView_(uiView), originColor_(0), - width_(0), height_(0), visible_(false), - touchable_(false) + explicit TestBtnOnClickRevertToOriginStateListener(UIView* uiView) + : uiView_(uiView), originColor_(0), width_(0), height_(0), visible_(false), touchable_(false) { if (uiView != nullptr) { originColor_ = uiView->GetStyle(STYLE_BACKGROUND_COLOR); @@ -638,29 +639,29 @@ void UITestBUTTON::UIKit_Button_Test_002(UIScrollView* container, UIButton* butt } UILabelButton* button8 = GetTestUIButton("隐藏", 430, 940, button); // 430: x-coordinate, 940: y-coordinate if (clickEnableVisiableListener_ == nullptr) { - clickEnableVisiableListener_ = static_cast( - new TestBtnOnClickVisableListener((UIView*)button, false)); + clickEnableVisiableListener_ = + static_cast(new TestBtnOnClickVisableListener((UIView*)button, false)); } button8->SetOnClickListener(clickEnableVisiableListener_); UILabelButton* button9 = GetTestUIButton("显示", 430, 990, button); // 430: x-coordinate, 990: y-coordinate if (clickDisableVisiableListener_ == nullptr) { - clickDisableVisiableListener_ = static_cast( - new TestBtnOnClickVisableListener((UIView*)button, true)); + clickDisableVisiableListener_ = + static_cast(new TestBtnOnClickVisableListener((UIView*)button, true)); } button9->SetOnClickListener(clickDisableVisiableListener_); UILabelButton* button10 = GetTestUIButton("可触摸 ", 520, 940, button); // 520: x-coordinate, 940: y-coordinate if (clickEnableTouchableListener_ == nullptr) { - clickEnableTouchableListener_ = static_cast( - new TestBtnOnClickTouchableListener((UIView*)button, true)); + clickEnableTouchableListener_ = + static_cast(new TestBtnOnClickTouchableListener((UIView*)button, true)); } button10->SetOnClickListener(clickEnableTouchableListener_); UILabelButton* button11 = GetTestUIButton("不可触摸", 520, 990, button); // 520: x-coordinate, 990: y-coordinate if (clickDisableTouchableListener_ == nullptr) { - clickDisableTouchableListener_ = static_cast( - new TestBtnOnClickTouchableListener((UIView*)button, false)); + clickDisableTouchableListener_ = + static_cast(new TestBtnOnClickTouchableListener((UIView*)button, false)); } button11->SetOnClickListener(clickDisableTouchableListener_); @@ -673,22 +674,22 @@ void UITestBUTTON::UIKit_Button_Test_002(UIScrollView* container, UIButton* butt UILabelButton* button13 = GetTestUIButton("变红", 160, 1090, button); // 160: x-coordinate, 1090: y-coordinate if (clickColorToRedListener_ == nullptr) { - clickColorToRedListener_ = static_cast( - new TestBtnOnClickChangeColorListener((UIView*)button, 0xFF, 0, 0)); + clickColorToRedListener_ = + static_cast(new TestBtnOnClickChangeColorListener((UIView*)button, 0xFF, 0, 0)); } button13->SetOnClickListener(clickColorToRedListener_); UILabelButton* button14 = GetTestUIButton("色彩还原", 250, 1040, button); // 250: x-coordinate, 1040: y-coordinate if (clickRevetColorListener_ == nullptr) { - clickRevetColorListener_ = static_cast( - new TestBtnOnClickRevertColorListener((UIView*)button)); + clickRevetColorListener_ = + static_cast(new TestBtnOnClickRevertColorListener((UIView*)button)); } button14->SetOnClickListener(clickRevetColorListener_); UILabelButton* button15 = GetTestUIButton("全部还原", 250, 1090, button); // 250: x-coordinate, 1090: y-coordinate if (clickRevetToOriginListener_ == nullptr) { - clickRevetToOriginListener_ = static_cast( - new TestBtnOnClickRevertToOriginStateListener((UIView*)button)); + clickRevetToOriginListener_ = + static_cast(new TestBtnOnClickRevertToOriginStateListener((UIView*)button)); } button15->SetOnClickListener(clickRevetToOriginListener_); @@ -710,21 +711,21 @@ void UITestBUTTON::UIKit_Button_Test_001() UIButton* button = new UIButton(); button->SetPosition(10, 935); // 10: x-coordinate, 935: y-coordinate - button->SetWidth(80); // 80: width - button->SetHeight(60); // 60: height + button->SetWidth(80); // 80: width + button->SetHeight(60); // 60: height button->SetImageSrc(BLUE_IMAGE_PATH, YELLOW_IMAGE_PATH); UILabelButton* button2 = GetTestUIButton("放大", 160, 940, button); // 160: x-coordinate, 940: y-coordinate if (clickBigListener_ == nullptr) { - clickBigListener_ = static_cast( - new TestBtnOnClickShapeChangeListener(button, CHANGE_SIZE)); + clickBigListener_ = + static_cast(new TestBtnOnClickShapeChangeListener(button, CHANGE_SIZE)); } button2->SetOnClickListener(clickBigListener_); UILabelButton* button3 = GetTestUIButton("缩小", 160, 990, button); // 160: x-coordinate, 990: y-coordinate if (clickSmallListener_ == nullptr) { - clickSmallListener_ = static_cast( - new TestBtnOnClickShapeChangeListener(button, -CHANGE_SIZE)); + clickSmallListener_ = + static_cast(new TestBtnOnClickShapeChangeListener(button, -CHANGE_SIZE)); } button3->SetOnClickListener(clickSmallListener_);