1 /*
2  * Copyright (c) 2021 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_STEPPER_STEPPER_COMPONENT_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_STEPPER_STEPPER_COMPONENT_H
18 
19 #include "core/components/stepper/stepper_item_component.h"
20 #include "core/components_v2/common/common_def.h"
21 #include "core/pipeline/base/component_group.h"
22 
23 namespace OHOS::Ace {
24 
25 using ChangeStatusFunc = std::function<void(const std::string&, const std::string&)>;
26 
27 class StepperController : public virtual AceType {
28     DECLARE_ACE_TYPE(StepperController, AceType);
29 
30 public:
SetRightButtonStatus(const std::string & status,const std::string & label)31     void SetRightButtonStatus(const std::string& status, const std::string& label)
32     {
33         if (setRightButtonStatusImpl_) {
34             setRightButtonStatusImpl_(status, label);
35         }
36     }
37 
SetRightButtonStatusImpl(const ChangeStatusFunc & setRightButtonStatusImpl)38     void SetRightButtonStatusImpl(const ChangeStatusFunc& setRightButtonStatusImpl)
39     {
40         setRightButtonStatusImpl_ = setRightButtonStatusImpl;
41     }
42 
43 private:
44     ChangeStatusFunc setRightButtonStatusImpl_;
45 };
46 
47 class ACE_EXPORT StepperComponent : public ComponentGroup {
48     DECLARE_ACE_TYPE(StepperComponent, ComponentGroup);
49 
50 public:
51     StepperComponent() = default;
52     explicit StepperComponent(const std::list<RefPtr<Component>>& children);
53     ~StepperComponent() override = default;
54 
55     RefPtr<Element> CreateElement() override;
56     RefPtr<RenderNode> CreateRenderNode() override;
57     void SetStepperLabels(const std::vector<StepperLabels>& stepperLabels);
58     const std::vector<StepperLabels>& GetStepperLabels() const;
59     void InsertChild(int32_t position, const RefPtr<Component>& child) override;
60     void AppendChild(const RefPtr<Component>& child) override;
61     void RemoveChild(const RefPtr<Component>& child) override;
62     std::list<RefPtr<StepperItemComponent>> CollectItems(const RefPtr<Component>& child);
63 
GetStepperController()64     RefPtr<StepperController> GetStepperController() const
65     {
66         return stepperController_;
67     }
68 
GetIndex()69     int32_t GetIndex() const
70     {
71         return index_;
72     }
73 
SetIndex(int32_t index)74     void SetIndex(int32_t index)
75     {
76         index_ = index;
77     }
78 
SetFinishEventId(const EventMarker & finishEventId)79     void SetFinishEventId(const EventMarker& finishEventId)
80     {
81         finishEventId_ = finishEventId;
82     }
83 
GetFinishEventId()84     const EventMarker& GetFinishEventId() const
85     {
86         return finishEventId_;
87     }
88 
SetSkipEventId(const EventMarker & skipEventId)89     void SetSkipEventId(const EventMarker& skipEventId)
90     {
91         skipEventId_ = skipEventId;
92     }
93 
GetSkipEventId()94     const EventMarker& GetSkipEventId() const
95     {
96         return skipEventId_;
97     }
98 
SetChangeEventId(const EventMarker & changeEventId)99     void SetChangeEventId(const EventMarker& changeEventId)
100     {
101         changeEventId_ = changeEventId;
102     }
103 
GetChangeEventId()104     const EventMarker& GetChangeEventId() const
105     {
106         return changeEventId_;
107     }
108 
SetNextEventId(const EventMarker & nextEventId)109     void SetNextEventId(const EventMarker& nextEventId)
110     {
111         nextEventId_ = nextEventId;
112     }
113 
GetNextEventId()114     const EventMarker& GetNextEventId() const
115     {
116         return nextEventId_;
117     }
118 
SetBackEventId(const EventMarker & backEventId)119     void SetBackEventId(const EventMarker& backEventId)
120     {
121         backEventId_ = backEventId;
122     }
123 
GetBackEventId()124     const EventMarker& GetBackEventId() const
125     {
126         return backEventId_;
127     }
128 
SetDefaultPaddingStart(const Dimension & defaultPaddingStart)129     void SetDefaultPaddingStart(const Dimension& defaultPaddingStart)
130     {
131         defaultPaddingStart_ = defaultPaddingStart;
132     }
133 
GetDefaultPaddingStart()134     const Dimension& GetDefaultPaddingStart() const
135     {
136         return defaultPaddingStart_;
137     }
138 
SetDefaultPaddingEnd(const Dimension & defaultPaddingEnd)139     void SetDefaultPaddingEnd(const Dimension& defaultPaddingEnd)
140     {
141         defaultPaddingEnd_ = defaultPaddingEnd;
142     }
143 
GetDefaultPaddingEnd()144     const Dimension& GetDefaultPaddingEnd() const
145     {
146         return defaultPaddingEnd_;
147     }
148 
SetProgressColor(const Color & progressColor)149     void SetProgressColor(const Color& progressColor)
150     {
151         progressColor_ = progressColor;
152     }
153 
GetProgressColor()154     const Color& GetProgressColor() const
155     {
156         return progressColor_;
157     }
158 
SetProgressDiameter(const Dimension & progressDiameter)159     void SetProgressDiameter(const Dimension& progressDiameter)
160     {
161         progressDiameter_ = progressDiameter;
162     }
163 
GetProgressDiameter()164     const Dimension& GetProgressDiameter() const
165     {
166         return progressDiameter_;
167     }
168 
SetArrowWidth(const Dimension & arrowWidth)169     void SetArrowWidth(const Dimension& arrowWidth)
170     {
171         arrowWidth_ = arrowWidth;
172     }
173 
GetArrowWidth()174     const Dimension& GetArrowWidth() const
175     {
176         return arrowWidth_;
177     }
178 
SetArrowHeight(const Dimension & arrowHeight)179     void SetArrowHeight(const Dimension& arrowHeight)
180     {
181         arrowHeight_ = arrowHeight;
182     }
183 
GetArrowHeight()184     const Dimension& GetArrowHeight() const
185     {
186         return arrowHeight_;
187     }
188 
SetArrowColor(const Color & arrowColor)189     void SetArrowColor(const Color& arrowColor)
190     {
191         arrowColor_ = arrowColor;
192     }
193 
GetArrowColor()194     const Color& GetArrowColor() const
195     {
196         return arrowColor_;
197     }
198 
SetDisabledColor(const Color & disabledColor)199     void SetDisabledColor(const Color& disabledColor)
200     {
201         disabledColor_ = disabledColor;
202     }
203 
GetDisabledColor()204     const Color& GetDisabledColor() const
205     {
206         return disabledColor_;
207     }
208 
SetRadius(const Dimension & radius)209     void SetRadius(const Dimension& radius)
210     {
211         radius_ = radius;
212     }
213 
GetRadius()214     const Dimension& GetRadius() const
215     {
216         return radius_;
217     }
218 
SetButtonPressedColor(const Color & buttonPressedColor)219     void SetButtonPressedColor(const Color& buttonPressedColor)
220     {
221         buttonPressedColor_ = buttonPressedColor;
222     }
223 
GetButtonPressedColor()224     const Color& GetButtonPressedColor() const
225     {
226         return buttonPressedColor_;
227     }
228 
SetButtonPressedHeight(const Dimension & buttonPressedHeight)229     void SetButtonPressedHeight(const Dimension& buttonPressedHeight)
230     {
231         buttonPressedHeight_ = buttonPressedHeight;
232     }
233 
GetButtonPressedHeight()234     const Dimension& GetButtonPressedHeight() const
235     {
236         return buttonPressedHeight_;
237     }
238 
SetControlHeight(const Dimension & controlHeight)239     void SetControlHeight(const Dimension& controlHeight)
240     {
241         controlHeight_ = controlHeight;
242     }
243 
GetControlHeight()244     const Dimension& GetControlHeight() const
245     {
246         return controlHeight_;
247     }
248 
SetControlMargin(const Dimension & controlMargin)249     void SetControlMargin(const Dimension& controlMargin)
250     {
251         controlMargin_ = controlMargin;
252     }
253 
GetControlMargin()254     const Dimension& GetControlMargin() const
255     {
256         return controlMargin_;
257     }
258 
SetControlPadding(const Dimension & controlPadding)259     void SetControlPadding(const Dimension& controlPadding)
260     {
261         controlPadding_ = controlPadding;
262     }
263 
GetControlPadding()264     const Dimension& GetControlPadding() const
265     {
266         return controlPadding_;
267     }
268 
SetFocusColor(const Color & focusColor)269     void SetFocusColor(const Color& focusColor)
270     {
271         focusColor_ = focusColor;
272     }
273 
GetFocusColor()274     const Color& GetFocusColor() const
275     {
276         return focusColor_;
277     }
278 
SetFocusBorderWidth(const Dimension & focusBorderWidth)279     void SetFocusBorderWidth(const Dimension& focusBorderWidth)
280     {
281         focusBorderWidth_ = focusBorderWidth;
282     }
283 
GetFocusBorderWidth()284     const Dimension& GetFocusBorderWidth() const
285     {
286         return focusBorderWidth_;
287     }
288 
SetMouseHoverColor(const Color & mouseHoverColor)289     void SetMouseHoverColor(const Color& mouseHoverColor)
290     {
291         mouseHoverColor_ = mouseHoverColor;
292     }
293 
GetMouseHoverColor()294     const Color& GetMouseHoverColor() const
295     {
296         return mouseHoverColor_;
297     }
298 
AppendLabel(const StepperLabels & label)299     void AppendLabel(const StepperLabels& label)
300     {
301         stepperLabels_.emplace_back(label);
302     }
303 
AppendTextStyle(const TextStyle & textStyle)304     void AppendTextStyle(const TextStyle& textStyle)
305     {
306         labelsTextStyles_.emplace_back(textStyle);
307     }
308 
GetLabelStyles()309     const std::vector<TextStyle>& GetLabelStyles() const
310     {
311         return labelsTextStyles_;
312     }
313 
SetDisabledAlpha(double disabledAlpha)314     void SetDisabledAlpha(double disabledAlpha)
315     {
316         disabledAlpha_ = disabledAlpha;
317     }
318 
GetDisabledAlpha()319     double GetDisabledAlpha() const
320     {
321         return disabledAlpha_;
322     }
323 
324     ACE_DEFINE_COMPONENT_EVENT(OnFinish, void());
325 
326     ACE_DEFINE_COMPONENT_EVENT(OnSkip, void());
327 
328     ACE_DEFINE_COMPONENT_EVENT(OnChange, void(int32_t, int32_t));
329 
330     ACE_DEFINE_COMPONENT_EVENT(OnNext, void(int32_t, int32_t));
331 
332     ACE_DEFINE_COMPONENT_EVENT(OnPrevious, void(int32_t, int32_t));
333 private:
334     std::vector<StepperLabels> stepperLabels_;
335     std::vector<TextStyle> labelsTextStyles_;
336     RefPtr<StepperController> stepperController_;
337     int32_t index_ = 0;
338     EventMarker finishEventId_;
339     EventMarker skipEventId_;
340     EventMarker changeEventId_;
341     EventMarker nextEventId_;
342     EventMarker backEventId_;
343     Dimension defaultPaddingStart_;
344     Dimension defaultPaddingEnd_;
345     Color progressColor_;
346     Dimension progressDiameter_;
347     Dimension arrowWidth_;
348     Dimension arrowHeight_;
349     Color arrowColor_;
350     Color disabledColor_;
351     Dimension radius_;
352     Color buttonPressedColor_;
353     Dimension buttonPressedHeight_;
354     Dimension controlHeight_;
355     Dimension controlMargin_;
356     Dimension controlPadding_;
357     Color focusColor_;
358     Dimension focusBorderWidth_;
359     Color mouseHoverColor_;
360     double disabledAlpha_ = 0.4;
361 };
362 
363 } // namespace OHOS::Ace
364 
365 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_STEPPER_STEPPER_COMPONENT_H
366