提交 95865723 编写于 作者: G guyuanzhang

Description:fix components support margin padding

Sig:graphic
Feature or Bugfix:Feature
Binary Source:No
上级 3cb0bfae
......@@ -124,12 +124,8 @@ void UIArcLabel::OnDraw(const Rect& invalidatedArea)
}
Rect trunc = invalidatedArea;
OpacityType opa = GetMixOpaScale();
DrawRect::Draw(GetRect(), trunc, *style_, opa);
Rect coords = GetContentRect();
if (trunc.Intersect(trunc, coords)) {
DrawArcText(trunc, opa);
}
UIView::OnDraw(invalidatedArea);
DrawArcText(trunc, opa);
}
void UIArcLabel::DrawArcText(const Rect& mask, OpacityType opaScale)
......@@ -139,8 +135,8 @@ void UIArcLabel::DrawArcText(const Rect& mask, OpacityType opaScale)
center.y = arcTextInfo_.arcCenter.y + GetRect().GetY();
InitArcLabelText();
UIFont::GetInstance()->SetCurrentFontId(arcLabelText_->GetFontId(), arcLabelText_->GetFontSize());
DrawLabel::DrawArcText(mask, arcLabelText_->GetText(), center, arcLabelText_->GetFontId(),
arcTextInfo_, orientation_, *style_, opaScale);
DrawLabel::DrawArcText(mask, arcLabelText_->GetText(), center, arcLabelText_->GetFontId(), arcTextInfo_,
orientation_, *style_, opaScale);
}
void UIArcLabel::RefreshArcLabel()
......@@ -161,18 +157,15 @@ void UIArcLabel::ReMeasure()
UIFont::GetInstance()->SetCurrentFontId(arcLabelText_->GetFontId(), arcLabelText_->GetFontSize());
MeasureArcTextInfo();
Rect textRect = TypedText::GetArcTextRect(arcLabelText_->GetText(),
arcCenter_,
style_->letterSpace_,
orientation_,
Rect textRect = TypedText::GetArcTextRect(arcLabelText_->GetText(), arcCenter_, style_->letterSpace_, orientation_,
arcTextInfo_);
int16_t arcTextWidth = textRect.GetWidth();
int16_t arcTextHeight = textRect.GetHeight();
SetPosition(textRect.GetX(), textRect.GetY());
Resize(arcTextWidth, arcTextHeight);
arcTextInfo_.arcCenter.x = arcCenter_.x - GetX();
arcTextInfo_.arcCenter.y = arcCenter_.y - GetY();
arcTextInfo_.arcCenter.x = arcCenter_.x - GetX() + style_->borderWidth_ + style_->paddingLeft_;
arcTextInfo_.arcCenter.y = arcCenter_.y - GetY() + style_->borderWidth_ + style_->paddingTop_;
textSize_.x = arcTextWidth;
textSize_.y = arcTextHeight;
Invalidate();
......
......@@ -25,8 +25,11 @@ UIBoxProgress::UIBoxProgress()
SetDirection(Direction::DIR_LEFT_TO_RIGHT);
}
void UIBoxProgress::DrawValidRect(const Image* image, const Rect& rect, const Rect& invalidatedArea,
const Style& style, uint16_t radius)
void UIBoxProgress::DrawValidRect(const Image* image,
const Rect& rect,
const Rect& invalidatedArea,
const Style& style,
uint16_t radius)
{
Rect cordsTmp;
if ((image != nullptr) && (image->GetSrcType() != IMG_SRC_UNKNOWN)) {
......@@ -65,8 +68,12 @@ void UIBoxProgress::DrawValidRect(const Image* image, const Rect& rect, const Re
}
}
void UIBoxProgress::DrawRoundCap(const Image* image, const Point& imgPos, const Rect& rect,
const Rect& invalidatedArea, uint16_t radius, const Style& style)
void UIBoxProgress::DrawRoundCap(const Image* image,
const Point& imgPos,
const Rect& rect,
const Rect& invalidatedArea,
uint16_t radius,
const Style& style)
{
Point leftTop;
Point leftBottom;
......@@ -134,8 +141,11 @@ void UIBoxProgress::DrawRoundCap(const Image* image, const Point& imgPos, const
DrawArc::GetInstance()->Draw(arcInfo, invalidatedArea, capStyle, opaScale_, CapType::CAP_NONE);
}
void UIBoxProgress::GetBackgroundParam(Point& startPoint, int16_t& width, int16_t& height, uint16_t& radius,
const Style& style)
void UIBoxProgress::GetBackgroundParam(Point& startPoint,
int16_t& width,
int16_t& height,
uint16_t& radius,
const Style& style)
{
Rect rect = GetOrigRect();
// 2: Half of the gap
......@@ -223,17 +233,14 @@ void UIBoxProgress::DrawForeground(const Rect& invalidatedArea, Rect& coords)
void UIBoxProgress::OnDraw(const Rect& invalidatedArea)
{
DrawRect::Draw(GetOrigRect(), invalidatedArea, *style_, opaScale_);
Rect trunc(invalidatedArea);
if (trunc.Intersect(trunc, GetOrigRect())) {
if (enableBackground_) {
DrawBackground(trunc);
}
UIView::OnDraw(invalidatedArea);
if (enableBackground_) {
DrawBackground(invalidatedArea);
}
if ((lastValue_ - rangeMin_ != 0) || (foregroundStyle_->lineCap_ == CapType::CAP_ROUND)) {
Rect coords;
DrawForeground(trunc, coords);
}
if ((lastValue_ - rangeMin_ != 0) || (foregroundStyle_->lineCap_ == CapType::CAP_ROUND)) {
Rect coords;
DrawForeground(invalidatedArea, coords);
}
}
} // namespace OHOS
\ No newline at end of file
......@@ -108,6 +108,7 @@ void UIButton::SetupThemeStyles()
buttonStyles_[PRESSED] = &(theme->GetButtonStyle().pressed);
buttonStyles_[INACTIVE] = &(theme->GetButtonStyle().inactive);
}
style_ = buttonStyles_[RELEASED];
}
int64_t UIButton::GetStyle(uint8_t key) const
......@@ -143,6 +144,7 @@ void UIButton::SetStyleForState(uint8_t key, int64_t value, ButtonState state)
}
buttonStyleAllocFlag_ = true;
}
style_ = buttonStyles_[RELEASED];
int16_t width = GetWidth();
int16_t height = GetHeight();
buttonStyles_[state]->SetStyle(key, value);
......
......@@ -40,7 +40,7 @@ void UIChart::SetHeight(int16_t height)
needRefresh_ = true;
}
UIViewGroup::SetHeight(height);
UIView::SetHeight(height);
xAxis_.SetHeight(height);
xAxis_.UpdateAxis();
yAxis_.SetHeight(height);
......@@ -49,7 +49,7 @@ void UIChart::SetHeight(int16_t height)
void UIChart::SetWidth(int16_t width)
{
UIViewGroup::SetWidth(width);
UIView::SetWidth(width);
xAxis_.SetWidth(width);
yAxis_.SetWidth(width);
xAxis_.UpdateAxis();
......@@ -59,10 +59,7 @@ void UIChart::SetWidth(int16_t width)
void UIChart::OnDraw(const Rect& invalidatedArea)
{
UIViewGroup::OnDraw(invalidatedArea);
Rect rect = GetContentRect();
if (rect.Intersect(rect, invalidatedArea)) {
DrawDataSerials(rect);
}
DrawDataSerials(invalidatedArea);
}
bool UIChart::AddDataSerial(UIChartDataSerial* dataSerial)
......
......@@ -369,13 +369,13 @@ bool UIList::ReCalculateDragEnd()
}
bool UIList::MoveChildStepInner(int16_t distance,
int16_t (UIView::*pfnGetXOrY)() const,
int16_t (Rect::*pfnGetWidthOrHeight)() const)
int16_t (UIView::*getXOrY)() const,
int16_t (UIView::*getWidthOrHeight)())
{
bool popRet = false;
bool pushRet = false;
if (distance > 0) {
if ((childrenHead_ == nullptr) || ((childrenHead_->*pfnGetXOrY)() + distance > 0)) {
if ((childrenHead_ == nullptr) || ((childrenHead_->*getXOrY)() + distance > 0)) {
uint16_t index = GetIndexDec(topIndex_);
if (index == topIndex_) {
return false;
......@@ -387,15 +387,14 @@ bool UIList::MoveChildStepInner(int16_t distance,
PushFront(newView);
pushRet = true;
}
if (childrenTail_ != nullptr &&
((childrenTail_->*pfnGetXOrY)() + distance > (this->GetRelativeRect().*pfnGetWidthOrHeight)())) {
if (childrenTail_ != nullptr && ((childrenTail_->*getXOrY)() + distance > (this->*getWidthOrHeight)())) {
PopItem(childrenTail_);
popRet = true;
}
} else {
if ((childrenTail_ == nullptr) ||
((childrenTail_->*pfnGetXOrY)() + (childrenTail_->GetRelativeRect().*pfnGetWidthOrHeight)() + distance <
(this->GetRelativeRect().*pfnGetWidthOrHeight)())) {
((childrenTail_->*getXOrY)() + (childrenTail_->*getWidthOrHeight)() + distance <
(this->*getWidthOrHeight)())) {
UIView* newView = recycle_.GetView(GetIndexInc(bottomIndex_));
if (newView == nullptr) {
return false;
......@@ -403,8 +402,7 @@ bool UIList::MoveChildStepInner(int16_t distance,
PushBack(newView);
pushRet = true;
}
if (childrenHead_ &&
(childrenHead_->*pfnGetXOrY)() + distance + (childrenHead_->GetRelativeRect().*pfnGetWidthOrHeight)() < 0) {
if (childrenHead_ && (childrenHead_->*getXOrY)() + distance + (childrenHead_->*getWidthOrHeight)() < 0) {
PopItem(childrenHead_);
popRet = true;
}
......@@ -415,9 +413,9 @@ bool UIList::MoveChildStepInner(int16_t distance,
bool UIList::MoveChildStep(int16_t distance)
{
if (direction_ == VERTICAL) {
return MoveChildStepInner(distance, &UIView::GetY, &Rect::GetHeight);
return MoveChildStepInner(distance, &UIView::GetY, &UIView::GetHeightWithMargin);
} else {
return MoveChildStepInner(distance, &UIView::GetX, &Rect::GetWidth);
return MoveChildStepInner(distance, &UIView::GetX, &UIView::GetWidthWithMargin);
}
}
......@@ -468,13 +466,9 @@ void UIList::PushBack(UIView* view)
SetHead(view);
} else {
if (direction_ == VERTICAL) {
view->SetPosition(view->GetStyle(STYLE_MARGIN_LEFT),
childrenTail_->GetY() + childrenTail_->GetRelativeRect().GetHeight() +
childrenTail_->GetStyle(STYLE_MARGIN_BOTTOM) + view->GetStyle(STYLE_MARGIN_TOP));
view->SetPosition(0, childrenTail_->GetY() + childrenTail_->GetHeightWithMargin());
} else {
view->SetPosition(childrenTail_->GetX() + childrenTail_->GetRelativeRect().GetWidth() +
childrenTail_->GetStyle(STYLE_MARGIN_RIGHT) + view->GetStyle(STYLE_MARGIN_LEFT),
view->GetStyle(STYLE_MARGIN_TOP));
view->SetPosition(childrenTail_->GetX() + childrenTail_->GetHeightWithMargin(), 0);
}
bottomIndex_ = GetIndexInc(bottomIndex_);
}
......@@ -492,13 +486,9 @@ void UIList::PushFront(UIView* view)
SetHead(view);
} else {
if (direction_ == VERTICAL) {
view->SetPosition(view->GetStyle(STYLE_MARGIN_LEFT),
GetChildrenHead()->GetY() - GetChildrenHead()->GetStyle(STYLE_MARGIN_TOP) -
view->GetRelativeRect().GetHeight() - view->GetStyle(STYLE_MARGIN_BOTTOM));
view->SetPosition(0, GetChildrenHead()->GetY() - view->GetHeightWithMargin());
} else {
view->SetPosition(GetChildrenHead()->GetX() - GetChildrenHead()->GetStyle(STYLE_MARGIN_LEFT) -
view->GetRelativeRect().GetWidth() - view->GetStyle(STYLE_MARGIN_RIGHT),
view->GetStyle(STYLE_MARGIN_TOP));
view->SetPosition(GetChildrenHead()->GetX() - view->GetWidthWithMargin(), 0);
}
topIndex_ = GetIndexDec(topIndex_);
}
......@@ -525,7 +515,7 @@ void UIList::PopItem(UIView* view)
void UIList::SetHead(UIView* view)
{
if (view != nullptr) {
view->SetPosition(view->GetStyle(STYLE_MARGIN_LEFT), view->GetStyle(STYLE_MARGIN_TOP));
view->SetPosition(0, 0);
topIndex_ = startIndex_;
bottomIndex_ = startIndex_;
}
......@@ -545,8 +535,7 @@ void UIList::MoveChildByOffset(int16_t xOffset, int16_t yOffset)
if ((onSelectedIndex_ != NULL_SELECT_INDEX) && (selectPosition_ != 0)) {
if (direction_ == VERTICAL) {
height = view->GetRelativeRect().GetHeight();
if ((GetChildrenHead()->GetY() - GetChildrenHead()->GetStyle(STYLE_MARGIN_TOP) + yOffset >
selectPosition_) ||
if ((GetChildrenHead()->GetY() + yOffset > selectPosition_) ||
(childrenTail_->GetY() + height + childrenTail_->GetStyle(STYLE_MARGIN_BOTTOM) + yOffset <
selectPosition_)) {
onSelectedIndex_ = NULL_SELECT_INDEX;
......@@ -557,8 +546,7 @@ void UIList::MoveChildByOffset(int16_t xOffset, int16_t yOffset)
}
} else {
width = view->GetRelativeRect().GetWidth();
if ((GetChildrenHead()->GetX() - GetChildrenHead()->GetStyle(STYLE_MARGIN_LEFT) + xOffset >
selectPosition_) ||
if ((GetChildrenHead()->GetX() + xOffset > selectPosition_) ||
(childrenTail_->GetX() + width + childrenTail_->GetStyle(STYLE_MARGIN_RIGHT) < selectPosition_)) {
onSelectedIndex_ = NULL_SELECT_INDEX;
onSelectedView_ = nullptr;
......
......@@ -23,8 +23,14 @@ namespace OHOS {
class PickerListScrollListener : public ListScrollListener {
public:
PickerListScrollListener(UIPicker* picker, UIList* list)
: listView_(list), pickerView_(picker), selectView_(nullptr), lastSelectView_(nullptr),
selectIndex_(0), isInitted_(false){}
: listView_(list),
pickerView_(picker),
selectView_(nullptr),
lastSelectView_(nullptr),
selectIndex_(0),
isInitted_(false)
{
}
virtual ~PickerListScrollListener() {}
......@@ -46,8 +52,7 @@ public:
if (pickerView_->highlightFontName_ == nullptr) {
static_cast<UILabel*>(view)->SetFontId(pickerView_->highlightFontId_);
} else {
static_cast<UILabel*>(view)
->SetFont(pickerView_->highlightFontName_, pickerView_->highlightFontSize_);
static_cast<UILabel*>(view)->SetFont(pickerView_->highlightFontName_, pickerView_->highlightFontSize_);
}
lastSelectView_ = view;
selectIndex_ = index;
......@@ -76,8 +81,7 @@ public:
if (pickerView_->highlightFontName_ == nullptr) {
static_cast<UILabel*>(view)->SetFontId(pickerView_->highlightFontId_);
} else {
static_cast<UILabel*>(view)
->SetFont(pickerView_->highlightFontName_, pickerView_->highlightFontSize_);
static_cast<UILabel*>(view)->SetFont(pickerView_->highlightFontName_, pickerView_->highlightFontSize_);
}
listView_->Invalidate();
......@@ -184,7 +188,7 @@ UIPicker::~UIPicker()
ClearValues();
Remove(&list_);
if (listListener_ != nullptr) {
delete static_cast<PickerListScrollListener *>(listListener_);
delete static_cast<PickerListScrollListener*>(listListener_);
listListener_ = nullptr;
}
......@@ -293,12 +297,9 @@ void UIPicker::RefreshList()
textAdapter_->SetDirect(direct_);
list_.SetHeight(height);
list_.SetWidth(itemsWidth_);
list_.SetPosition(GetWidth() / 2 - list_.GetWidth() / 2, 0); // 2: half
list_.LayoutCenterOfParent();
list_.SetScrollBlankSize((height - itemsHeight_) / 2); // 2: half
list_.SetSelectPosition(height / 2); // 2: half
list_.SetStyle(*style_);
list_.SetStyle(STYLE_BORDER_WIDTH, 0);
list_.SetStyle(STYLE_BACKGROUND_OPA, 0);
list_.SetSelectPosition(height / 2); // 2: half
if (!isSetAdaptered_) {
list_.SetAdapter(textAdapter_);
isSetAdaptered_ = true;
......@@ -342,7 +343,7 @@ bool UIPicker::RefreshSelected(uint16_t index)
listListener->SetInitStatus(false);
// 2: half
int16_t yOffset = (list_.GetHeight() - itemsHeight_) / 2 -
itemsHeight_ * (index - list_.GetChildrenHead()->GetViewIndex());
itemsHeight_ * (index - list_.GetChildrenHead()->GetViewIndex());
list_.SetScrollStateListener(nullptr);
list_.ScrollBy(yOffset - list_.GetChildrenHead()->GetY());
list_.SetScrollStateListener(listListener);
......@@ -466,4 +467,4 @@ void UIPicker::SetTextFormatter(TextFormatter* formatter)
textAdapter_->SetTextFormatter(formatter);
Refresh();
}
}
} // namespace OHOS
......@@ -230,12 +230,12 @@ void UISwipeView::SwitchToPage(int16_t dst, bool needAnimator)
if (alignMode_ == ALIGN_LEFT) {
xOffset = -dstView->GetX();
} else if (alignMode_ == ALIGN_RIGHT) {
xOffset = GetWidth() - (dstView->GetX() + dstView->GetWidth());
xOffset = GetWidth() - (dstView->GetX() + dstView->GetWidthWithMargin());
} else {
xOffset = (GetWidth() >> 1) - (dstView->GetX() + (dstView->GetWidth() >> 1));
xOffset = (GetWidth() >> 1) - (dstView->GetX() + (dstView->GetWidthWithMargin() >> 1));
}
} else {
yOffset = (GetHeight() >> 1) - (dstView->GetY() + (dstView->GetHeight() >> 1));
yOffset = (GetHeight() >> 1) - (dstView->GetY() + (dstView->GetHeightWithMargin() >> 1));
}
if ((xOffset != 0) || (yOffset != 0)) {
......@@ -279,9 +279,9 @@ void UISwipeView::SortChild()
while (next != nullptr) {
if (direction_ == HORIZONTAL) {
next->SetX(pre->GetX() + pre->GetWidth());
next->SetX(pre->GetRelativeRect().GetRight() + pre->GetStyle(STYLE_MARGIN_RIGHT));
} else {
next->SetY(pre->GetY() + pre->GetHeight());
next->SetY(pre->GetRelativeRect().GetBottom() + pre->GetStyle(STYLE_MARGIN_BOTTOM));
}
pre = next;
next->SetViewIndex(index);
......@@ -375,9 +375,9 @@ void UISwipeView::RefreshCurrentViewInner(int16_t distance,
void UISwipeView::RefreshCurrentView(int16_t distance)
{
if (direction_ == HORIZONTAL) {
RefreshCurrentViewInner(distance, &UIView::GetX, &UIView::GetWidth);
RefreshCurrentViewInner(distance, &UIView::GetX, &UIView::GetWidthWithMargin);
} else {
RefreshCurrentViewInner(distance, &UIView::GetY, &UIView::GetHeight);
RefreshCurrentViewInner(distance, &UIView::GetY, &UIView::GetHeightWithMargin);
}
}
......
......@@ -468,8 +468,8 @@ Rect UIView::GetOrigRect() const
int16_t y = rect_.GetY();
UIView* par = parent_;
while (par != nullptr) {
x += par->GetX() + par->style_->paddingLeft_ + par->style_->borderWidth_;
y += par->GetY() + par->style_->paddingTop_ + par->style_->borderWidth_;
x += par->GetRelativeRect().GetX() + par->GetStyle(STYLE_PADDING_LEFT) + par->GetStyle(STYLE_BORDER_WIDTH);
y += par->GetRelativeRect().GetY() + par->GetStyle(STYLE_PADDING_TOP) + par->GetStyle(STYLE_BORDER_WIDTH);
par = par->parent_;
}
return Rect(x, y, x + rect_.GetWidth() - 1, y + rect_.GetHeight() - 1);
......
......@@ -296,9 +296,10 @@ void FlexLayout::LayoutHorizontal()
GetCrossAxisPosY(posY, count, rowsMaxHeight, child);
if (direction_ == LAYOUT_HOR_R) {
child->SetPosition(GetWidth() - (posX - left) - child->GetRelativeRect().GetWidth() - right, posY);
child->SetPosition(GetWidth() - posX - child->GetRelativeRect().GetWidth() - right,
posY - child->GetStyle(STYLE_MARGIN_TOP));
} else {
child->SetPosition(posX, posY);
child->SetPosition(posX - left, posY - child->GetStyle(STYLE_MARGIN_TOP));
}
posX += child->GetRelativeRect().GetWidth() + right + interval;
child->LayoutChildren();
......@@ -483,9 +484,10 @@ void FlexLayout::LayoutVertical()
GetCrossAxisPosX(posX, count, columnsMaxWidth, child);
if (direction_ == LAYOUT_VER_R) {
child->SetPosition(posX, GetHeight() - (posY - top) - child->GetRelativeRect().GetHeight() - bottom);
child->SetPosition(posX - child->GetStyle(STYLE_MARGIN_LEFT),
GetHeight() - posY - child->GetRelativeRect().GetHeight() - bottom);
} else {
child->SetPosition(posX, posY);
child->SetPosition(posX - child->GetStyle(STYLE_MARGIN_LEFT), posY - top);
}
posY += child->GetRelativeRect().GetHeight() + bottom + interval;
child->LayoutChildren();
......
......@@ -113,6 +113,17 @@ public:
return UIView::GetHeight();
}
/**
* @brief Sets the view style.
* @param style Indicates the view style.
* @since 1.0
* @version 1.0
*/
virtual void SetStyle(Style& style) override
{
UIView::SetStyle(style);
}
/**
* @brief Sets a style.
*
......
......@@ -290,9 +290,7 @@ public:
void SetWidth(int16_t width) override
{
contentWidth_ = width;
Style* style = buttonStyles_[state_];
UIView::SetWidth(width + (style->paddingLeft_ + style->paddingRight_) +
(style->borderWidth_ * 2)); /* 2: left and right border */
UIView::SetWidth(width); /* 2: left and right border */
}
/**
......@@ -305,9 +303,7 @@ public:
void SetHeight(int16_t height) override
{
contentHeight_ = height;
Style* style = buttonStyles_[state_];
UIView::SetHeight(height + (style->paddingTop_ + style->paddingBottom_) +
(style->borderWidth_ * 2)); /* 2: top and bottom border */
UIView::SetHeight(height); /* 2: top and bottom border */
}
/**
......
......@@ -421,6 +421,8 @@ public:
*/
void SetY(int16_t y) override;
void ReMeasure() override;
protected:
Text* labelText_;
void RefreshLabel();
......@@ -430,7 +432,6 @@ protected:
private:
friend class LabelAnimator;
void ReMeasure() override;
void RemeasureForMarquee(int16_t textWidth);
bool needRefresh_ : 1;
......
......@@ -446,9 +446,8 @@ private:
void PushFront(UIView* view);
void SetHead(UIView* view);
bool MoveChildStep(int16_t distance);
bool MoveChildStepInner(int16_t distance,
int16_t (UIView::*pfnGetXOrY)() const,
int16_t (Rect::*pfnGetWidthOrHeight)() const);
bool
MoveChildStepInner(int16_t distance, int16_t (UIView::*getXOrY)() const, int16_t (UIView::*getWidthOrHeight)());
uint16_t GetIndexInc(uint16_t index);
uint16_t GetIndexDec(uint16_t index);
......
......@@ -360,8 +360,10 @@ protected:
private:
void RefreshCurrentView(int16_t distance);
void RefreshCurrentViewInner(int16_t distance, int16_t (UIView::*pfnGetXOrY)() const,
int16_t(UIView::*pfnGetWidthOrHeight)());
void RefreshCurrentViewInner(int16_t distance,
int16_t (UIView::*pfnGetXOrY)() const,
int16_t (UIView::*pfnGetWidthOrHeight)());
bool isNeedLoop();
void MoveFirstChildToLast();
void MoveLastChildToFirst();
......
......@@ -879,7 +879,12 @@ public:
* @since 1.0
* @version 1.0
*/
virtual void SetX(int16_t x) { rect_.SetX(x); }
virtual void SetX(int16_t x)
{
if (GetX() != x) {
rect_.SetX(x + GetStyle(STYLE_MARGIN_LEFT));
}
}
/**
* @brief Sets a percentage that represents the proportion of the view's x-coordinate
......@@ -896,7 +901,10 @@ public:
* @since 1.0
* @version 1.0
*/
int16_t GetX() const { return rect_.GetX(); }
int16_t GetX() const
{
return rect_.GetX() - GetStyle(STYLE_MARGIN_LEFT);
}
/**
* @brief Sets the y-coordinate for the view.
......@@ -904,7 +912,12 @@ public:
* @since 1.0
* @version 1.0
*/
virtual void SetY(int16_t y) { rect_.SetY(y); }
virtual void SetY(int16_t y)
{
if (GetY() != y) {
rect_.SetY(y + GetStyle(STYLE_MARGIN_TOP));
}
}
/**
* @brief Sets a percentage that represents the proportion of the view's y-coordinate
......@@ -921,7 +934,32 @@ public:
* @since 1.0
* @version 1.0
*/
int16_t GetY() const { return rect_.GetY(); }
int16_t GetY() const
{
return rect_.GetY() - GetStyle(STYLE_MARGIN_TOP);
}
/**
* @brief 获取组件设置margin属性后margin的宽度,包括组件宽度加marginLeft 加 marginRight.
* @return margin的宽度
* @since 3.0
* @version 3.0
*/
int16_t GetWidthWithMargin()
{
return GetRelativeRect().GetWidth() + GetStyle(STYLE_MARGIN_LEFT) + GetStyle(STYLE_MARGIN_RIGHT);
}
/**
* @brief 获取组件设置margin属性后margin的高度度,包括组件宽度加marginTop 加 marginBottom.
* @return margin的高度
* @since 3.0
* @version 3.0
*/
int16_t GetHeightWithMargin()
{
return GetRelativeRect().GetHeight() + GetStyle(STYLE_MARGIN_TOP) + GetStyle(STYLE_MARGIN_BOTTOM);
}
/**
* @brief Sets the position for the view.
......@@ -930,7 +968,11 @@ public:
* @since 1.0
* @version 1.0
*/
virtual void SetPosition(int16_t x, int16_t y) { rect_.SetPosition(x, y); }
virtual void SetPosition(int16_t x, int16_t y)
{
SetX(x);
SetY(y);
}
/**
* @brief Sets the position percentages for the view.
......
......@@ -60,6 +60,7 @@ test_sources = [
"../uitest/test_view_group/ui_test_view_group.cpp",
"../uitest/test_view_percent/ui_test_view_percent.cpp",
"../uitest/test_view_scale_rotate/ui_test_view_scale_rotate.cpp",
"../uitest/test_border_margin_padding/ui_test_border_margin_padding.cpp",
"src/test_ability.cpp",
"src/test_case_list_adapter.cpp",
"src/ui_test_app.cpp",
......
......@@ -19,6 +19,7 @@
#include "test_animator/ui_test_animator.h"
#include "test_anti_aliasing/ui_test_anti_aliasing.h"
#include "test_arc_label/ui_test_arc_label.h"
#include "test_border_margin_padding/ui_test_border_margin_padding.h"
#include "test_button/ui_test_button.h"
#include "test_canvas/ui_test_canvas.h"
#include "test_chart/ui_test_chart_pillar.h"
......@@ -141,6 +142,7 @@ void UITestGroup::SetUpTestCase()
#if ENABLE_FOCUS_MANAGER
testCaseList_.PushBack(TestCaseInfo{"FocusManager", new UITestFocusManager()});
#endif
testCaseList_.PushBack(TestCaseInfo{"Border_Margin_Padding", new UITestBorderMarginPadding()});
}
List<TestCaseInfo>& UITestGroup::GetTestCase()
......
/*
* Copyright (c) 2020-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_BORDER_MARGIN_PADDING_H
#define UI_TEST_BORDER_MARGIN_PADDING_H
#include "components/text_adapter.h"
#include "components/ui_chart.h"
#include "components/ui_label.h"
#include "components/ui_picker.h"
#include "components/ui_scroll_view.h"
#include "components/ui_toggle_button.h"
#include "layout/grid_layout.h"
#include "layout/list_layout.h"
#include "ui_test.h"
namespace OHOS {
class BorderListener;
class MarginListener;
class PaddingListener;
class UITestBorderMarginPadding : public UITest {
public:
UITestBorderMarginPadding()
{
style_ = StyleDefault::GetDefaultStyle();
style_.bgOpa_ = OPA_OPAQUE;
style_.bgColor_ = Color::Gray();
}
virtual ~UITestBorderMarginPadding() {}
void SetUp() override;
void TearDown() override;
UIView* GetTestView() override;
void ReloadTest();
void UIKit_UITestBorderMarginPadding_Test_001();
void UIKit_UITestBorderMarginPadding_Test_002();
void UIKit_UITestBorderMarginPadding_Test_003();
void UIKit_UITestBorderMarginPadding_Test_004();
void UIKit_UITestBorderMarginPadding_Test_005();
void UIKit_UITestBorderMarginPadding_Test_006();
void UIKit_UITestBorderMarginPadding_Test_007();
void UIKit_UITestBorderMarginPadding_Test_008();
void UIKit_UITestBorderMarginPadding_Test_009();
void UIKit_UITestBorderMarginPadding_Test_010();
void UIKit_UITestBorderMarginPadding_Test_011();
void UIKit_UITestBorderMarginPadding_Test_012();
void UIKit_UITestBorderMarginPadding_Test_013();
void UIKit_UITestBorderMarginPadding_Test_014();
void UIKit_UITestBorderMarginPadding_Test_015();
void UIKit_UITestBorderMarginPadding_Test_016();
void UIKit_UITestBorderMarginPadding_Test_017();
void UIKit_UITestBorderMarginPadding_Test_018();
Style style_;
private:
const int16_t TITLE_HEIGHT = 29;
const int16_t BUTTON_GROUP_WIDTH = 250;
UIScrollView scroll_;
GridLayout layoutButton_;
ListLayout* listScroll_ = nullptr;
UIViewGroup container_;
UILabel labelMargin_;
UIToggleButton margin_;
UILabel labelBorder_;
UIToggleButton border_;
UILabel labelPadding_;
UIToggleButton padding_;
MarginListener* marginListener_ = nullptr;
BorderListener* borderListener_ = nullptr;
PaddingListener* paddingListener_ = nullptr;
UIChartPolyline* chart_ = nullptr;
UIChartDataSerial* dataSerial_ = nullptr;
TextAdapter* adapter_ = nullptr;
List<const char*>* adapterData_ = nullptr;
UIPicker* picker_ = nullptr;
void AddTitle(const char* text);
};
class MarginListener : public UIToggleButton::OnChangeListener {
public:
explicit MarginListener(UITestBorderMarginPadding* view)
{
view_ = view;
}
virtual ~MarginListener() {}
virtual bool OnChange(UICheckBox::UICheckBoxState state)
{
if (state == UICheckBox::SELECTED) {
view_->style_.SetStyle(STYLE_MARGIN_LEFT, MARGIN_SIZE);
view_->style_.SetStyle(STYLE_MARGIN_TOP, MARGIN_SIZE);
view_->style_.SetStyle(STYLE_MARGIN_RIGHT, MARGIN_SIZE);
view_->style_.SetStyle(STYLE_MARGIN_BOTTOM, MARGIN_SIZE);
} else {
view_->style_.SetStyle(STYLE_MARGIN_LEFT, 0);
view_->style_.SetStyle(STYLE_MARGIN_TOP, 0);
view_->style_.SetStyle(STYLE_MARGIN_RIGHT, 0);
view_->style_.SetStyle(STYLE_MARGIN_BOTTOM, 0);
}
view_->ReloadTest();
}
private:
static constexpr int16_t MARGIN_SIZE = 30;
UITestBorderMarginPadding* view_ = nullptr;
};
class BorderListener : public UIToggleButton::OnChangeListener {
public:
explicit BorderListener(UITestBorderMarginPadding* view)
{
view_ = view;
}
virtual ~BorderListener() {}
virtual bool OnChange(UICheckBox::UICheckBoxState state)
{
if (state == UICheckBox::SELECTED) {
view_->style_.SetStyle(STYLE_BORDER_WIDTH, 20); // 20: border width
view_->style_.SetStyle(STYLE_BORDER_OPA, OPA_OPAQUE);
view_->style_.SetStyle(STYLE_BORDER_COLOR, Color::Blue().full);
} else {
view_->style_.SetStyle(STYLE_BORDER_WIDTH, 0);
}
view_->ReloadTest();
}
private:
UITestBorderMarginPadding* view_ = nullptr;
};
class PaddingListener : public UIToggleButton::OnChangeListener {
public:
explicit PaddingListener(UITestBorderMarginPadding* view)
{
view_ = view;
}
virtual ~PaddingListener() {}
virtual bool OnChange(UICheckBox::UICheckBoxState state)
{
if (state == UICheckBox::SELECTED) {
view_->style_.SetStyle(STYLE_PADDING_LEFT, PADDING_SIZE);
view_->style_.SetStyle(STYLE_PADDING_TOP, PADDING_SIZE);
view_->style_.SetStyle(STYLE_PADDING_RIGHT, PADDING_SIZE);
view_->style_.SetStyle(STYLE_PADDING_BOTTOM, PADDING_SIZE);
} else {
view_->style_.SetStyle(STYLE_PADDING_LEFT, 0);
view_->style_.SetStyle(STYLE_PADDING_TOP, 0);
view_->style_.SetStyle(STYLE_PADDING_RIGHT, 0);
view_->style_.SetStyle(STYLE_PADDING_BOTTOM, 0);
}
view_->ReloadTest();
}
private:
static constexpr int16_t PADDING_SIZE = 30;
UITestBorderMarginPadding* view_ = nullptr;
};
} // namespace OHOS
#endif // UI_TEST_BORDER_MARGIN_PADDING_H
......@@ -30,6 +30,7 @@ SOURCES += \
../../../../test/uitest/test_animator/ui_test_animator.cpp \
../../../../test/uitest/test_anti_aliasing/ui_test_anti_aliasing.cpp \
../../../../test/uitest/test_arc_label/ui_test_arc_label.cpp \
../../../../test/uitest/test_border_margin_padding/ui_test_border_margin_padding.cpp \
../../../../test/uitest/test_button/ui_test_button.cpp \
../../../../test/uitest/test_canvas/ui_test_canvas.cpp \
../../../../test/uitest/test_chart/ui_test_chart_pillar.cpp \
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册