1 /* 2 * Copyright (c) 2022-2023 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_GAUGE_GAUGE_LAYOUT_ALGORITHM_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_GAUGE_GAUGE_LAYOUT_ALGORITHM_H 18 19 #include "core/components_ng/image_provider/image_loading_context.h" 20 #include "core/components_ng/layout/box_layout_algorithm.h" 21 namespace OHOS::Ace::NG { 22 class ACE_EXPORT GaugeLayoutAlgorithm : public BoxLayoutAlgorithm { 23 DECLARE_ACE_TYPE(GaugeLayoutAlgorithm, BoxLayoutAlgorithm); 24 25 public: 26 GaugeLayoutAlgorithm(); GaugeLayoutAlgorithm(const RefPtr<ImageLoadingContext> & indicatorIconLoadingCtx)27 explicit GaugeLayoutAlgorithm(const RefPtr<ImageLoadingContext>& indicatorIconLoadingCtx) 28 : indicatorIconLoadingCtx_(indicatorIconLoadingCtx) 29 {} 30 31 ~GaugeLayoutAlgorithm() override = default; 32 33 void OnReset() override; 34 35 void Measure(LayoutWrapper* layoutWrapper) override; 36 void Layout(LayoutWrapper* layoutWrapper) override; 37 38 std::optional<SizeF> MeasureContent( 39 const LayoutConstraintF& contentConstraint, LayoutWrapper* layoutWrapper) override; 40 41 private: 42 void MeasureLimitValueText(LayoutWrapper* layoutWrapper, const SizeF& parentSize, bool isMin); 43 void MeasureDescription(LayoutWrapper* layoutWrapper, const SizeF& parentSize); 44 void MeasureTitleChild(LayoutWrapper* layoutWrapper, const SizeF& parentSize); 45 bool CheckDescriptionIsImageNode(const RefPtr<LayoutWrapper>& layoutWrapper) const; 46 void MeasureLimitValueTextWidth(LayoutWrapper* layoutWrapper); 47 bool GetLimitFontSize(LayoutWrapper* layoutWrapper, bool isMin, Dimension& fontSize); 48 void SetLimitFontSize(LayoutWrapper* layoutWrapper, bool isMin, const Dimension& fontSize); 49 void MeasureFontSize(LayoutWrapper* layoutWrapper); 50 RefPtr<ImageLoadingContext> indicatorIconLoadingCtx_; 51 double limitValueTextWidth_ = 0.0; 52 double startAngleOffsetX_ = 0.0; 53 double endAngleOffsetX_ = 0.0; 54 ACE_DISALLOW_COPY_AND_MOVE(GaugeLayoutAlgorithm); 55 }; 56 57 } // namespace OHOS::Ace::NG 58 59 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_GAUGE_GAUGE_LAYOUT_ALGORITHM_H