From ff285d2c146fedb250cfe5118cc35ed653c2decb Mon Sep 17 00:00:00 2001 From: zhanghang Date: Wed, 10 Sep 2025 16:12:42 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90select=E4=B8=8B=E6=8B=89=E8=8F=9C?= =?UTF-8?q?=E5=8D=95=E3=80=91=E9=BB=98=E8=AE=A4=E6=A0=B7=E5=BC=8F=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E6=94=AF=E6=8C=81=E4=BA=A7=E5=93=81=E5=B7=AE=E5=BC=82?= =?UTF-8?q?=E5=8C=96=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhanghang --- .../core/components/select/select_theme.h | 131 +++++++++++++++++- .../pattern/menu/menu_layout_algorithm.cpp | 6 +- .../pattern/menu/menu_layout_algorithm.h | 2 + .../pattern/select/select_model_ng.cpp | 4 +- .../pattern/select/select_pattern.cpp | 56 ++++++-- .../pattern/select/select_pattern.h | 3 +- 6 files changed, 181 insertions(+), 21 deletions(-) diff --git a/frameworks/core/components/select/select_theme.h b/frameworks/core/components/select/select_theme.h index 9dc320c16ea..78e467c4a78 100644 --- a/frameworks/core/components/select/select_theme.h +++ b/frameworks/core/components/select/select_theme.h @@ -47,6 +47,7 @@ constexpr double TITLE_RIGHT_PADDING = 8.0; constexpr double TITLE_BOTTOM_PADDING = 16.0; constexpr double SELECT_OPTION_INTERVAL = 6.0; constexpr FontWeight SELECT_MENU_CHECK_MARK_FONT_WEIGHT = FontWeight::REGULAR; +constexpr FontWeight SELECT_FONT_WEIGHT = FontWeight::NORMAL; constexpr Dimension SELECT_MENU_CHECK_MARK_FONT_SIZE = 24.0_vp; constexpr uint32_t SELECT_MENU_CHECK_MARK_DEFAULT_COLOR = 0xFF182431; @@ -122,6 +123,7 @@ public: ParsePartTwo(theme, pattern); ParsePartThree(theme, pattern); ParsePartFourth(theme, pattern); + ParsePartFifth(theme, pattern); } void ParseNewPattern(const RefPtr& themeConstants, const RefPtr& theme) const @@ -140,7 +142,8 @@ public: theme->fontFamily_ = "sans-serif"; theme->fontSize_ = pattern->GetAttr("text_font_size", 16.0_fp); theme->fontColor_ = pattern->GetAttr("select_font_color", Color(0xe5000000)); - theme->fontWeight_ = FontWeight::NORMAL; + theme->fontWeight_ = FontWeight(static_cast(pattern->GetAttr( + "select_font_weight", static_cast(SELECT_FONT_WEIGHT)))); theme->textDecoration_ = TextDecoration::NONE; auto optionSize = pattern->GetAttr("select_option_show_count", INT32_MAX); theme->optionSize_ = optionSize < 0 ? theme->optionSize_ : static_cast(optionSize); @@ -203,8 +206,6 @@ public: theme->defaultPaddingTop_ = pattern->GetAttr("default_padding_top", theme->defaultPaddingTop_); theme->defaultPaddingBottomFixed_ = pattern->GetAttr("default_padding_bottom_fixed", theme->defaultPaddingBottomFixed_); - theme->contentSpinnerPadding_ = - pattern->GetAttr("content_spinner_padding", theme->contentSpinnerPadding_); theme->menuAnimationOffset_ = pattern->GetAttr("menu_animation_offset", theme->menuAnimationOffset_); theme->spinnerWidth_ = pattern->GetAttr("spinner_width", theme->spinnerWidth_); @@ -352,6 +353,45 @@ public: pattern->GetAttr("select_check_mark_color", Color(SELECT_MENU_CHECK_MARK_DEFAULT_COLOR)); } + void ParsePartFifth(const RefPtr& theme, const RefPtr& pattern) const + { + theme->spinnerSymbolSize_ = pattern->GetAttr("select_spinner_symbol_size", 16.0_fp); + if (Container::GreatOrEqualAPITargetVersion(PlatformVersion::VERSION_TWELVE)) { + theme->selectSpinnerSymbolSizeMap_.insert( + std::pair(ControlSize::NORMAL, theme->spinnerSymbolSize_)); + theme->selectSpinnerSymbolSizeMap_.insert(std::pair( + ControlSize::SMALL, pattern->GetAttr("select_small_spinner_symbol_size", 14.0_fp))); + } + theme->disabledBackgroundColorAlpha_ = + pattern->GetAttr("select_disabled_background_color_alpha", 1.0); + theme->contentSpinnerPadding_ = + pattern->GetAttr("content_spinner_padding", theme->contentSpinnerPadding_); + if (Container::GreatOrEqualAPITargetVersion(PlatformVersion::VERSION_TWELVE)) { + theme->selectContentSpinnerPaddingMap_.insert( + std::pair(ControlSize::NORMAL, theme->contentSpinnerPadding_)); + theme->selectContentSpinnerPaddingMap_.insert(std::pair( + ControlSize::SMALL, pattern->GetAttr("small_content_spinner_padding", 8.0_vp))); + } + theme->selectLeftMargin_ = + pattern->GetAttr("select_normal_left_margin", 8.0_vp); + if (Container::GreatOrEqualAPITargetVersion(PlatformVersion::VERSION_TWELVE)) { + theme->selectLeftMarginMap_.insert( + std::pair(ControlSize::NORMAL, theme->selectLeftMargin_)); + theme->selectLeftMarginMap_.insert(std::pair( + ControlSize::SMALL, pattern->GetAttr("select_small_left_margin", 4.0_vp))); + } + theme->selectRightMargin_ = + pattern->GetAttr("select_normal_right_margin", 8.0_vp); + if (Container::GreatOrEqualAPITargetVersion(PlatformVersion::VERSION_TWELVE)) { + theme->selectRightMarginMap_.insert( + std::pair(ControlSize::NORMAL, theme->selectRightMargin_)); + theme->selectRightMarginMap_.insert(std::pair( + ControlSize::SMALL, pattern->GetAttr("select_small_right_margin", 4.0_vp))); + } + theme->selectMenuAdditionX_ = pattern->GetAttr("select_menu_addition_x", 0.0_vp); + theme->selectMenuAdditionY_ = pattern->GetAttr("select_menu_addition_y", 0.0_vp); + } + void ParseAttribute(const RefPtr& theme, const RefPtr& pattern) const { theme->titleLeftPadding_ = Dimension(TITLE_LEFT_PADDING, DimensionUnit::VP); @@ -382,7 +422,7 @@ public: theme->optionTextStyle_.SetFontSize(pattern->GetAttr("text_font_size", 16.0_fp)); theme->optionTextStyle_.SetFontFamilies({ pattern->GetAttr("text_font_family_regular", "sans-serif") }); - theme->optionTextStyle_.SetFontWeight(FontWeight::NORMAL); + theme->optionTextStyle_.SetFontWeight(theme->isTV_ ? FontWeight::MEDIUM : FontWeight::NORMAL); theme->optionTextStyle_.SetTextColor(pattern->GetAttr("select_font_color", Color(0xe5000000))); theme->optionTextStyle_.SetTextDecoration(TextDecoration::NONE); theme->menuLargeMargin_ = pattern->GetAttr("menu_large_margin", theme->menuLargeMargin_); @@ -540,6 +580,12 @@ public: theme->menuItemHorIntervalPadding_ = menuItemHorIntervalPadding_; theme->menuPadding_ = menuPadding_; theme->menuWordBreak_ = menuWordBreak_; + theme->selectLeftMargin_ = selectLeftMargin_; + theme->selectRightMargin_ = selectRightMargin_; + theme->disabledBackgroundColorAlpha_ = disabledBackgroundColorAlpha_; + theme->spinnerSymbolSize_ = spinnerSymbolSize_; + theme->selectMenuAdditionX_ = selectMenuAdditionX_; + theme->selectMenuAdditionY_ = selectMenuAdditionY_; } void CloneWideScreenAttrs(RefPtr& theme) @@ -1544,6 +1590,70 @@ public: { return menuAnimationScale_; } + + const Dimension& GetSelectLeftMargin(ControlSize controlSize) const + { + if (Container::GreatOrEqualAPITargetVersion(PlatformVersion::VERSION_TWELVE)) { + auto result = selectLeftMarginMap_.find(controlSize); + if (result != selectLeftMarginMap_.end()) { + return result->second; + } + } + return selectLeftMargin_; + } + + const Dimension& GetSelectRightMargin(ControlSize controlSize) const + { + if (Container::GreatOrEqualAPITargetVersion(PlatformVersion::VERSION_TWELVE)) { + auto result = selectRightMarginMap_.find(controlSize); + if (result != selectRightMarginMap_.end()) { + return result->second; + } + } + return selectRightMargin_; + } + + const Dimension& GetContentSpinnerPadding(ControlSize controlSize) const + { + if (Container::GreatOrEqualAPITargetVersion(PlatformVersion::VERSION_TWELVE)) { + auto result = selectContentSpinnerPaddingMap_.find(controlSize); + if (result != selectContentSpinnerPaddingMap_.end()) { + return result->second; + } + } + return contentSpinnerPadding_; + } + + const Dimension& GetSpinnerSymbolSize() const + { + return spinnerSymbolSize_; + } + + const Dimension& GetSpinnerSymbolSize(ControlSize controlSize) const + { + if (Container::GreatOrEqualAPITargetVersion(PlatformVersion::VERSION_TWELVE)) { + auto result = selectSpinnerSymbolSizeMap_.find(controlSize); + if (result != selectSpinnerSymbolSizeMap_.end()) { + return result->second; + } + } + return spinnerSymbolSize_; + } + + const Dimension& GetSelectMenuAdditionX() const + { + return selectMenuAdditionX_; + } + + const Dimension& GetSelectMenuAdditionY() const + { + return selectMenuAdditionY_; + } + + double GetDisabledBackgroundColorAlpha() const + { + return disabledBackgroundColorAlpha_; + } RefPtr GetMenuAnimationCurve() const { @@ -1581,6 +1691,18 @@ private: Color disabledMenuFontColor_; Color menuTitleFontColor_; + std::unordered_map selectLeftMarginMap_; + std::unordered_map selectRightMarginMap_; + std::unordered_map selectContentSpinnerPaddingMap_; + std::unordered_map selectSpinnerSymbolSizeMap_; + Dimension selectLeftMargin_ = 8.0_vp; + Dimension selectRightMargin_ = 8.0_vp; + Dimension contentSpinnerPadding_ = 8.0_vp; + Dimension spinnerSymbolSize_ = 16.0_fp; + Dimension selectMenuAdditionX_ = 0.0_vp; + Dimension selectMenuAdditionY_ = 0.0_vp; + double disabledBackgroundColorAlpha_ = 1.0; + bool allowScale_ = true; Dimension fontSize_; Color fontColor_; @@ -1630,7 +1752,6 @@ private: Dimension defaultPaddingEnd_; Dimension defaultPaddingTop_; Dimension defaultPaddingBottomFixed_; - Dimension contentSpinnerPadding_; Dimension menuAnimationOffset_; Dimension spinnerWidth_; Dimension spinnerHeight_; diff --git a/frameworks/core/components_ng/pattern/menu/menu_layout_algorithm.cpp b/frameworks/core/components_ng/pattern/menu/menu_layout_algorithm.cpp index f51c3edccaf..7caefddfb4c 100644 --- a/frameworks/core/components_ng/pattern/menu/menu_layout_algorithm.cpp +++ b/frameworks/core/components_ng/pattern/menu/menu_layout_algorithm.cpp @@ -719,6 +719,8 @@ void MenuLayoutAlgorithm::InitializePaddingAPI12(LayoutWrapper* layoutWrapper) margin_ = static_cast(theme->GetMenuPadding().ConvertToPx()); optionPadding_ = margin_; + selectMenuAdditionX_ = static_cast(theme->GetSelectMenuAdditionX().ConvertToPx()); + selectMenuAdditionY_ = static_cast(theme->GetSelectMenuAdditionY().ConvertToPx()); if (!canExpandCurrentWindow_) { paddingStart_ = static_cast(theme->GetMenuLargeMargin().ConvertToPx()); paddingEnd_ = static_cast(theme->GetMenuLargeMargin().ConvertToPx()); @@ -2727,7 +2729,7 @@ float MenuLayoutAlgorithm::VerticalLayout(const SizeF& size, float position, boo placement_ = Placement::BOTTOM; // can put menu below click point if (GreatOrEqual(bottomSpace_, size.Height())) { - return position + margin_; + return position + margin_ - selectMenuAdditionY_; } if (Container::GreatOrEqualAPIVersion(PlatformVersion::VERSION_ELEVEN) && isContextMenu) { if (LessNotEqual(bottomSpace_, size.Height()) && LessNotEqual(size.Height(), wrapperRect_.Height())) { @@ -2778,7 +2780,7 @@ float MenuLayoutAlgorithm::HorizontalLayout(const SizeF& size, float position, b float wrapperWidth = wrapperSize_.Width(); // can fit menu on the right side of position if (GreatOrEqual(rightSpace_, size.Width())) { - return position + margin_; + return position + margin_ - selectMenuAdditionX_; } // fit menu on the left side diff --git a/frameworks/core/components_ng/pattern/menu/menu_layout_algorithm.h b/frameworks/core/components_ng/pattern/menu/menu_layout_algorithm.h index aed164fee1a..82d84262340 100644 --- a/frameworks/core/components_ng/pattern/menu/menu_layout_algorithm.h +++ b/frameworks/core/components_ng/pattern/menu/menu_layout_algorithm.h @@ -335,6 +335,8 @@ private: float paddingTop_ = 0.0f; float paddingBottom_ = 0.0f; float optionPadding_ = 0.0f; + float selectMenuAdditionX_ = 0.0f; + float selectMenuAdditionY_ = 0.0f; float top_ = 0.0; float bottom_ = 0.0; float left_ = 0.0; diff --git a/frameworks/core/components_ng/pattern/select/select_model_ng.cpp b/frameworks/core/components_ng/pattern/select/select_model_ng.cpp index d20dc7179c5..69208572312 100644 --- a/frameworks/core/components_ng/pattern/select/select_model_ng.cpp +++ b/frameworks/core/components_ng/pattern/select/select_model_ng.cpp @@ -786,8 +786,8 @@ void SelectModelNG::InitSelect(FrameNode* frameNode, const std::vectorGetSelectLeftRightMargin()); - paddings.right = NG::CalcLength(pattern->GetSelectLeftRightMargin()); + paddings.left = NG::CalcLength(pattern->GetSelectLeftMargin(ControlSize::NORMAL)); + paddings.right = NG::CalcLength(pattern->GetSelectRightMargin(ControlSize::NORMAL)); ViewAbstract::SetPadding(frameNode, paddings); } diff --git a/frameworks/core/components_ng/pattern/select/select_pattern.cpp b/frameworks/core/components_ng/pattern/select/select_pattern.cpp index 0e18f6a28ee..4732111c03d 100644 --- a/frameworks/core/components_ng/pattern/select/select_pattern.cpp +++ b/frameworks/core/components_ng/pattern/select/select_pattern.cpp @@ -73,8 +73,6 @@ constexpr Dimension CALIBERATE_X = 4.0_vp; constexpr Dimension CALIBERATE_Y = 4.0_vp; -constexpr Dimension SELECT_SMALL_PADDING_VP = 4.0_vp; - constexpr Dimension SELECT_MARGIN_VP = 8.0_vp; constexpr uint32_t RENDERINGSTRATEGY_MULTIPLE_COLOR = 1; @@ -168,7 +166,17 @@ void SelectPattern::OnModifyDone() if (Container::LessThanAPITargetVersion(PlatformVersion::VERSION_TWELVE)) { renderContext->UpdateBackgroundColor(theme->GetBackgroundColor()); } else { - renderContext->UpdateBackgroundColor(theme->GetButtonBackgroundColor()); + if (!eventHub->IsEnabled()) { + renderContext->UpdateBackgroundColor( + theme->GetButtonBackgroundColor().BlendOpacity(theme->GetDisabledBackgroundColorAlpha())); + BorderColorProperty disabledBorderColorProperty; + const Color& disabledBorderColor = theme->GetSelectNormalBorderColor(); + disabledBorderColorProperty.SetColor( + disabledBorderColor.BlendOpacity(theme->GetDisabledBackgroundColorAlpha())); + renderContext->UpdateBorderColor(disabledBorderColorProperty); + } else { + renderContext->UpdateBackgroundColor(theme->GetButtonBackgroundColor()); + } } } @@ -1507,7 +1515,11 @@ void SelectPattern::InitSpinner( uint32_t symbolId = selectTheme->GetSpinnerSource(); spinnerLayoutProperty->UpdateSymbolSourceInfo(SymbolSourceInfo{symbolId}); spinnerLayoutProperty->UpdateSymbolColorList({selectTheme->GetSpinnerSymbolColor()}); - spinnerLayoutProperty->UpdateFontSize(selectTheme->GetFontSize()); + if (selectTheme->IsTV()) { + spinnerLayoutProperty->UpdateFontSize(selectTheme->GetSpinnerSymbolSize()); + } else { + spinnerLayoutProperty->UpdateFontSize(selectTheme->GetFontSize()); + } spinnerLayoutProperty->UpdateSymbolRenderingStrategy(RENDERINGSTRATEGY_MULTIPLE_COLOR); } @@ -2196,21 +2208,32 @@ void SelectPattern::ResetParams() SetFontSize(selectTheme->GetFontSize(controlSize_)); auto spinnerLayoutProperty = spinner_->GetLayoutProperty(); CHECK_NULL_VOID(spinnerLayoutProperty); - spinnerLayoutProperty->UpdateFontSize(selectTheme->GetFontSize(controlSize_)); + if (selectTheme->IsTV()) { + spinnerLayoutProperty->UpdateFontSize(selectTheme->GetSpinnerSymbolSize(controlSize_)); + } else { + spinnerLayoutProperty->UpdateFontSize(selectTheme->GetFontSize(controlSize_)); + } auto renderContext = select->GetRenderContext(); BorderRadiusProperty border; border.SetRadius(selectTheme->GetSelectDefaultBorderRadius(controlSize_)); renderContext->UpdateBorderRadius(border); + auto row = FrameNode::GetFrameNode(select->GetFirstChild()->GetTag(), select->GetFirstChild()->GetId()); + CHECK_NULL_VOID(row); + auto rowProps = row->GetLayoutProperty(); + CHECK_NULL_VOID(rowProps); + rowProps->UpdateSpace(selectTheme->GetContentSpinnerPadding(controlSize_)); + row->MarkModifyDone(); + row->MarkDirtyNode(); NG::PaddingProperty paddings; paddings.top = std::nullopt; paddings.bottom = std::nullopt; if (controlSize_ == ControlSize::SMALL) { - paddings.left = NG::CalcLength(SELECT_SMALL_PADDING_VP); - paddings.right = NG::CalcLength(SELECT_SMALL_PADDING_VP); + paddings.left = NG::CalcLength(selectTheme->GetSelectLeftMargin(ControlSize::SMALL)); + paddings.right = NG::CalcLength(selectTheme->GetSelectRightMargin(ControlSize::SMALL)); } else { - paddings.left = NG::CalcLength(selectTheme->GetSelectNormalLeftRightMargin()); - paddings.right = NG::CalcLength(selectTheme->GetSelectNormalLeftRightMargin()); + paddings.left = NG::CalcLength(selectTheme->GetSelectLeftMargin(ControlSize::NORMAL)); + paddings.right = NG::CalcLength(selectTheme->GetSelectRightMargin(ControlSize::NORMAL)); } ViewAbstract::SetPadding(paddings); } @@ -2251,7 +2274,18 @@ ControlSize SelectPattern::GetControlSize() return controlSize_; } -Dimension SelectPattern::GetSelectLeftRightMargin() const +Dimension SelectPattern::GetSelectLeftMargin(ControlSize controlSize) const +{ + auto host = GetHost(); + CHECK_NULL_RETURN(host, SELECT_MARGIN_VP); + auto pipeline = host->GetContext(); + CHECK_NULL_RETURN(pipeline, SELECT_MARGIN_VP); + auto selectTheme = pipeline->GetTheme(); + CHECK_NULL_RETURN(selectTheme, SELECT_MARGIN_VP); + return selectTheme->GetSelectLeftMargin(controlSize); +} + +Dimension SelectPattern::GetSelectRightMargin(ControlSize controlSize) const { auto host = GetHost(); CHECK_NULL_RETURN(host, SELECT_MARGIN_VP); @@ -2259,7 +2293,7 @@ Dimension SelectPattern::GetSelectLeftRightMargin() const CHECK_NULL_RETURN(pipeline, SELECT_MARGIN_VP); auto selectTheme = pipeline->GetTheme(); CHECK_NULL_RETURN(selectTheme, SELECT_MARGIN_VP); - return selectTheme->GetSelectNormalLeftRightMargin(); + return selectTheme->GetSelectRightMargin(controlSize); } bool SelectPattern::GetShadowFromTheme(ShadowStyle shadowStyle, Shadow& shadow) diff --git a/frameworks/core/components_ng/pattern/select/select_pattern.h b/frameworks/core/components_ng/pattern/select/select_pattern.h index 52927a9dbb3..a1212567760 100644 --- a/frameworks/core/components_ng/pattern/select/select_pattern.h +++ b/frameworks/core/components_ng/pattern/select/select_pattern.h @@ -226,7 +226,8 @@ public: void SetDividerMode(const std::optional& mode); ControlSize GetControlSize(); void SetLayoutDirection(TextDirection value); - Dimension GetSelectLeftRightMargin() const; + Dimension GetSelectLeftMargin(ControlSize controlSize) const; + Dimension GetSelectRightMargin(ControlSize controlSize) const; bool OnThemeScopeUpdate(int32_t themeScopeId) override; RefPtr CreatePaintProperty() override { -- Gitee