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_RENDER_DIVIDER_PAINTER_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_RENDER_DIVIDER_PAINTER_H
18 
19 #include <optional>
20 
21 #include "base/geometry/ng/point_t.h"
22 #include "core/components/common/layout/constants.h"
23 #include "core/components/common/properties/color.h"
24 #include "core/components_ng/render/drawing.h"
25 
26 namespace OHOS::Ace::NG {
27 class DividerPainter {
28 public:
DividerPainter(float constrainStrokeWidth,float dividerLength,bool vertical,std::optional<Color> dividerColor,std::optional<LineCap> lineCap)29     DividerPainter(float constrainStrokeWidth, float dividerLength, bool vertical, std::optional<Color> dividerColor,
30         std::optional<LineCap> lineCap)
31         : constrainStrokeWidth_(constrainStrokeWidth), dividerLength_(dividerLength), vertical_(vertical),
32           dividerColor_(dividerColor), lineCap_(lineCap)
33     {}
DividerPainter(float constrainStrokeWidth,float dividerLength,bool vertical)34     DividerPainter(float constrainStrokeWidth, float dividerLength, bool vertical)
35         : constrainStrokeWidth_(constrainStrokeWidth), dividerLength_(dividerLength), vertical_(vertical),
36           dividerColor_(std::nullopt), lineCap_(LineCap::SQUARE)
37     {}
DividerPainter(float constrainStrokeWidth,float dividerLength)38     DividerPainter(float constrainStrokeWidth, float dividerLength)
39         : constrainStrokeWidth_(constrainStrokeWidth), dividerLength_(dividerLength), vertical_(false),
40           dividerColor_(std::nullopt), lineCap_(LineCap::SQUARE)
41     {}
42     ~DividerPainter() = default;
43 
44     void DrawLine(RSCanvas& canvas, const OffsetF& offset) const;
45 
SetDividerLength(float length)46     void SetDividerLength(float length)
47     {
48         dividerLength_ = length;
49     }
50 
51 private:
52     float constrainStrokeWidth_ = 0.0f;
53     float dividerLength_ = 0.0f;
54     bool vertical_ = false;
55 
56     std::optional<Color> dividerColor_;
57     std::optional<LineCap> lineCap_;
58 };
59 } // namespace OHOS::Ace::NG
60 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_RENDER_DIVIDER_PAINTER_H