diff --git a/frameworks/core/components/select/select_theme.h b/frameworks/core/components/select/select_theme.h index 31afffd19095d51666c28f2d67df90f9c550a049..5a6b0dbc1789878ef5ae09961ebc62d542983019 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; @@ -140,7 +141,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); @@ -215,6 +217,13 @@ public: theme->selectSpinnerWidthMap_.insert(std::pair( ControlSize::SMALL, pattern->GetAttr("small_spinner_width", 0.0_vp))); } + theme->selectTextSpinnerSpace_ = pattern->GetAttr("text_spinner_space", 8.0_vp); + if (Container::GreatOrEqualAPITargetVersion(PlatformVersion::VERSION_TWELVE)) { + theme->selectTextSpinnerSpaceMap_.insert( + std::pair(ControlSize::NORMAL, theme->selectTextSpinnerSpace_)); + theme->selectTextSpinnerSpaceMap_.insert(std::pair( + ControlSize::SMALL, pattern->GetAttr("small_text_spinner_space", 8.0_vp))); + } } void ParsePartTwo(const RefPtr& theme, const RefPtr& pattern) const @@ -303,7 +312,24 @@ public: theme->optionNormalWidth_ = pattern->GetAttr("option_normal_width", 156.0_vp); theme->selectedFontSizeText = pattern->GetAttr("select_font_size_text", 16.0_fp); theme->selectNormalLeftRightMargin_ = - pattern->GetAttr("select_normal_left_right_margin", 8.0_vp); + pattern->GetAttr("select_normal_left_right_margin", 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->menuBlendBgColor_ = pattern->GetAttr("menu_is_blend_bg_color", 0); theme->optionFocusedBoxPadding_ = pattern->GetAttr("option_focused_box_padding", 0.0_vp); @@ -455,6 +481,7 @@ public: theme->optionMinHeight_ = optionMinHeight_; theme->tvFocusTextColor_ = tvFocusTextColor_; theme->tvNormalBackColor_ = tvNormalBackColor_; + theme->selectTextSpinnerSpace_ = selectTextSpinnerSpace_; } void ClonePartTwo(RefPtr& theme) @@ -563,6 +590,8 @@ public: theme->optionNormalWidth_ = optionNormalWidth_; theme->selectedFontSizeText = selectedFontSizeText; theme->selectNormalLeftRightMargin_ = selectNormalLeftRightMargin_; + theme->selectLeftMargin_ = selectLeftMargin_; + theme->selectRightMargin_ = selectRightMargin_; theme->menuBlendBgColor_ = menuBlendBgColor_; theme->optionFocusedBoxPadding_ = optionFocusedBoxPadding_; theme->spinnerFocusedSymbolColor_ = spinnerFocusedSymbolColor_; @@ -1128,6 +1157,17 @@ public: return menuAnimationOffset_; } + const Dimension& GetTextSpinnerSpace(ControlSize controlSize) const + { + if (Container::GreatOrEqualAPITargetVersion(PlatformVersion::VERSION_TWELVE)) { + auto result = selectTextSpinnerSpaceMap_.find(controlSize); + if (result != selectTextSpinnerSpaceMap_.end()) { + return result->second; + } + } + return selectTextSpinnerSpace_; + } + const Dimension& GetSpinnerWidth() const { return spinnerWidth_; @@ -1441,6 +1481,28 @@ public: return selectNormalLeftRightMargin_; } + 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_; + } + bool GetMenuBlendBgColor() const { return menuBlendBgColor_; @@ -1673,6 +1735,10 @@ private: std::unordered_map selectSpinnerWidthMap_; std::unordered_map selectSpinnerHeightMap_; std::unordered_map selectFontSizeMap_; + std::unordered_map selectLeftMarginMap_; + std::unordered_map selectRightMarginMap_; + std::unordered_map selectTextSpinnerSpaceMap_; + Dimension selectTextSpinnerSpace_; Dimension menuLargeMargin_; Dimension menuMediumMargin_; Dimension menuItemChildMinHeight_; @@ -1709,6 +1775,8 @@ private: Dimension optionNormalWidth_; Dimension selectedFontSizeText; Dimension selectNormalLeftRightMargin_ = 8.0_vp; + Dimension selectLeftMargin_ = 8.0_vp; + Dimension selectRightMargin_ = 8.0_vp; bool menuBlendBgColor_ = false; Dimension optionFocusedBoxPadding_ = 0.0_vp; Color spinnerFocusedSymbolColor_ = Color(0xff182431); diff --git a/frameworks/core/components_ng/pattern/select/select_layout_algorithm.cpp b/frameworks/core/components_ng/pattern/select/select_layout_algorithm.cpp index 88e8d5a79359a73d9a173cba22840f4eeab6576b..2bb46471b36e57e5517eff7839286fe7f1c9b846 100644 --- a/frameworks/core/components_ng/pattern/select/select_layout_algorithm.cpp +++ b/frameworks/core/components_ng/pattern/select/select_layout_algorithm.cpp @@ -22,7 +22,6 @@ namespace OHOS::Ace::NG { namespace { -constexpr float MIN_SPACE = 8.0f; constexpr float MIN_CHAR_VAL = 2.0f; constexpr float SMALL_MIN_CHAR_VAL = 1.0f; } // namespace @@ -39,17 +38,19 @@ void SelectLayoutAlgorithm::Measure(LayoutWrapper* layoutWrapper) auto rowProps = DynamicCast(rowWrapper->GetLayoutProperty()); CHECK_NULL_VOID(rowProps); auto space = static_cast(rowProps->GetSpaceValue(Dimension()).ConvertToPx()); - auto minSpace = Dimension(MIN_SPACE, DimensionUnit::VP); - if (space < minSpace.ConvertToPx()) { - space = minSpace.ConvertToPx(); - rowProps->UpdateSpace(minSpace); - } auto host = layoutProps->GetHost(); CHECK_NULL_VOID(host); auto pipeline = host->GetContext(); CHECK_NULL_VOID(pipeline); auto theme = pipeline->GetTheme(); CHECK_NULL_VOID(theme); + auto pattern = host->GetPattern(); + CHECK_NULL_VOID(pattern); + auto minSpace = theme->GetTextSpinnerSpace(pattern->GetControlSize()); + if (space < minSpace.ConvertToPx()) { + space = minSpace.ConvertToPx(); + rowProps->UpdateSpace(minSpace); + } UpdateMargin(layoutWrapper, theme); auto spinnerSize = MeasureAndGetSize(rowWrapper->GetOrCreateChildByIndex(1), childConstraint); childConstraint.maxSize.MinusWidth(spinnerSize.Width() + space); 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 fdb2f49f28e85910d66ea01cc88b6c9e32886074..40b717ec07d08029590b4718a879c1ca1a071b8c 100644 --- a/frameworks/core/components_ng/pattern/select/select_model_ng.cpp +++ b/frameworks/core/components_ng/pattern/select/select_model_ng.cpp @@ -787,8 +787,8 @@ void SelectModelNG::InitSelect(FrameNode* frameNode, const std::vectorGetSelectLeftRightMargin()); - paddings.right = NG::CalcLength(pattern->GetSelectLeftRightMargin()); + paddings.left = NG::CalcLength(pattern->GetSelectLeftMargin(pattern->GetControlSize())); + paddings.right = NG::CalcLength(pattern->GetSelectRightMargin(pattern->GetControlSize())); 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 fab52da26c295d0b365b6a8160df379b8c23826f..04ff2843cfcec7669645ac13cf40909b1e0d1994 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; @@ -2206,11 +2204,11 @@ void SelectPattern::ResetParams() 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 +2249,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 +2268,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 254c1c2cc8bc06473d7511e2f3b86e9c76e5548a..b409e2bef000c05d686f8491f21a6f615ef082dd 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 {