1 /* 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_TIME_PICKER_TIME_PICKER_COLUMN_LAYOUT_ALGORITHM_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_TIME_PICKER_TIME_PICKER_COLUMN_LAYOUT_ALGORITHM_H 18 19 #include "base/i18n/localization.h" 20 #include "core/components/picker/picker_theme.h" 21 #include "core/components_ng/base/ui_node.h" 22 #include "core/components_ng/layout/layout_wrapper.h" 23 #include "core/components_ng/pattern/linear_layout/linear_layout_algorithm.h" 24 25 namespace OHOS::Ace::NG { 26 27 class ACE_EXPORT TimePickerColumnLayoutAlgorithm : public LinearLayoutAlgorithm { 28 DECLARE_ACE_TYPE(TimePickerColumnLayoutAlgorithm, LinearLayoutAlgorithm); 29 30 public: 31 TimePickerColumnLayoutAlgorithm() = default; 32 ~TimePickerColumnLayoutAlgorithm() override = default; 33 OnReset()34 void OnReset() override {} 35 36 void Measure(LayoutWrapper* layoutWrapper) override; 37 void Layout(LayoutWrapper* layoutWrapper) override; 38 void MeasureText(LayoutWrapper* layoutWrapper, const SizeF& size); 39 void ChangeAmPmTextStyle(uint32_t index, uint32_t showOptionCount, const SizeF& size, 40 const RefPtr<LayoutWrapper>& childLayoutWrapper, LayoutWrapper* layoutWrapper); 41 SetHour24(bool value)42 void SetHour24(bool value) 43 { 44 hour24_ = value; 45 } 46 GetHour24()47 bool GetHour24() const 48 { 49 return hour24_; 50 } GetCurrentOffset()51 std::vector<int32_t> GetCurrentOffset() const 52 { 53 return currentOffset_; 54 } 55 SetCurrentOffset(const std::vector<int32_t> & currentOffset)56 void SetCurrentOffset(const std::vector<int32_t>& currentOffset) 57 { 58 currentOffset_ = currentOffset; 59 } 60 61 private: 62 const Dimension AdjustFontSizeScale(const Dimension& fontSizeValue, double fontScale); 63 bool NeedAdaptForAging(); 64 float ReCalcItemHeightScale(const Dimension& userSetHeight, bool isDividerSpacing = true); 65 bool hour24_ = SystemProperties::Is24HourClock(); 66 void InitGradient(const float& gradientPercent, const RefPtr<FrameNode> blendNode, 67 const RefPtr<FrameNode> columnNode); 68 float GetPickerMaxHeight( 69 const std::optional<LayoutConstraintF>& layoutConstraint, const RefPtr<FrameNode>& pickerNode); 70 void MeasureText(LayoutWrapper* layoutWrapper, const RefPtr<PickerTheme>& pickerTheme, const SizeF& size); 71 72 float pickerItemHeight_ = 0.0f; 73 float dividerSpacingFontScale_ = 1.0f; 74 float gradientFontScale_ = 1.0f; 75 std::vector<int32_t> currentOffset_; 76 77 ACE_DISALLOW_COPY_AND_MOVE(TimePickerColumnLayoutAlgorithm); 78 }; 79 } // namespace OHOS::Ace::NG 80 81 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_TIME_PICKER_TIME_PICKER_COLUMN_LAYOUT_ALGORITHM_H 82