From d8257deba521f2d9ec2ba78f0640f3e645a1f27a Mon Sep 17 00:00:00 2001 From: s30052571 Date: Thu, 7 Mar 2024 16:25:40 +0800 Subject: [PATCH] update menubar style for lost part. Signed-off-by: s30052571 --- .../pattern/app_bar/app_bar_view.cpp | 194 ++++++++--------- .../app_bar/atomic_service_pattern.cpp | 205 +++++++++++------- .../pattern/app_bar/atomic_service_pattern.h | 12 +- 3 files changed, 225 insertions(+), 186 deletions(-) diff --git a/frameworks/core/components_ng/pattern/app_bar/app_bar_view.cpp b/frameworks/core/components_ng/pattern/app_bar/app_bar_view.cpp index 70620f8a1c7..2af5edb22f8 100644 --- a/frameworks/core/components_ng/pattern/app_bar/app_bar_view.cpp +++ b/frameworks/core/components_ng/pattern/app_bar/app_bar_view.cpp @@ -69,7 +69,7 @@ RefPtr AppBarView::Create(const RefPtr& stage) auto pattern = atom->GetPattern(); CHECK_NULL_RETURN(pattern, nullptr); pattern->UpdateColor(); - pattern->UpdateRowLayout(); + pattern->UpdateLayout(); return atom; } @@ -77,25 +77,27 @@ RefPtr AppBarView::BuildMenuBarRow() { auto menuBarRow = FrameNode::CreateFrameNode(V2::APP_BAR_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr(false)); - // get theme - auto appBarTheme = GetAppBarTheme(); - CHECK_NULL_RETURN(appBarTheme, nullptr); - // add children + auto theme = GetAppBarTheme(); + CHECK_NULL_RETURN(theme, nullptr); + auto menuBar = BuildMenuBar(); menuBarRow->AddChild(menuBar); - // init + auto layoutProperty = menuBarRow->GetLayoutProperty(); auto renderContext = menuBarRow->GetRenderContext(); - + // size layoutProperty->UpdateUserDefinedIdealSize( - CalcSize(CalcLength(1.0, DimensionUnit::PERCENT), CalcLength(appBarTheme->GetMenuBarHeight()))); - + CalcSize(CalcLength(1.0, DimensionUnit::PERCENT), CalcLength(theme->GetMenuBarHeight()))); + // main axis align layoutProperty->UpdateMainAxisAlign(FlexAlign::FLEX_END); - renderContext->UpdatePosition(OffsetT(0.0_vp, appBarTheme->GetMenuBarTopMargin())); + // position + renderContext->UpdatePosition(OffsetT(0.0_vp, theme->GetMenuBarTopMargin())); + // background color renderContext->UpdateBackgroundColor(Color::TRANSPARENT); + // hit test mode menuBarRow->SetHitTestMode(HitTestMode::HTMTRANSPARENT_SELF); - menuBarRow->MarkModifyDone(); + menuBarRow->MarkModifyDone(); return menuBarRow; } @@ -103,10 +105,9 @@ RefPtr AppBarView::BuildMenuBar() { auto menuBar = FrameNode::CreateFrameNode(V2::ROW_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr(false)); - // get theme - auto appBarTheme = GetAppBarTheme(); - CHECK_NULL_RETURN(appBarTheme, nullptr); - // add child + auto theme = GetAppBarTheme(); + CHECK_NULL_RETURN(theme, nullptr); + auto menuButton = BuildButton(true); BindMenuCallback(menuButton); menuBar->AddChild(menuButton); @@ -115,104 +116,76 @@ RefPtr AppBarView::BuildMenuBar() auto closeButton = BuildButton(false); BindCloseCallback(closeButton); menuBar->AddChild(closeButton); - // init + auto layoutProperty = menuBar->GetLayoutProperty(); auto renderContext = menuBar->GetRenderContext(); - + // main axis align layoutProperty->UpdateMainAxisAlign(FlexAlign::FLEX_START); - + // border width BorderWidthProperty borderWidth; - borderWidth.SetBorderWidth(appBarTheme->GetBorderWidth()); + borderWidth.SetBorderWidth(theme->GetBorderWidth()); layoutProperty->UpdateBorderWidth(borderWidth); renderContext->UpdateBorderWidth(borderWidth); - - auto bent = appBarTheme->GetBentRadius(); + // border radius + auto bent = theme->GetBentRadius(); renderContext->UpdateBorderRadius(BorderRadiusProperty(bent)); - MarginProperty margin; - margin.left = CalcLength(appBarTheme->GetMenuBarLeftMargin()); - margin.right = CalcLength(appBarTheme->GetMenuBarRightMargin()); - layoutProperty->UpdateMargin(margin); menuBar->MarkModifyDone(); - return menuBar; } RefPtr AppBarView::BuildButton(bool isMenuButton) { - auto appBarTheme = GetAppBarTheme(); - CHECK_NULL_RETURN(appBarTheme, nullptr); - auto icon = BuildIcon(isMenuButton); - // create button auto button = FrameNode::CreateFrameNode( V2::BUTTON_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr()); auto renderContext = button->GetRenderContext(); renderContext->UpdateBackgroundColor(Color::TRANSPARENT); - // init + auto theme = GetAppBarTheme(); + CHECK_NULL_RETURN(theme, nullptr); + + auto icon = BuildIcon(isMenuButton); + button->AddChild(icon); + auto layoutProperty = button->GetLayoutProperty(); - layoutProperty->UpdateType(ButtonType::CUSTOM); + // type + layoutProperty->UpdateType(ButtonType::NORMAL); + // size layoutProperty->UpdateUserDefinedIdealSize( - CalcSize(CalcLength(appBarTheme->GetButtonWidth()), CalcLength(appBarTheme->GetButtonHeight()))); - auto buttonRenderContext = button->GetRenderContext(); - auto bent = appBarTheme->GetBentRadius(); - auto rightAngle = appBarTheme->GetRightAngle(); - if (isMenuButton) { - buttonRenderContext->UpdateBorderRadius(BorderRadiusProperty(bent, rightAngle, bent, rightAngle)); - } else { - buttonRenderContext->UpdateBorderRadius(BorderRadiusProperty(rightAngle, bent, rightAngle, bent)); - } - auto focus = button->GetFocusHub(); - auto focusPattern = button->GetPattern(); - if (focus) { - focus->SetFocusable(true); - } - if (focusPattern) { - focusPattern->SetStyleType(FocusStyleType::INNER_BORDER); - } + CalcSize(CalcLength(theme->GetButtonWidth()), CalcLength(theme->GetButtonHeight()))); + // focus style type + auto focusHub = button->GetFocusHub(); + CHECK_NULL_RETURN(focusHub, nullptr); + focusHub->SetFocusStyleType(FocusStyleType::INNER_BORDER); + // focus border width auto buttonPattern = button->GetPattern(); - if (buttonPattern) { - buttonPattern->SetClickedColor(appBarTheme->GetClickEffectColor()); - } - button->AddChild(icon); - button->MarkModifyDone(); + CHECK_NULL_RETURN(buttonPattern, nullptr); + buttonPattern->SetFocusBorderWidth(theme->GetFocusedOutlineWidth()); + button->MarkModifyDone(); return button; } RefPtr AppBarView::BuildIcon(bool isMenuIcon) { - // create image auto icon = FrameNode::CreateFrameNode( V2::IMAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr()); - // set icon + auto theme = GetAppBarTheme(); + CHECK_NULL_RETURN(theme, nullptr); + ImageSourceInfo imageSourceInfo; imageSourceInfo.SetResourceId( isMenuIcon ? InternalResource::ResourceId::APP_BAR_MENU_SVG : InternalResource::ResourceId::APP_BAR_CLOSE_SVG); auto layoutProperty = icon->GetLayoutProperty(); layoutProperty->UpdateImageSourceInfo(imageSourceInfo); - // set size - auto appBarTheme = GetAppBarTheme(); - CHECK_NULL_RETURN(appBarTheme, nullptr); + // size layoutProperty->UpdateUserDefinedIdealSize( - CalcSize(CalcLength(appBarTheme->GetNewIconSize()), CalcLength(appBarTheme->GetNewIconSize()))); - // set margin - MarginProperty margin; - margin.top = CalcLength(appBarTheme->GetIconVerticalMargin()); - margin.bottom = CalcLength(appBarTheme->GetIconVerticalMargin()); - if (isMenuIcon) { - margin.left = CalcLength(appBarTheme->GetIconOutsideMargin()); - margin.right = CalcLength(appBarTheme->GetIconInsideMargin()); - } else { - margin.left = CalcLength(appBarTheme->GetIconInsideMargin()); - margin.right = CalcLength(appBarTheme->GetIconOutsideMargin()); - } - auto focus = icon->GetFocusHub(); - if (focus) { - focus->SetFocusable(false); - } - layoutProperty->UpdateMargin(margin); - icon->MarkModifyDone(); + CalcSize(CalcLength(theme->GetNewIconSize()), CalcLength(theme->GetNewIconSize()))); + // focusable + auto focusHub = icon->GetFocusHub(); + CHECK_NULL_RETURN(focusHub, nullptr); + focusHub->SetFocusable(true); + icon->MarkModifyDone(); return icon; } @@ -220,20 +193,27 @@ RefPtr AppBarView::BuildDivider() { auto divider = FrameNode::CreateFrameNode( V2::DIVIDER_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr()); - // get theme - auto appBarTheme = GetAppBarTheme(); - CHECK_NULL_RETURN(appBarTheme, nullptr); - // init + auto theme = GetAppBarTheme(); + CHECK_NULL_RETURN(theme, nullptr); + auto layoutProperty = divider->GetLayoutProperty(); + // size layoutProperty->UpdateUserDefinedIdealSize( - CalcSize(CalcLength(appBarTheme->GetDividerWidth()), CalcLength(appBarTheme->GetDividerHeight()))); + CalcSize(CalcLength(theme->GetDividerWidth()), CalcLength(theme->GetDividerHeight()))); + // direction layoutProperty->UpdateVertical(true); - layoutProperty->UpdateStrokeWidth(appBarTheme->GetDividerWidth()); - + // stroke width + layoutProperty->UpdateStrokeWidth(theme->GetDividerWidth()); + // marigin + MarginProperty margin; + margin.left = CalcLength(-(theme->GetDividerWidth())); auto renderProperty = divider->GetPaintProperty(); - renderProperty->UpdateDividerColor(appBarTheme->GetDividerColor()); + // color + renderProperty->UpdateDividerColor(theme->GetDividerColor()); + // line cap renderProperty->UpdateLineCap(LineCap::ROUND); + divider->MarkModifyDone(); return divider; } @@ -246,12 +226,12 @@ void AppBarView::BindMenuCallback(const RefPtr& menuButton) #else auto pipeline = PipelineContext::GetCurrentContext(); CHECK_NULL_VOID(pipeline); - auto appBarTheme = pipeline->GetTheme(); - CHECK_NULL_VOID(appBarTheme); + auto theme = pipeline->GetTheme(); + CHECK_NULL_VOID(theme); if (SystemProperties::GetExtSurfaceEnabled()) { - LOGI("start panel bundleName is %{public}s, abilityName is %{public}s", - appBarTheme->GetBundleName().c_str(), appBarTheme->GetAbilityName().c_str()); - pipeline->FireSharePanelCallback(appBarTheme->GetBundleName(), appBarTheme->GetAbilityName()); + LOGI("start panel bundleName is %{public}s, abilityName is %{public}s", theme->GetBundleName().c_str(), + theme->GetAbilityName().c_str()); + pipeline->FireSharePanelCallback(theme->GetBundleName(), theme->GetAbilityName()); } else { auto menuButton = weakButton.Upgrade(); CHECK_NULL_VOID(menuButton); @@ -259,9 +239,9 @@ void AppBarView::BindMenuCallback(const RefPtr& menuButton) } #endif }; - auto buttonEventHub = menuButton->GetOrCreateGestureEventHub(); - if (buttonEventHub) { - buttonEventHub->AddClickEvent(AceType::MakeRefPtr(std::move(clickCallback))); + auto eventHub = menuButton->GetOrCreateGestureEventHub(); + if (eventHub) { + eventHub->AddClickEvent(AceType::MakeRefPtr(std::move(clickCallback))); } } @@ -274,9 +254,9 @@ void AppBarView::BindCloseCallback(const RefPtr& closeButton) CHECK_NULL_VOID(windowManager); windowManager->WindowMinimize(); }; - auto buttonEventHub = closeButton->GetOrCreateGestureEventHub(); - if (buttonEventHub) { - buttonEventHub->AddClickEvent(AceType::MakeRefPtr(std::move(clickCallback))); + auto eventHub = closeButton->GetOrCreateGestureEventHub(); + if (eventHub) { + eventHub->AddClickEvent(AceType::MakeRefPtr(std::move(clickCallback))); } } @@ -293,9 +273,9 @@ void AppBarView::BindContentCover(const RefPtr& targetNode) CHECK_NULL_VOID(overlayManager); std::string stageAbilityName = ""; - auto appBarTheme = pipeline->GetTheme(); - if (appBarTheme) { - stageAbilityName = appBarTheme->GetStageAbilityName(); + auto theme = pipeline->GetTheme(); + if (theme) { + stageAbilityName = theme->GetStageAbilityName(); } NG::ModalStyle modalStyle; modalStyle.modalTransition = NG::ModalTransition::NONE; @@ -357,14 +337,26 @@ std::optional AppBarView::GetAppBarRect() } auto theme = GetAppBarTheme(); CHECK_NULL_RETURN(theme, std::nullopt); - SizeF size(theme->GetMenuBarWidth().ConvertToPx(), theme->GetMenuBarHeight().ConvertToPx()); auto atom = atomicService_.Upgrade(); CHECK_NULL_RETURN(atom, std::nullopt); auto pattern = atom->GetPattern(); CHECK_NULL_RETURN(pattern, std::nullopt); auto menuBar = pattern->GetMenuBar(); CHECK_NULL_RETURN(menuBar, std::nullopt); - auto offset = menuBar->GetParentGlobalOffsetDuringLayout(); + auto size = menuBar->GetGeometryNode()->GetMarginFrameSize(); + auto offset = menuBar->GetGeometryNode()->GetMarginFrameOffset(); + auto parent = menuBar->GetParent(); + while (parent) { + auto frameNode = AceType::DynamicCast(parent); + if (frameNode) { + offset += frameNode->GetGeometryNode()->GetFrameOffset(); + } + parent = parent->GetParent(); + } + offset.AddY(theme->GetMenuBarTopMargin().ConvertToPx()); + auto manager = pipeline->GetSafeAreaManager(); + CHECK_NULL_RETURN(manager, std::nullopt); + offset.AddY(manager->GetSystemSafeArea().top_.Length()); return RectF(offset, size); } } // namespace OHOS::Ace::NG diff --git a/frameworks/core/components_ng/pattern/app_bar/atomic_service_pattern.cpp b/frameworks/core/components_ng/pattern/app_bar/atomic_service_pattern.cpp index 88231eff83b..d14509bb131 100644 --- a/frameworks/core/components_ng/pattern/app_bar/atomic_service_pattern.cpp +++ b/frameworks/core/components_ng/pattern/app_bar/atomic_service_pattern.cpp @@ -41,17 +41,19 @@ void AtomicServicePattern::BeforeCreateLayoutWrapper() .bottom = CalcLength(safeArea.bottom_.Length()), }; host->GetLayoutProperty()->UpdatePadding(padding); + auto systemSafeArea = manager->GetSystemSafeArea(); - if (safeArea.top_.Length() != systemSafeArea.top_.Length()) { - auto menuBarRow = DynamicCast(host->GetChildAtIndex(1)); - auto renderContext = menuBarRow->GetRenderContext(); - auto appBarTheme = pipeline->GetTheme(); - CHECK_NULL_VOID(appBarTheme); - float topMargin = appBarTheme->GetMenuBarTopMargin().ConvertToPx() + systemSafeArea.top_.Length(); - renderContext->UpdatePosition(OffsetT(0.0_vp, Dimension(topMargin, DimensionUnit::PX))); - menuBarRow->MarkModifyDone(); - menuBarRow->MarkDirtyNode(); - } + auto theme = pipeline->GetTheme(); + CHECK_NULL_VOID(theme); + float topMargin = theme->GetMenuBarTopMargin().ConvertToPx(); + topMargin += (systemSafeArea.top_.Length() - safeArea.top_.Length()); + auto menuBarRow = GetMenuBarRow(); + CHECK_NULL_VOID(menuBarRow); + auto renderContext = menuBarRow->GetRenderContext(); + renderContext->UpdatePosition(OffsetT(0.0_vp, Dimension(topMargin, DimensionUnit::PX))); + + menuBarRow->MarkModifyDone(); + menuBarRow->MarkDirtyNode(); } void AtomicServicePattern::OnAttachToFrameNode() @@ -66,16 +68,11 @@ void AtomicServicePattern::OnAttachToFrameNode() void AtomicServicePattern::OnLanguageConfigurationUpdate() { - UpdateRowLayout(); + UpdateLayout(); } void AtomicServicePattern::OnColorConfigurationUpdate() { - auto node = GetHost(); - CHECK_NULL_VOID(node); - auto row = node->GetLastChild(); - CHECK_NULL_VOID(row); - row->SetNeedCallChildrenUpdate(false); UpdateColor(); } @@ -129,101 +126,147 @@ RefPtr AtomicServicePattern::GetCloseIcon() void AtomicServicePattern::UpdateColor() { - // get theme auto pipeline = PipelineContext::GetCurrentContext(); CHECK_NULL_VOID(pipeline); - auto appBarTheme = pipeline->GetTheme(); - CHECK_NULL_VOID(appBarTheme); - // set icon color + auto theme = pipeline->GetTheme(); + + auto menuBar = GetMenuBar(); + UpdateMenuBarColor(theme, menuBar); + + auto menuButton = GetMenuButton(); + UpdateButtonColor(theme, menuButton); + auto closeButton = GetCloseButton(); + UpdateButtonColor(theme, closeButton); + auto menuIcon = GetMenuIcon(); - CHECK_NULL_VOID(menuIcon); - SetEachIconColor(menuIcon, appBarTheme->GetIconColor(), InternalResource::ResourceId::APP_BAR_MENU_SVG); + UpdateIconColor(theme, menuIcon); auto closeIcon = GetCloseIcon(); - CHECK_NULL_VOID(closeIcon); - SetEachIconColor(closeIcon, appBarTheme->GetIconColor(), InternalResource::ResourceId::APP_BAR_CLOSE_SVG); - // set background color - auto menuBar = GetMenuBar(); + UpdateIconColor(theme, closeIcon); +} + +void AtomicServicePattern::UpdateMenuBarColor(RefPtr& theme, RefPtr& menuBar) +{ + CHECK_NULL_VOID(theme); CHECK_NULL_VOID(menuBar); - auto menuBarRenderContext = menuBar->GetRenderContext(); + auto renderContext = menuBar->GetRenderContext(); + // background blur style BlurStyleOption option; option.blurStyle = SystemProperties::GetColorMode() == ColorMode::DARK ? BlurStyle::COMPONENT_ULTRA_THICK : BlurStyle::COMPONENT_THIN; - menuBarRenderContext->UpdateBackBlurStyle(option); - // set border color - BorderColorProperty borderColorProperty; - borderColorProperty.SetColor(appBarTheme->GetBorderColor()); - menuBarRenderContext->UpdateBorderColor(borderColorProperty); + renderContext->UpdateBackBlurStyle(option); + // border color + BorderColorProperty borderColor; + borderColor.SetColor(theme->GetBorderColor()); + renderContext->UpdateBorderColor(borderColor); + menuBar->MarkModifyDone(); menuBar->MarkDirtyNode(); } -void AtomicServicePattern::UpdateRowLayout() +void AtomicServicePattern::UpdateButtonColor(RefPtr& theme, RefPtr& button) +{ + CHECK_NULL_VOID(theme); + CHECK_NULL_VOID(button); + // pressed color + auto buttonPattern = button->GetPattern(); + CHECK_NULL_VOID(buttonPattern); + buttonPattern->SetClickedColor(theme->GetClickEffectColor()); + // focus border color + buttonPattern->SetFocusBorderColor(theme->GetFocusedOutlineColor()); + + button->MarkModifyDone(); + button->MarkDirtyNode(); +} + +void AtomicServicePattern::UpdateIconColor(RefPtr& theme, RefPtr& icon) +{ + CHECK_NULL_VOID(theme); + CHECK_NULL_VOID(icon); + // fill color + auto layoutProperty = icon->GetLayoutProperty(); + auto imageSourceInfo = layoutProperty->GetImageSourceInfo(); + imageSourceInfo->SetFillColor(theme->GetIconColor()); + layoutProperty->UpdateImageSourceInfo(imageSourceInfo.value()); + + icon->MarkModifyDone(); + icon->MarkDirtyNode(); +} + +void AtomicServicePattern::UpdateLayout() { - bool isRtl = AceApplicationInfo::GetInstance().IsRightToLeft(); - // get theme auto pipeline = PipelineContext::GetCurrentContext(); CHECK_NULL_VOID(pipeline); - auto appBarTheme = pipeline->GetTheme(); - CHECK_NULL_VOID(appBarTheme); - // set margin + auto theme = pipeline->GetTheme(); + CHECK_NULL_VOID(theme); + bool isRtl = AceApplicationInfo::GetInstance().IsRightToLeft(); + auto menuBar = GetMenuBar(); + UpdateMenuBarLayout(theme, menuBar, isRtl); + + auto menuButton = GetMenuButton(); + UpdateButtonLayout(theme, menuButton, !isRtl); + auto closeButton = GetCloseButton(); + UpdateButtonLayout(theme, closeButton, isRtl); + + auto menuIcon = GetMenuIcon(); + UpdateIconLayout(theme, menuIcon, !isRtl); + auto closeIcon = GetCloseIcon(); + UpdateIconLayout(theme, closeIcon, isRtl); +} + +void AtomicServicePattern::UpdateMenuBarLayout(RefPtr& theme, RefPtr& menuBar, bool isRtl) +{ + CHECK_NULL_VOID(theme); CHECK_NULL_VOID(menuBar); - MarginProperty menuBarMargin; + + MarginProperty margin; if (isRtl) { - menuBarMargin.left = CalcLength(appBarTheme->GetMenuBarRightMargin()); - menuBarMargin.right = CalcLength(appBarTheme->GetMenuBarLeftMargin()); + margin.left = CalcLength(theme->GetMenuBarRightMargin()); + margin.right = CalcLength(theme->GetMenuBarLeftMargin()); } else { - menuBarMargin.left = CalcLength(appBarTheme->GetMenuBarLeftMargin()); - menuBarMargin.right = CalcLength(appBarTheme->GetMenuBarRightMargin()); + margin.left = CalcLength(theme->GetMenuBarLeftMargin()); + margin.right = CalcLength(theme->GetMenuBarRightMargin()); } - menuBar->GetLayoutProperty()->UpdateMargin(menuBarMargin); + menuBar->GetLayoutProperty()->UpdateMargin(margin); + menuBar->MarkModifyDone(); menuBar->MarkDirtyNode(); +} - auto menuIcon = GetMenuIcon(); - CHECK_NULL_VOID(menuIcon); - auto closeIcon = GetCloseIcon(); - CHECK_NULL_VOID(closeIcon); - MarginProperty menuIconMargin; - MarginProperty closeIconMargin; - menuIconMargin.top = CalcLength(appBarTheme->GetIconVerticalMargin()); - menuIconMargin.bottom = CalcLength(appBarTheme->GetIconVerticalMargin()); - closeIconMargin.top = CalcLength(appBarTheme->GetIconVerticalMargin()); - closeIconMargin.bottom = CalcLength(appBarTheme->GetIconVerticalMargin()); - if (isRtl) { - menuIconMargin.left = CalcLength(appBarTheme->GetIconInsideMargin()); - menuIconMargin.right = CalcLength(appBarTheme->GetIconOutsideMargin()); - closeIconMargin.left = CalcLength(appBarTheme->GetIconOutsideMargin()); - closeIconMargin.right = CalcLength(appBarTheme->GetIconInsideMargin()); - } else { - menuIconMargin.left = CalcLength(appBarTheme->GetIconOutsideMargin()); - menuIconMargin.right = CalcLength(appBarTheme->GetIconInsideMargin()); - closeIconMargin.left = CalcLength(appBarTheme->GetIconInsideMargin()); - closeIconMargin.right = CalcLength(appBarTheme->GetIconOutsideMargin()); - } - menuIcon->GetLayoutProperty()->UpdateMargin(menuIconMargin); - closeIcon->GetLayoutProperty()->UpdateMargin(closeIconMargin); +void AtomicServicePattern::UpdateButtonLayout(RefPtr& theme, RefPtr& button, bool isLeft) +{ + CHECK_NULL_VOID(theme); + CHECK_NULL_VOID(button); + + auto bent = theme->GetBentRadius(); + auto rightAngle = theme->GetRightAngle(); + auto leftBorderRadius = BorderRadiusProperty(bent, rightAngle, rightAngle, bent); + auto rightBorderRadius = BorderRadiusProperty(rightAngle, bent, bent, rightAngle); - menuIcon->MarkModifyDone(); - menuIcon->MarkDirtyNode(); - closeIcon->MarkModifyDone(); - closeIcon->MarkDirtyNode(); + auto layoutProperty = button->GetLayoutProperty(); + layoutProperty->UpdateBorderRadius(isLeft ? leftBorderRadius : rightBorderRadius); + + button->MarkModifyDone(); + button->MarkDirtyNode(); } -void AtomicServicePattern::SetEachIconColor( - RefPtr icon, const std::optional& color, InternalResource::ResourceId image) +void AtomicServicePattern::UpdateIconLayout(RefPtr& theme, RefPtr& icon, bool isLeft) { + CHECK_NULL_VOID(theme); CHECK_NULL_VOID(icon); - ImageSourceInfo info; - if (color.has_value()) { - info.SetResourceId(image, color); + + MarginProperty margin; + margin.top = CalcLength(theme->GetIconVerticalMargin()); + margin.bottom = CalcLength(theme->GetIconVerticalMargin()); + if (isLeft) { + margin.left = CalcLength(theme->GetIconOutsideMargin()); + margin.right = CalcLength(theme->GetIconInsideMargin()); } else { - auto pipeline = PipelineContext::GetCurrentContext(); - CHECK_NULL_VOID(pipeline); - auto appBarTheme = pipeline->GetTheme(); - info.SetResourceId(image, appBarTheme->GetTextColor()); + margin.left = CalcLength(theme->GetIconInsideMargin()); + margin.right = CalcLength(theme->GetIconOutsideMargin()); } - icon->GetLayoutProperty()->UpdateImageSourceInfo(info); + icon->GetLayoutProperty()->UpdateMargin(margin); + icon->MarkModifyDone(); icon->MarkDirtyNode(); } diff --git a/frameworks/core/components_ng/pattern/app_bar/atomic_service_pattern.h b/frameworks/core/components_ng/pattern/app_bar/atomic_service_pattern.h index 77ec2c06ac2..f139d52aa31 100644 --- a/frameworks/core/components_ng/pattern/app_bar/atomic_service_pattern.h +++ b/frameworks/core/components_ng/pattern/app_bar/atomic_service_pattern.h @@ -23,6 +23,7 @@ namespace OHOS::Ace::NG { class AtomicServicePattern : public LinearLayoutPattern { DECLARE_ACE_TYPE(AtomicServicePattern, LinearLayoutPattern); + ACE_DISALLOW_COPY_AND_MOVE(AtomicServicePattern); public: AtomicServicePattern() : LinearLayoutPattern(true) {}; @@ -43,10 +44,13 @@ public: RefPtr GetMenuIcon(); RefPtr GetCloseIcon(); void UpdateColor(); - void UpdateRowLayout(); - void SetEachIconColor( - RefPtr icon, const std::optional& color, InternalResource::ResourceId image); - ACE_DISALLOW_COPY_AND_MOVE(AtomicServicePattern); + void UpdateMenuBarColor(RefPtr& theme, RefPtr& menuBar); + void UpdateButtonColor(RefPtr& theme, RefPtr& button); + void UpdateIconColor(RefPtr& theme, RefPtr& icon); + void UpdateLayout(); + void UpdateMenuBarLayout(RefPtr& theme, RefPtr& menuBar, bool isRtl); + void UpdateButtonLayout(RefPtr& theme, RefPtr& button, bool isLeft); + void UpdateIconLayout(RefPtr& theme, RefPtr& icon, bool isLeft); }; } // namespace OHOS::Ace::NG #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_ATOMIC_SERVICE_PATTERN_H -- Gitee