提交 017b82b7 编写于 作者: Y YueBiang

fix bugs of scroll bar

Signed-off-by: NYueBiang <suyue7@huawei.com>
上级 1eccea2e
......@@ -66,10 +66,6 @@ bool Screen::GetCurrentScreenBitmap(ImageInfo& info)
ScreenShape Screen::GetScreenShape()
{
#if RECTANGLE_SCREEN
return ScreenShape::RECTANGLE;
#else
return ScreenShape::CIRCLE;
#endif
return BaseGfxEngine::GetInstance()->GetScreenShape();
}
} // namespace OHOS
......@@ -15,20 +15,11 @@
#include "components/ui_abstract_scroll.h"
#include "animator/interpolation.h"
#include "common/screen.h"
#include "components/ui_abstract_scroll_bar.h"
#include "graphic_timer.h"
#if RECTANGLE_SCREEN
#include "components/ui_box_scroll_bar.h"
#define BAR_OP(obj, op, ...) \
do { \
obj.yScrollBar_->op(__VA_ARGS__); \
obj.xScrollBar_->op(__VA_ARGS__); \
} while (0)
#else
#include "components/ui_arc_scroll_bar.h"
#define BAR_OP(obj, op, ...) obj.yScrollBar_->op(__VA_ARGS__)
#endif
#include "components/ui_box_scroll_bar.h"
#include "graphic_timer.h"
namespace {
#if ENABLE_ROTATE_INPUT
......@@ -84,17 +75,33 @@ private:
bezielY =
Interpolation::GetBezierY(bezielY / OPA_OPAQUE, 0, BEZIER_CONTROL_POINT_Y_1, BEZIER_CONTROL_POINT_X_2, 1);
opa = static_cast<uint8_t>(bezielY * opa);
BAR_OP(scrollView_, SetOpacity, opa);
if (scrollView_.yScrollBarVisible_) {
scrollView_.yScrollBar_->SetOpacity(opa);
}
if (scrollView_.xScrollBarVisible_) {
scrollView_.xScrollBar_->SetOpacity(opa);
}
scrollView_.Invalidate();
}
void OnStop(UIView& view) override
{
if (isEaseIn_) {
BAR_OP(scrollView_, SetOpacity, OPA_OPAQUE);
if (scrollView_.yScrollBarVisible_) {
scrollView_.yScrollBar_->SetOpacity(OPA_OPAQUE);
}
if (Screen::GetInstance().GetScreenShape() == ScreenShape::RECTANGLE &&
scrollView_.xScrollBarVisible_) {
scrollView_.xScrollBar_->SetOpacity(OPA_OPAQUE);
}
timer_.Start(); // The timer is triggered when animation stops.
} else {
BAR_OP(scrollView_, SetOpacity, OPA_TRANSPARENT);
if (scrollView_.yScrollBarVisible_) {
scrollView_.yScrollBar_->SetOpacity(OPA_TRANSPARENT);
}
if (scrollView_.xScrollBarVisible_) {
scrollView_.xScrollBar_->SetOpacity(OPA_TRANSPARENT);
}
}
scrollView_.Invalidate();
}
......@@ -123,27 +130,6 @@ UIAbstractScroll::UIAbstractScroll()
easingFunc_(EasingEquation::CubicEaseOut),
scrollAnimator_(&animatorCallback_, this, 0, true)
{
#if RECTANGLE_SCREEN
xScrollBar_ = new UIBoxScrollBar();
if (xScrollBar_ == nullptr) {
GRAPHIC_LOGE("new UIBoxScrollBar fail");
return;
}
yScrollBar_ = new UIBoxScrollBar();
#else
yScrollBar_ = new UIArcScrollBar();
#endif
if (yScrollBar_ == nullptr) {
GRAPHIC_LOGE("new ScrollBar fail");
return;
}
#if DEFAULT_ANIMATION
barEaseInOutAnimator_ = new BarEaseInOutAnimator(*this);
if (barEaseInOutAnimator_ == nullptr) {
GRAPHIC_LOGE("new BarEaseInOutAnimator fail");
return;
}
#endif
#if ENABLE_FOCUS_MANAGER
focusable_ = true;
#endif
......@@ -160,15 +146,19 @@ UIAbstractScroll::UIAbstractScroll()
UIAbstractScroll::~UIAbstractScroll()
{
#if DEFAULT_ANIMATION
delete barEaseInOutAnimator_;
barEaseInOutAnimator_ = nullptr;
#endif
#if RECTANGLE_SCREEN
delete xScrollBar_;
xScrollBar_ = nullptr;
if (barEaseInOutAnimator_ != nullptr) {
delete barEaseInOutAnimator_;
barEaseInOutAnimator_ = nullptr;
}
#endif
delete yScrollBar_;
yScrollBar_ = nullptr;
if (xScrollBar_ != nullptr) {
delete xScrollBar_;
xScrollBar_ = nullptr;
}
if (yScrollBar_ != nullptr) {
delete yScrollBar_;
yScrollBar_ = nullptr;
}
}
void UIAbstractScroll::MoveChildByOffset(int16_t offsetX, int16_t offsetY)
......@@ -185,21 +175,6 @@ void UIAbstractScroll::MoveChildByOffset(int16_t offsetX, int16_t offsetY)
view->SetPosition(x, y);
view = view->GetNextSibling();
}
Rect childrenRect = GetAllChildRelativeRect();
/* calculate scrollBar's the proportion of foreground */
int16_t totalLen = childrenRect.GetHeight() + 2 * scrollBlankSize_; // 2: two blank space on both sizes
int16_t len = GetHeight();
yScrollBar_->SetForegroundProportion(static_cast<float>(len) / totalLen);
/* calculate scrolling progress */
yScrollBar_->SetScrollProgress(static_cast<float>(scrollBlankSize_ - childrenRect.GetTop()) / (totalLen - len));
#if RECTANGLE_SCREEN
/* so do x-bar */
totalLen = childrenRect.GetWidth() + 2 * scrollBlankSize_; // 2: two blank space on both sizes
len = GetWidth();
xScrollBar_->SetForegroundProportion(static_cast<float>(len) / totalLen);
xScrollBar_->SetScrollProgress(static_cast<float>(scrollBlankSize_ - childrenRect.GetLeft()) / (totalLen - len));
#endif
Invalidate();
}
......@@ -319,29 +294,61 @@ void UIAbstractScroll::ListAnimatorCallback::Callback(UIView* view)
}
}
void UIAbstractScroll::OnPostDraw(BufferInfo& gfxDstBuffer, const Rect& invalidatedArea)
void UIAbstractScroll::SetXScrollBarVisible(bool visible)
{
Rect scrollRect = GetRect();
uint8_t opa = GetMixOpaScale();
#if RECTANGLE_SCREEN
if (yScrollBarVisible_) {
yScrollBar_->SetPosition(scrollRect.GetRight() - SCROLL_BAR_WIDTH + 1, scrollRect.GetTop(), SCROLL_BAR_WIDTH,
scrollRect.GetHeight());
yScrollBar_->OnDraw(gfxDstBuffer, invalidatedArea, opa);
if (Screen::GetInstance().GetScreenShape() == ScreenShape::CIRCLE) {
return;
} else if (visible && xScrollBar_ == nullptr) {
xScrollBar_ = new UIBoxScrollBar();
}
if (xScrollBarVisible_) {
xScrollBar_->SetPosition(scrollRect.GetLeft(), scrollRect.GetBottom() - SCROLL_BAR_WIDTH + 1,
scrollRect.GetWidth() - SCROLL_BAR_WIDTH, SCROLL_BAR_WIDTH);
xScrollBar_->OnDraw(gfxDstBuffer, invalidatedArea, opa);
xScrollBarVisible_ = visible;
#if DEFAULT_ANIMATION
if (xScrollBarVisible_ && barEaseInOutAnimator_ == nullptr) {
barEaseInOutAnimator_ = new BarEaseInOutAnimator(*this);
}
#else
if (yScrollBarVisible_) {
int16_t x = scrollRect.GetX() + (GetWidth() / 2); // 2: half
int16_t y = scrollRect.GetY() + (GetHeight() / 2); // 2: half
yScrollBar_->SetPosition(x, y, SCROLL_BAR_WIDTH, GetWidth() / 2); // 2: half
yScrollBar_->OnDraw(gfxDstBuffer, invalidatedArea, opa);
#endif
}
void UIAbstractScroll::SetYScrollBarVisible(bool visible)
{
yScrollBarVisible_ = visible;
if (yScrollBarVisible_ && yScrollBar_ == nullptr) {
if (Screen::GetInstance().GetScreenShape() == ScreenShape::CIRCLE) {
yScrollBar_ = new UIArcScrollBar();
} else {
yScrollBar_ = new UIBoxScrollBar();
}
}
#if DEFAULT_ANIMATION
if (yScrollBarVisible_ && barEaseInOutAnimator_ == nullptr) {
barEaseInOutAnimator_ = new BarEaseInOutAnimator(*this);
}
#endif
}
void UIAbstractScroll::OnPostDraw(BufferInfo& gfxDstBuffer, const Rect& invalidatedArea)
{
Rect scrollRect = GetRect();
uint8_t opa = GetMixOpaScale();
if (Screen::GetInstance().GetScreenShape() == ScreenShape::RECTANGLE) {
if (yScrollBarVisible_) {
yScrollBar_->SetPosition(scrollRect.GetRight() - SCROLL_BAR_WIDTH + 1, scrollRect.GetTop(),
SCROLL_BAR_WIDTH, scrollRect.GetHeight());
yScrollBar_->OnDraw(gfxDstBuffer, invalidatedArea, opa);
}
if (xScrollBarVisible_) {
xScrollBar_->SetPosition(scrollRect.GetLeft(), scrollRect.GetBottom() - SCROLL_BAR_WIDTH + 1,
scrollRect.GetWidth() - SCROLL_BAR_WIDTH, SCROLL_BAR_WIDTH);
xScrollBar_->OnDraw(gfxDstBuffer, invalidatedArea, opa);
}
} else {
if (yScrollBarVisible_) {
int16_t x = scrollRect.GetX() + (GetWidth() / 2); // 2: half
int16_t y = scrollRect.GetY() + (GetHeight() / 2); // 2: half
yScrollBar_->SetPosition(x, y, SCROLL_BAR_WIDTH, GetWidth() / 2); // 2: half
yScrollBar_->OnDraw(gfxDstBuffer, invalidatedArea, opa);
}
}
UIView::OnPostDraw(gfxDstBuffer, invalidatedArea);
}
......
......@@ -14,60 +14,11 @@
*/
#include "components/ui_abstract_scroll_bar.h"
#include "gfx_utils/graphic_log.h"
#include "themes/theme_manager.h"
namespace OHOS {
UIAbstractScrollBar::UIAbstractScrollBar() : backgroundStyleAllocFlag_(false), foregroundStyleAllocFlag_(false)
UIAbstractScrollBar::UIAbstractScrollBar()
{
Theme* theme = ThemeManager::GetInstance().GetCurrent();
if (theme != nullptr) {
backgroundStyle_ = &(theme->GetProgressBackgroundStyle());
foregroundStyle_ = &(theme->GetProgressForegroundStyle());
} else {
backgroundStyle_ = &(StyleDefault::GetProgressBackgroundStyle());
foregroundStyle_ = &(StyleDefault::GetProgressForegroundStyle());
}
backgroundStyle_ = &(StyleDefault::GetScrollBarBackgroundStyle());
foregroundStyle_ = &(StyleDefault::GetScrollBarForegroundStyle());
}
UIAbstractScrollBar::~UIAbstractScrollBar()
{
if (backgroundStyleAllocFlag_) {
delete backgroundStyle_;
backgroundStyle_ = nullptr;
backgroundStyleAllocFlag_ = false;
}
if (foregroundStyleAllocFlag_) {
delete foregroundStyle_;
foregroundStyle_ = nullptr;
foregroundStyleAllocFlag_ = false;
}
}
void UIAbstractScrollBar::SetBackgroundStyle(const Style& backroundStyle)
{
if (!backgroundStyleAllocFlag_) {
backgroundStyle_ = new Style();
if (backgroundStyle_ == nullptr) {
GRAPHIC_LOGE("new Style fail");
return;
}
backgroundStyleAllocFlag_ = true;
}
*backgroundStyle_ = backroundStyle;
}
void UIAbstractScrollBar::SetForegroundStyle(const Style& foregroundStyle)
{
if (!foregroundStyleAllocFlag_) {
foregroundStyle_ = new Style();
if (foregroundStyle_ == nullptr) {
GRAPHIC_LOGE("new Style fail");
return;
}
foregroundStyleAllocFlag_ = true;
}
*foregroundStyle_ = foregroundStyle;
}
} // namespace OHOS
\ No newline at end of file
} // namespace OHOS
......@@ -25,16 +25,12 @@ class UIAbstractScrollBar : public HeapBase {
public:
UIAbstractScrollBar();
virtual ~UIAbstractScrollBar();
virtual ~UIAbstractScrollBar() {};
virtual void SetPosition(int16_t x, int16_t y, int16_t width, int16_t height) {}
virtual void OnDraw(BufferInfo& gfxDstBuffer, const Rect& invalidatedArea, uint8_t backgroundOpa) {}
void SetBackgroundStyle(const Style& backroundStyle);
void SetForegroundStyle(const Style& foregroundStyle);
void SetScrollProgress(float scrollProgress)
{
scrollProgress_ = scrollProgress;
......@@ -59,8 +55,6 @@ public:
}
protected:
bool backgroundStyleAllocFlag_ : 1;
bool foregroundStyleAllocFlag_ : 1;
uint8_t opacity_ = OPA_TRANSPARENT;
float scrollProgress_ = 0;
float foregroundProportion_ = 0;
......
......@@ -18,7 +18,21 @@
#include "draw/draw_arc.h"
#include "engines/gfx/gfx_engine_manager.h"
namespace {
constexpr uint16_t START_ANGLE_IN_DEGREE = 60;
constexpr uint16_t END_ANGLE_IN_DEGREE = 120;
constexpr uint16_t SCROLL_BAR_WIDTH = 4;
constexpr uint16_t SCROLL_BAR_MIN_ARC = 10;
} // namespace
namespace OHOS {
UIArcScrollBar::UIArcScrollBar()
: radius_(0),
width_(SCROLL_BAR_WIDTH),
startAngle_(START_ANGLE_IN_DEGREE),
endAngle_(END_ANGLE_IN_DEGREE),
center_({0, 0}) {}
void UIArcScrollBar::SetPosition(int16_t x, int16_t y, int16_t width, int16_t radius)
{
if ((width > 0) && (radius > 0)) {
......@@ -40,6 +54,9 @@ void UIArcScrollBar::OnDraw(BufferInfo& gfxDstBuffer, const Rect& invalidatedAre
void UIArcScrollBar::DrawForeground(BufferInfo& gfxDstBuffer, const Rect& invalidatedArea, uint8_t backgroundOpa)
{
uint16_t foregoundAngleRange = foregroundProportion_ * (END_ANGLE_IN_DEGREE - START_ANGLE_IN_DEGREE);
if (foregoundAngleRange < SCROLL_BAR_MIN_ARC) {
foregoundAngleRange = SCROLL_BAR_MIN_ARC;
}
int16_t minAngle = START_ANGLE_IN_DEGREE;
int16_t maxAngle = END_ANGLE_IN_DEGREE - foregoundAngleRange;
int16_t startAngle = minAngle + scrollProgress_ * (maxAngle - minAngle);
......@@ -54,8 +71,6 @@ void UIArcScrollBar::DrawForeground(BufferInfo& gfxDstBuffer, const Rect& invali
arcInfo.center = center_;
arcInfo.startAngle = MATH_MAX(startAngle, START_ANGLE_IN_DEGREE);
arcInfo.endAngle = MATH_MIN(endAngle, END_ANGLE_IN_DEGREE);
foregroundStyle_->lineCap_ = CapType::CAP_ROUND;
foregroundStyle_->lineWidth_ = width_;
BaseGfxEngine::GetInstance()->DrawArc(gfxDstBuffer, arcInfo, invalidatedArea, *foregroundStyle_, backgroundOpa,
foregroundStyle_->lineCap_);
}
......@@ -67,8 +82,6 @@ void UIArcScrollBar::DrawBackground(BufferInfo& gfxDstBuffer, const Rect& invali
arcInfo.center = center_;
arcInfo.startAngle = START_ANGLE_IN_DEGREE;
arcInfo.endAngle = END_ANGLE_IN_DEGREE;
backgroundStyle_->lineCap_ = CapType::CAP_ROUND;
backgroundStyle_->lineWidth_ = width_;
BaseGfxEngine::GetInstance()->DrawArc(gfxDstBuffer, arcInfo, invalidatedArea, *backgroundStyle_, backgroundOpa,
backgroundStyle_->lineCap_);
}
......
......@@ -21,7 +21,7 @@
namespace OHOS {
class UIArcScrollBar : public UIAbstractScrollBar {
public:
UIArcScrollBar() = default;
UIArcScrollBar();
virtual ~UIArcScrollBar() = default;
......@@ -29,19 +29,14 @@ public:
void OnDraw(BufferInfo& gfxDstBuffer, const Rect& invalidatedArea, uint8_t backgroundOpa) override;
protected:
void DrawForeground(BufferInfo& gfxDstBuffer, const Rect& invalidatedArea, uint8_t backgroundOpa);
void DrawBackground(BufferInfo& gfxDstBuffer, const Rect& invalidatedArea, uint8_t backgroundOpa);
protected:
static constexpr uint16_t START_ANGLE_IN_DEGREE = 60;
static constexpr uint16_t END_ANGLE_IN_DEGREE = 120;
static constexpr uint16_t SCROLL_BAR_WIDTH = 5;
int16_t radius_ = 0;
int16_t width_ = SCROLL_BAR_WIDTH;
uint16_t startAngle_ = START_ANGLE_IN_DEGREE;
uint16_t endAngle_ = END_ANGLE_IN_DEGREE;
Point center_ = {0, 0};
int16_t radius_;
int16_t width_;
uint16_t startAngle_;
uint16_t endAngle_;
Point center_;
};
} // namespace OHOS
#endif // GRAPHIC_LITE_UI_ARC_SCROLL_BAR_H
......@@ -18,6 +18,10 @@
#include "draw/draw_rect.h"
#include "engines/gfx/gfx_engine_manager.h"
namespace {
constexpr uint16_t SCROLL_BAR_MIN_LEN = 10;
} // namespace
namespace OHOS {
void UIBoxScrollBar::SetPosition(int16_t x, int16_t y, int16_t width, int16_t height)
{
......@@ -38,12 +42,18 @@ void UIBoxScrollBar::OnDraw(BufferInfo& gfxDstBuffer, const Rect& invalidatedAre
/* Draw foreground */
if (backgroundRect_.GetWidth() < backgroundRect_.GetHeight()) {
int16_t forgroundHeight = foregroundProportion_ * backgroundRect_.GetHeight();
if (forgroundHeight < SCROLL_BAR_MIN_LEN) {
forgroundHeight = SCROLL_BAR_MIN_LEN;
}
int16_t forgroundTop =
backgroundRect_.GetTop() + scrollProgress_ * (backgroundRect_.GetHeight() - forgroundHeight);
rect.SetRect(backgroundRect_.GetLeft(), forgroundTop, backgroundRect_.GetRight(),
forgroundTop + forgroundHeight - 1);
} else {
int16_t forgroundWidth = foregroundProportion_ * backgroundRect_.GetWidth();
if (forgroundWidth < SCROLL_BAR_MIN_LEN) {
forgroundWidth = SCROLL_BAR_MIN_LEN;
}
int16_t forgroundLeft =
backgroundRect_.GetLeft() + scrollProgress_ * (backgroundRect_.GetWidth() - forgroundWidth);
rect.SetRect(forgroundLeft, backgroundRect_.GetTop(), forgroundLeft + forgroundWidth - 1,
......
......@@ -77,6 +77,9 @@ void UIList::Recycle::InitRecycle()
FillActiveView();
listView_->Invalidate();
hasInitialiszed_ = true;
if (listView_->xScrollBarVisible_ || listView_->yScrollBarVisible_) {
MesureAdapterRelativeRect();
}
}
UIView* UIList::Recycle::GetView(int16_t index)
......@@ -158,7 +161,6 @@ UIList::UIList(uint8_t direction)
selectPosition_(0),
onSelectedIndex_(0),
recycle_(this),
hasMeasuredAdapterRect_(false),
scrollListener_(nullptr)
{
#if ENABLE_ROTATE_INPUT
......@@ -498,12 +500,6 @@ void UIList::SetAdapter(AbstractAdapter* adapter)
{
recycle_.SetAdapter(adapter);
recycle_.InitRecycle();
if (xScrollBarVisible_ || yScrollBarVisible_) {
recycle_.MesureAdapterRelativeRect();
hasMeasuredAdapterRect_ = true;
} else {
hasMeasuredAdapterRect_ = false;
}
}
UIView* UIList::GetSelectView()
......@@ -735,12 +731,6 @@ void UIList::ScrollTo(uint16_t index)
onSelectedView_ = nullptr;
SetStartIndex(index);
recycle_.InitRecycle();
if (xScrollBarVisible_ || yScrollBarVisible_) {
recycle_.MesureAdapterRelativeRect();
hasMeasuredAdapterRect_ = true;
} else {
hasMeasuredAdapterRect_ = false;
}
}
void UIList::RefreshList()
......@@ -772,12 +762,6 @@ void UIList::RefreshList()
startIndex_ = topIndex;
}
recycle_.InitRecycle();
if (xScrollBarVisible_ || yScrollBarVisible_) {
recycle_.MesureAdapterRelativeRect();
hasMeasuredAdapterRect_ = true;
} else {
hasMeasuredAdapterRect_ = false;
}
startIndex_ = tmpStartIndex;
if (direction_ == VERTICAL) {
......@@ -796,27 +780,27 @@ void UIList::RemoveAll()
void UIList::SetXScrollBarVisible(bool visible)
{
bool lastVisible = xScrollBarVisible_;
UIAbstractScroll::SetXScrollBarVisible(visible);
if (!recycle_.HasInitialiszed() || !xScrollBarVisible_) {
hasMeasuredAdapterRect_ = false;
return;
}
if (!hasMeasuredAdapterRect_) {
recycle_.MesureAdapterRelativeRect();
hasMeasuredAdapterRect_ = true;
if (!lastVisible && xScrollBarVisible_) {
if (recycle_.HasInitialiszed()) {
recycle_.MesureAdapterRelativeRect();
} else {
recycle_.InitRecycle();
}
}
}
void UIList::SetYScrollBarVisible(bool visible)
{
bool lastVisible = yScrollBarVisible_;
UIAbstractScroll::SetYScrollBarVisible(visible);
if (!recycle_.HasInitialiszed() || !yScrollBarVisible_) {
hasMeasuredAdapterRect_ = false;
return;
}
if (!hasMeasuredAdapterRect_) {
recycle_.MesureAdapterRelativeRect();
hasMeasuredAdapterRect_ = true;
if (!lastVisible && yScrollBarVisible_) {
if (recycle_.HasInitialiszed()) {
recycle_.MesureAdapterRelativeRect();
} else {
recycle_.InitRecycle();
}
}
}
......
......@@ -14,6 +14,7 @@
*/
#include "components/ui_scroll_view.h"
#include "components/ui_abstract_scroll_bar.h"
#include "dock/focus_manager.h"
#include "dock/vibrator_manager.h"
#include "draw/draw_rect.h"
......@@ -30,12 +31,8 @@ constexpr float DEFAULT_VIBRATOR_LEN = 1.0;
namespace OHOS {
UIScrollView::UIScrollView()
: xSliderPos_({0, 0}),
ySliderPos_({0, 0}),
scrollBarWidth_(DEFAULT_BAR_WIDTH),
xScrollable_(true),
: xScrollable_(true),
yScrollable_(true),
minScrollBarLen_(DEFAULT_MIN_BAR_LEN),
scrollListener_(nullptr)
{
#if ENABLE_ROTATE_INPUT
......@@ -50,10 +47,6 @@ UIScrollView::UIScrollView()
focusable_ = true;
#endif
direction_ = HORIZONTAL_AND_VERTICAL;
xSlider_.SetVisible(false);
ySlider_.SetVisible(false);
xSlider_.SetStyle(StyleDefault::GetBrightStyle());
ySlider_.SetStyle(StyleDefault::GetBrightStyle());
}
bool UIScrollView::OnDragEvent(const DragEvent& event)
......@@ -62,7 +55,6 @@ bool UIScrollView::OnDragEvent(const DragEvent& event)
UIAbstractScroll::StopAnimator();
}
Drag(event);
RefreshAnimator();
return UIView::OnDragEvent(event);
}
......@@ -141,7 +133,6 @@ bool UIScrollView::OnRotateEvent(const RotateEvent& event)
lastVibratorRotateLen_ = totalRotateLen_;
}
#endif
RefreshAnimator();
return UIView::OnRotateEvent(event);
}
......@@ -200,18 +191,10 @@ bool UIScrollView::DragXInner(int16_t distance)
} else {
int16_t childRight = childRect.GetRight();
int16_t scrollWidth = GetWidth();
if (yScrollable_ && ySlider_.IsVisible()) {
if (childRight < scrollWidth - ySlider_.GetWidth() - (scrollBlankSize_ + reboundSize)) {
distance = 0;
} else if (childRight + distance < scrollWidth - ySlider_.GetWidth() - (scrollBlankSize_ + reboundSize)) {
distance = scrollWidth - ySlider_.GetWidth() - (scrollBlankSize_ + reboundSize) - childRight;
}
} else {
if (childRight < scrollWidth - (scrollBlankSize_ + reboundSize)) {
distance = 0;
} else if (childRight + distance < scrollWidth - (scrollBlankSize_ + reboundSize)) {
distance = scrollWidth - (scrollBlankSize_ + reboundSize) - childRight - 1;
}
if (childRight < scrollWidth - (scrollBlankSize_ + reboundSize)) {
distance = 0;
} else if (childRight + distance < scrollWidth - (scrollBlankSize_ + reboundSize)) {
distance = scrollWidth - (scrollBlankSize_ + reboundSize) - childRight - 1;
}
}
......@@ -239,19 +222,10 @@ bool UIScrollView::DragYInner(int16_t distance)
} else {
int16_t childBottom = childRect.GetBottom();
int16_t scrollHeight = GetHeight();
if (xScrollable_ && xSlider_.IsVisible()) {
if (childBottom < scrollHeight - xSlider_.GetHeight() - (scrollBlankSize_ + reboundSize)) {
distance = 0;
} else if (childBottom + distance <
scrollHeight - xSlider_.GetHeight() - (scrollBlankSize_ + reboundSize)) {
distance = scrollHeight - xSlider_.GetHeight() - (scrollBlankSize_ + reboundSize) - childBottom;
}
} else {
if (childBottom < scrollHeight - (scrollBlankSize_ + reboundSize)) {
if (childBottom < scrollHeight - (scrollBlankSize_ + reboundSize)) {
distance = 0;
} else if (childBottom + distance < scrollHeight - (scrollBlankSize_ + reboundSize)) {
} else if (childBottom + distance < scrollHeight - (scrollBlankSize_ + reboundSize)) {
distance = scrollHeight - (scrollBlankSize_ + reboundSize) - childBottom - 1;
}
}
}
......@@ -267,8 +241,10 @@ bool UIScrollView::MoveOffset(int16_t offsetX, int16_t offsetY)
scrollListener_->SetScrollState(OnScrollListener::SCROLL_STATE_MOVE);
}
UIAbstractScroll::MoveChildByOffset(offsetX, offsetY);
if (xScrollBarVisible_ || yScrollBarVisible_) {
RefreshScrollBar();
}
Invalidate();
RefreshScrollBarPosition();
return true;
}
return false;
......@@ -276,148 +252,25 @@ bool UIScrollView::MoveOffset(int16_t offsetX, int16_t offsetY)
void UIScrollView::RefreshScrollBar()
{
Rect childRect = GetAllChildRelativeRect();
if (xScrollable_ && (childRect.GetWidth() <= GetWidth())) {
xSliderPos_.y = GetHeight() - scrollBarWidth_;
xSlider_.SetHeight(scrollBarWidth_);
// y scroll bar is on, x scroll bar width should be group width - scroll bar width
if (yScrollable_) {
xSlider_.SetWidth(GetWidth() - scrollBarWidth_);
} else {
xSlider_.SetWidth(GetWidth());
}
}
if (yScrollable_ && (childRect.GetHeight() <= GetHeight())) {
ySliderPos_.x = GetWidth() - scrollBarWidth_;
ySliderPos_.y = 0;
ySlider_.SetWidth(scrollBarWidth_);
// x scroll bar is on, y scroll bar height should be group height - scroll bar width
if (xScrollable_) {
ySlider_.SetHeight(GetHeight() - scrollBarWidth_);
} else {
ySlider_.SetHeight(GetHeight());
}
}
float multiple;
// child width is larger than group width, resize the x scroll bar width
if (xScrollable_ && (childRect.GetWidth() > GetWidth()) && (childRect.GetWidth() != 0)) {
int16_t groupWidth = GetWidth();
int16_t xWidth;
if (yScrollable_) {
multiple = static_cast<float>(groupWidth - scrollBarWidth_) / childRect.GetWidth();
xWidth = static_cast<int16_t>((groupWidth - scrollBarWidth_) * multiple);
} else {
multiple = static_cast<float>(groupWidth) / childRect.GetWidth();
xWidth = static_cast<int16_t>(groupWidth * multiple);
}
if (xWidth < minScrollBarLen_) {
xWidth = minScrollBarLen_;
}
xSliderPos_.x = GetXScrollOffset(childRect);
xSliderPos_.y = GetHeight() - scrollBarWidth_;
xSlider_.SetWidth(xWidth);
xSlider_.SetHeight(scrollBarWidth_);
Rect childrenRect = GetAllChildRelativeRect();
/* calculate scrollBar's the proportion of foreground */
int16_t totalLen = childrenRect.GetHeight() + 2 * scrollBlankSize_; // 2: two blank space on both sizes
int16_t len = GetHeight();
if (yScrollBarVisible_) {
yScrollBar_->SetForegroundProportion(static_cast<float>(len) / totalLen);
/* calculate scrolling progress */
yScrollBar_->SetScrollProgress(static_cast<float>(scrollBlankSize_ - childrenRect.GetTop()) /
(totalLen - len));
}
if (xScrollBarVisible_) {
/* so do x-bar */
totalLen = childrenRect.GetWidth() + 2 * scrollBlankSize_; // 2: two blank space on both sizes
len = GetWidth();
xScrollBar_->SetForegroundProportion(static_cast<float>(len) / totalLen);
xScrollBar_->SetScrollProgress(static_cast<float>(scrollBlankSize_ - childrenRect.GetLeft()) /
(totalLen - len));
}
// child height is larger than group height, resize the y scroll height
if (yScrollable_ && (childRect.GetHeight() > GetHeight()) && (childRect.GetHeight() != 0)) {
int16_t groupHeight = GetHeight();
int16_t yHeight;
if (xScrollable_) {
multiple = static_cast<float>(groupHeight - scrollBarWidth_) / childRect.GetHeight();
yHeight = static_cast<int16_t>((groupHeight - scrollBarWidth_) * multiple);
} else {
multiple = static_cast<float>(groupHeight) / childRect.GetHeight();
yHeight = static_cast<int16_t>(groupHeight * multiple);
}
// scroll bar may be too small, keep it min size
if (yHeight < minScrollBarLen_) {
yHeight = minScrollBarLen_;
}
ySliderPos_.x = GetWidth() - scrollBarWidth_;
ySliderPos_.y = GetYScrollOffset(childRect);
ySlider_.SetHeight(yHeight);
ySlider_.SetWidth(scrollBarWidth_);
}
}
void UIScrollView::RefreshScrollBarPosition()
{
if (!xSlider_.IsVisible() && !ySlider_.IsVisible()) {
return;
}
Rect childRect = GetAllChildRelativeRect();
if ((childRect.GetWidth() == 0) || (childRect.GetHeight() == 0)) {
return;
}
if (xScrollable_) {
int16_t xOffset = GetXScrollOffset(childRect);
xSliderPos_.x = xOffset;
Invalidate();
}
if (yScrollable_) {
int16_t yOffset = GetYScrollOffset(childRect);
ySliderPos_.y = yOffset;
Invalidate();
}
}
int16_t UIScrollView::GetXScrollOffset(const Rect& childRect)
{
Rect scrollRect = GetRelativeRect();
int16_t xOffset;
int16_t scrollBarOffset = 0;
if (yScrollable_) {
scrollBarOffset = scrollBarWidth_;
}
int16_t childRectLeft = childRect.GetLeft();
int16_t childRectWidth = childRect.GetWidth();
int16_t scrollRectWidth = scrollRect.GetWidth();
int16_t xSliderWidth = xSlider_.GetWidth();
if ((childRectLeft >= 0) || (childRectWidth - scrollRectWidth + scrollBarOffset == 0)) {
xOffset = 0;
} else {
float multiple = static_cast<float>(scrollRectWidth - scrollBarOffset - xSliderWidth) /
(childRectWidth - scrollRectWidth + scrollBarOffset);
xOffset = static_cast<int16_t>(-childRectLeft * multiple);
}
return xOffset;
}
int16_t UIScrollView::GetYScrollOffset(const Rect& childRect)
{
Rect scrollRect = GetRelativeRect();
int16_t yOffset;
int16_t scrollBarOffset = 0;
if (xScrollable_) {
scrollBarOffset = scrollBarWidth_;
}
int16_t childRectTop = childRect.GetTop();
int16_t childRectHeight = childRect.GetHeight();
int16_t scrollRectHeight = scrollRect.GetHeight();
int16_t ySliderHeight = ySlider_.GetHeight();
if ((childRectTop >= 0) || (childRectHeight - scrollRectHeight + scrollBarOffset == 0)) {
yOffset = 0;
} else {
float multiple = static_cast<float>(scrollRectHeight - scrollBarOffset - ySliderHeight) /
(childRectHeight - scrollRectHeight + scrollBarOffset);
yOffset = static_cast<int16_t>(-childRectTop * multiple);
}
return yOffset;
}
void UIScrollView::OnChildChanged()
{
RefreshScrollBar();
RefreshAnimator();
}
void UIScrollView::CalculateReboundDistance(int16_t& dragDistanceX, int16_t& dragDistanceY)
......
......@@ -138,6 +138,16 @@ public:
return height_;
}
virtual void SetScreenShape(ScreenShape screenShape)
{
screenShape_ = screenShape;
}
virtual ScreenShape GetScreenShape()
{
return screenShape_;
}
static BaseGfxEngine* GetInstance()
{
return baseEngine_;
......@@ -156,6 +166,7 @@ protected:
static BaseGfxEngine* baseEngine_;
uint16_t width_ = HORIZONTAL_RESOLUTION;
uint16_t height_ = VERTICAL_RESOLUTION;
ScreenShape screenShape_ = RECTANGLE;
};
}
......
......@@ -39,14 +39,6 @@
#include "gfx_utils/image_info.h"
namespace OHOS {
/**
* @brief Enumerates screen shapes.
*/
enum ScreenShape {
RECTANGLE = 0, // rectangular screen
CIRCLE // circular screen
};
/**
* @brief Represents the screen info of the device.
*
......
......@@ -38,7 +38,6 @@
#include "animator/animator.h"
#include "animator/easing_equation.h"
#include "common/screen.h"
#include "components/ui_view_group.h"
namespace OHOS {
......@@ -267,19 +266,9 @@ public:
}
#endif
void SetXScrollBarVisible(bool visible)
{
if (Screen::GetInstance().GetScreenShape() == ScreenShape::CIRCLE) {
xScrollBarVisible_ = false;
return;
}
xScrollBarVisible_ = visible;
}
void SetXScrollBarVisible(bool visible);
void SetYScrollBarVisible(bool visible)
{
yScrollBarVisible_ = visible;
}
void SetYScrollBarVisible(bool visible);
void OnPostDraw(BufferInfo& gfxDstBuffer, const Rect& invalidatedArea) override;
......@@ -299,7 +288,7 @@ protected:
/* the maximum number of historical drag data */
static constexpr uint8_t MAX_DELTA_Y_SIZE = 3;
static constexpr uint16_t SCROLL_BAR_WIDTH = 5;
static constexpr uint16_t SCROLL_BAR_WIDTH = 4;
static constexpr uint8_t MAX_ROTATE_FACTOR = 128;
class ListAnimatorCallback : public AnimatorCallback {
......
......@@ -410,6 +410,7 @@ protected:
private:
friend class UIPicker;
friend class Recycle;
class Recycle : public HeapBase {
public:
explicit Recycle(UIList* list) : adapter_(nullptr), listView_(list), hasInitialiszed_(false) {}
......@@ -418,9 +419,15 @@ private:
UIView* GetView(int16_t index);
void SetAdapter(AbstractAdapter* adapter)
{
hasInitialiszed_ = false;
adapter_ = adapter;
}
bool HasInitialiszed()
{
return hasInitialiszed_;
}
void AddScrapView(UIView* view)
{
scrapView_.PushBack(view);
......@@ -436,11 +443,6 @@ private:
scrapView_.Clear();
}
bool HasInitialiszed()
{
return hasInitialiszed_;
}
Rect GetAdapterItemsReletiveRect();
void MoveAdapterItemsRelativeRect(int16_t x, int16_t y);
void MesureAdapterRelativeRect();
......@@ -486,7 +488,6 @@ private:
uint16_t selectPosition_;
int16_t onSelectedIndex_;
Recycle recycle_;
bool hasMeasuredAdapterRect_;
ListScrollListener* scrollListener_;
void CalculateReboundDistance(int16_t& dragDistanceX, int16_t& dragDistanceY) override;
};
......
......@@ -166,19 +166,6 @@ public:
*/
void ScrollBy(int16_t xDistance, int16_t yDistance);
/**
* @brief Sets the width for this scroll bar.
*
* @param width Indicates the width to set. The default value is {@link DEFAULT_BAR_WIDTH}.
* @since 1.0
* @version 1.0
*/
void SetScrollbarWidth(uint8_t width)
{
scrollBarWidth_ = width;
minScrollBarLen_ = scrollBarWidth_ * MIN_BAR_MULTIPLE;
}
/**
* @brief Sets whether a horizontal scroll is enabled.
*
......@@ -241,8 +228,6 @@ public:
scrollListener_ = scrollListener;
}
void RefreshScrollBar();
protected:
void StopAnimator() override;
bool DragXInner(int16_t distance) override;
......@@ -250,23 +235,11 @@ protected:
private:
void Drag(const DragEvent& event);
void RefreshScrollBarPosition();
bool MoveOffset(int16_t offsetX, int16_t offsetY);
int16_t GetXScrollOffset(const Rect& childRect);
int16_t GetYScrollOffset(const Rect& childRect);
void OnChildChanged() override;
void CalculateReboundDistance(int16_t& dragDistanceX, int16_t& dragDistanceY) override;
static constexpr uint8_t DEFAULT_BAR_WIDTH = 5;
static constexpr uint8_t MIN_BAR_MULTIPLE = 2;
static constexpr uint8_t DEFAULT_MIN_BAR_LEN = DEFAULT_BAR_WIDTH * MIN_BAR_MULTIPLE;
UIView xSlider_;
UIView ySlider_;
Point xSliderPos_;
Point ySliderPos_;
int16_t scrollBarWidth_;
void RefreshScrollBar();
bool xScrollable_;
bool yScrollable_;
int16_t minScrollBarLen_;
OnScrollListener* scrollListener_;
#if ENABLE_ROTATE_INPUT
int16_t lastRotateLen_;
......
......@@ -318,6 +318,10 @@ public:
*/
static constexpr uint8_t VERTICAL = 1;
void SetXScrollBarVisible(bool visible) = delete;
void SetYScrollBarVisible(bool visible) = delete;
protected:
bool DragXInner(int16_t distance) override;
bool DragYInner(int16_t distance) override;
......
......@@ -45,6 +45,7 @@ test_sources = [
"../uitest/test_render/ui_test_render.cpp",
"../uitest/test_rotate_input/ui_test_rotate_input.cpp",
"../uitest/test_screenshot/ui_test_screenshot.cpp",
"../uitest/test_scroll_bar/ui_test_scroll_bar.cpp",
"../uitest/test_slider/ui_test_slider.cpp",
"../uitest/test_texture_mapper/ui_test_texture_mapper.cpp",
"../uitest/test_transform/ui_test_transform.cpp",
......
......@@ -66,5 +66,6 @@ namespace OHOS {
#define VIDEO_SOURCE_DIRECTORY (IMAGE_DIR "video.mp4")
#define TEST_RIGHT_ARROW (IMAGE_DIR "ic_arrow_right.png")
#define TEST_BACK_LEFT_ARROW (IMAGE_DIR "ic_back.png")
#define TEST_CIRCLE_FORE_IMAGE (FACE_DIR "fore.png")
} // namespace OHOS
#endif // TEST_RESOURCE_CONFIG_H
......@@ -53,6 +53,7 @@
#include "test_screenshot/ui_test_screenshot.h"
#endif
#include "test_digital_clock/ui_test_digital_clock.h"
#include "test_scroll_bar/ui_test_scroll_bar.h"
#include "test_slider/ui_test_slider.h"
#include "test_texture_mapper/ui_test_texture_mapper.h"
#include "test_transform/ui_test_transform.h"
......@@ -145,6 +146,7 @@ void UITestGroup::SetUpTestCase()
testCaseList_.PushBack(TestCaseInfo{"FocusManager", new UITestFocusManager()});
#endif
testCaseList_.PushBack(TestCaseInfo{"Border_Margin_Padding", new UITestBorderMarginPadding()});
testCaseList_.PushBack(TestCaseInfo{"ScrollBar", new UITestScrollBar()});
}
List<TestCaseInfo>& UITestGroup::GetTestCase()
......
......@@ -16,9 +16,9 @@
#include "graphic_config.h"
#if ENABLE_DEBUG
#include "common/screen.h"
#include "components/root_view.h"
#include "dfx/event_injector.h"
#include "engines/gfx/gfx_engine_manager.h"
#include "ui_test_event_injector.h"
#include <string>
#if ENABLE_WINDOW
......
......@@ -14,12 +14,12 @@
*/
#include "ui_test_rotate_input.h"
#include "common/screen.h"
#include "components/ui_label.h"
#include "components/ui_label_button.h"
#include "cstdio"
#include "dock/focus_manager.h"
#include "dock/vibrator_manager.h"
#include "engines/gfx/gfx_engine_manager.h"
#if ENABLE_ROTATE_INPUT
namespace OHOS {
......
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "ui_test_scroll_bar.h"
#include "components/ui_label_button.h"
#include "engines/gfx/gfx_engine_manager.h"
#include "test_resource_config.h"
namespace {
constexpr int16_t LABEL_WIDTH = 150;
constexpr int16_t LABEL_HEIGHT = 74;
constexpr int16_t LABEL_INTERVAL = 50;
constexpr int16_t LABEL_LEFT_INTERVAL = 125;
constexpr int16_t VIEW_WIDTH = 400;
constexpr int16_t VIEW_HEIGHT = 400;
}
namespace OHOS {
void UITestScrollBar::SetUp()
{
BaseGfxEngine::GetInstance()->SetScreenShape(ScreenShape::CIRCLE);
if (container_ == nullptr) {
container_ = new UIViewGroup();
}
if (scrollView_ == nullptr) {
scrollView_ = new UIScrollView();
}
if (list_ == nullptr) {
list_ = new UIList();
}
if (foreImg1_ == nullptr) {
foreImg1_ = new UIImageView();
}
if (foreImg2_ == nullptr) {
foreImg2_ = new UIImageView();
}
if (adapter_ == nullptr) {
adapter_ = new TextAdapter();
}
if (adapterData_ == nullptr) {
adapterData_ = new List<const char*>();
adapterData_->PushBack("abcd0");
adapterData_->PushBack("abcd1");
adapterData_->PushBack("abcd2");
adapterData_->PushBack("abcd3");
adapterData_->PushBack("abcd4");
adapterData_->PushBack("abcd5");
adapterData_->PushBack("abcd6");
adapterData_->PushBack("abcd7");
adapterData_->PushBack("abcd8");
adapterData_->PushBack("abcd9");
adapterData_->PushBack("abcd10");
adapterData_->PushBack("abcd11");
adapterData_->PushBack("abcd12");
adapterData_->PushBack("abcd13");
adapterData_->PushBack("abcd14");
adapterData_->PushBack("abcd15");
}
container_->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight());
container_->Add(scrollView_);
scrollView_->SetPosition(0, 0, VIEW_WIDTH, VIEW_HEIGHT);
scrollView_->SetYScrollBarVisible(true);
scrollView_->SetHorizontalScrollState(false);
scrollView_->SetReboundSize(50); // 50: rebound size
container_->Add(list_);
list_->SetPosition(450, 0, VIEW_WIDTH, VIEW_HEIGHT); // 450: x
list_->SetYScrollBarVisible(true);
list_->SetReboundSize(50); // 50: rebound size
}
void UITestScrollBar::TearDown()
{
DeleteChildren(container_);
container_ = nullptr;
scrollView_ = nullptr;
list_ = nullptr;
foreImg1_ = nullptr;
foreImg2_ = nullptr;
if (adapterData_ != nullptr) {
adapterData_->Clear();
delete adapterData_;
adapterData_ = nullptr;
}
if (adapter_ != nullptr) {
delete adapter_;
adapter_ = nullptr;
}
BaseGfxEngine::GetInstance()->SetScreenShape(ScreenShape::RECTANGLE);
}
const UIView* UITestScrollBar::GetTestView()
{
UIKit_ScrollBar_TEST_Scroll_view_001();
UIKit_ScrollBar_TEST_List_001();
return container_;
}
void UITestScrollBar::UIKit_ScrollBar_TEST_Scroll_view_001()
{
UILabelButton* label1 = new UILabelButton();
scrollView_->Add(label1);
label1->LayoutTopOfParent(LABEL_INTERVAL);
label1->LayoutLeftOfParent(LABEL_LEFT_INTERVAL);
label1->SetWidth(LABEL_WIDTH);
label1->SetHeight(LABEL_HEIGHT);
label1->SetViewId("label1");
label1->SetText("label1");
UILabelButton* label2 = new UILabelButton();
scrollView_->Add(label2);
label2->LayoutBottomToSibling("label1", LABEL_INTERVAL);
label2->LayoutLeftOfParent(LABEL_LEFT_INTERVAL);
label2->SetWidth(LABEL_WIDTH);
label2->SetHeight(LABEL_HEIGHT);
label2->SetViewId("label2");
label2->SetText("label2");
UILabelButton* label3 = new UILabelButton();
scrollView_->Add(label3);
label3->LayoutBottomToSibling("label2", LABEL_INTERVAL);
label3->LayoutLeftOfParent(LABEL_LEFT_INTERVAL);
label3->SetWidth(LABEL_WIDTH);
label3->SetHeight(LABEL_HEIGHT);
label3->SetViewId("label3");
label3->SetText("label3");
UILabelButton* label4 = new UILabelButton();
scrollView_->Add(label4);
label4->LayoutBottomToSibling("label3", LABEL_INTERVAL);
label4->LayoutLeftOfParent(LABEL_LEFT_INTERVAL);
label4->SetWidth(LABEL_WIDTH);
label4->SetHeight(LABEL_HEIGHT);
label4->SetViewId("label4");
label4->SetText("label4");
UILabelButton* label5 = new UILabelButton();
scrollView_->Add(label5);
label5->LayoutBottomToSibling("label4", LABEL_INTERVAL);
label5->LayoutLeftOfParent(LABEL_LEFT_INTERVAL);
label5->SetWidth(LABEL_WIDTH);
label5->SetHeight(LABEL_HEIGHT);
label5->SetViewId("label5");
label5->SetText("label5");
foreImg1_->SetSrc(TEST_CIRCLE_FORE_IMAGE);
container_->Add(foreImg1_);
foreImg1_->SetPosition(0, 0);
}
void UITestScrollBar::UIKit_ScrollBar_TEST_List_001()
{
adapter_->SetLineBreakMode(UILabel::LINE_BREAK_CLIP);
adapter_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE);
adapter_->SetHeight(LABEL_HEIGHT);
adapter_->SetWidth(VIEW_WIDTH);
adapter_->SetData(adapterData_);
list_->SetAdapter(adapter_);
list_->SetIntercept(true);
list_->SetYScrollBarVisible(true);
foreImg2_->SetSrc(TEST_CIRCLE_FORE_IMAGE);
container_->Add(foreImg2_);
foreImg2_->SetPosition(450, 0); // 450: x
}
} // namespace OHOS
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef UI_TEST_SCROLL_BAR_H
#define UI_TEST_SCROLL_BAR_H
#include "components/text_adapter.h"
#include "components/ui_image_view.h"
#include "components/ui_list.h"
#include "components/ui_scroll_view.h"
#include "ui_test.h"
namespace OHOS {
class UITestScrollBar : public UITest {
public:
UITestScrollBar() {}
~UITestScrollBar() {}
void SetUp() override;
void TearDown() override;
const UIView* GetTestView() override;
void UIKit_ScrollBar_TEST_Scroll_view_001();
void UIKit_ScrollBar_TEST_List_001();
private:
UIViewGroup* container_ = nullptr;
UIScrollView* scrollView_ = nullptr;
UIList* list_ = nullptr;
UIImageView* foreImg1_ = nullptr;
UIImageView* foreImg2_ = nullptr;
List<const char*>* adapterData_ = nullptr;
TextAdapter* adapter_ = nullptr;
}; // namespace OHOS
}
#endif // UI_TEST_SCROLL_BAR_H
......@@ -201,7 +201,6 @@ void UITestUIScrollView::UIKit_UIScrollView_Test_bar_004()
scroll->SetPosition(positionX_, positionY_, g_scrollW, g_scrollH);
VISIBLE_XBAR(true);
scroll->SetYScrollBarVisible(true);
scroll->SetScrollbarWidth(20); // 20: means scroll bar width
container_->Add(scroll);
UIButton* button1 = new UIButton();
button1->SetPosition(0, 0, g_smallButtonW, g_smallButtonH);
......@@ -330,4 +329,4 @@ void UITestUIScrollView::SetLastPos(UIView* view)
lastX_ = view->GetX();
lastY_ = view->GetY() + view->GetHeight();
}
} // namespace OHOS
\ No newline at end of file
} // namespace OHOS
......@@ -118,29 +118,27 @@ HWTEST_F(ScrollBarTest, UIScrollBarSetPosition, TestSize.Level0)
EXPECT_NE(boxBar.GetWidth(), ZERO_LEN);
}
HWTEST_F(ScrollBarTest, UIScrollBarSetBarStyle, TestSize.Level0)
HWTEST_F(ScrollBarTest, UIScrollBarGetBarStyle, TestSize.Level0)
{
Style& defaultBackStyle = StyleDefault::GetProgressBackgroundStyle();
Style& defaultForeStyle = StyleDefault::GetProgressForegroundStyle();
Style testStyle;
Style& defaultBackStyle = StyleDefault::GetScrollBarBackgroundStyle();
Style& defaultForeStyle = StyleDefault::GetScrollBarForegroundStyle();
TestArcScrollBarTest arcBar;
TestBoxScrollBarTest boxBar;
EXPECT_EQ(arcBar.GetBackStyle()->GetStyle(STYLE_LINE_COLOR), defaultBackStyle.GetStyle(STYLE_LINE_COLOR));
EXPECT_EQ(arcBar.GetForeStyle()->GetStyle(STYLE_LINE_COLOR), defaultForeStyle.GetStyle(STYLE_LINE_COLOR));
arcBar.SetBackgroundStyle(testStyle);
EXPECT_EQ(arcBar.GetBackStyle()->GetStyle(STYLE_LINE_COLOR), testStyle.GetStyle(STYLE_LINE_COLOR));
arcBar.SetForegroundStyle(testStyle);
EXPECT_EQ(arcBar.GetForeStyle()->GetStyle(STYLE_LINE_COLOR), defaultForeStyle.GetStyle(STYLE_LINE_COLOR));
EXPECT_EQ(arcBar.GetBackStyle()->GetStyle(STYLE_LINE_OPA), defaultBackStyle.GetStyle(STYLE_LINE_OPA));
EXPECT_EQ(arcBar.GetForeStyle()->GetStyle(STYLE_LINE_OPA), defaultForeStyle.GetStyle(STYLE_LINE_OPA));
TestBoxScrollBarTest boxBar;
EXPECT_EQ(boxBar.GetBackStyle()->GetStyle(STYLE_LINE_COLOR), defaultBackStyle.GetStyle(STYLE_LINE_COLOR));
EXPECT_EQ(boxBar.GetForeStyle()->GetStyle(STYLE_LINE_COLOR), defaultForeStyle.GetStyle(STYLE_LINE_COLOR));
EXPECT_EQ(boxBar.GetBackStyle()->GetStyle(STYLE_BACKGROUND_COLOR),
defaultBackStyle.GetStyle(STYLE_BACKGROUND_COLOR));
EXPECT_EQ(boxBar.GetForeStyle()->GetStyle(STYLE_BACKGROUND_COLOR),
defaultForeStyle.GetStyle(STYLE_BACKGROUND_COLOR));
boxBar.SetBackgroundStyle(testStyle);
EXPECT_EQ(boxBar.GetBackStyle()->GetStyle(STYLE_LINE_COLOR), testStyle.GetStyle(STYLE_LINE_COLOR));
boxBar.SetForegroundStyle(testStyle);
EXPECT_EQ(boxBar.GetForeStyle()->GetStyle(STYLE_LINE_COLOR), defaultForeStyle.GetStyle(STYLE_LINE_COLOR));
EXPECT_EQ(boxBar.GetBackStyle()->GetStyle(STYLE_BACKGROUND_OPA), defaultBackStyle.GetStyle(STYLE_BACKGROUND_OPA));
EXPECT_EQ(boxBar.GetForeStyle()->GetStyle(STYLE_BACKGROUND_OPA), defaultForeStyle.GetStyle(STYLE_BACKGROUND_OPA));
}
HWTEST_F(ScrollBarTest, UIScrollBarSetForegroundProportion, TestSize.Level0)
......
......@@ -19,10 +19,6 @@
using namespace testing::ext;
namespace OHOS {
namespace {
constexpr uint8_t DEFAULT_BAR_WIDTH = 5;
}
class ScrollViewTest : public testing::Test {
public:
static void SetUpTestCase();
......
......@@ -56,6 +56,7 @@ SOURCES += \
../../../../test/uitest/test_qrcode/ui_test_qrcode.cpp \
../../../../test/uitest/test_render/ui_test_render.cpp \
../../../../test/uitest/test_rotate_input/ui_test_rotate_input.cpp \
../../../../test/uitest/test_scroll_bar/ui_test_scroll_bar.cpp \
../../../../test/uitest/test_slider/ui_test_slider.cpp \
../../../../test/uitest/test_texture_mapper/ui_test_texture_mapper.cpp \
../../../../test/uitest/test_transform/ui_test_transform.cpp \
......@@ -112,6 +113,7 @@ HEADERS += \
../../../../test/uitest/test_qrcode/ui_test_qrcode.cpp \
../../../../test/uitest/test_render/ui_test_render.h \
../../../../test/uitest/test_rotate_input/ui_test_rotate_input.h \
../../../../test/uitest/test_scroll_bar/ui_test_scroll_bar.h \
../../../../test/uitest/test_slider/ui_test_slider.h \
../../../../test/uitest/test_texture_mapper/ui_test_texture_mapper.h \
../../../../test/uitest/test_transform/ui_test_transform.h \
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册