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