1  /*
2   * Copyright (c) 2020-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  /**
17   * @addtogroup UI_Components
18   * @{
19   *
20   * @brief Defines UI components such as buttons, texts, images, lists, and progress bars.
21   *
22   * @since 1.0
23   * @version 1.0
24   */
25  
26  /**
27   * @file ui_view.h
28   *
29   * @brief Declares the base class of a view, providing basic view attributes and operations. All views are derived
30   *        from this class.
31   *
32   * @since 1.0
33   * @version 1.0
34   */
35  
36  #ifndef GRAPHIC_LITE_UI_VIEW_H
37  #define GRAPHIC_LITE_UI_VIEW_H
38  
39  #include "events/cancel_event.h"
40  #include "events/click_event.h"
41  #include "events/drag_event.h"
42  #include "events/event.h"
43  #include "events/long_press_event.h"
44  #include "events/press_event.h"
45  #include "events/release_event.h"
46  #if ENABLE_ROTATE_INPUT
47  #include "events/rotate_event.h"
48  #endif
49  #include "gfx_utils/color.h"
50  #include "gfx_utils/geometry2d.h"
51  #include "gfx_utils/graphic_buffer.h"
52  #include "gfx_utils/graphic_log.h"
53  #include "gfx_utils/heap_base.h"
54  #include "gfx_utils/image_info.h"
55  #include "gfx_utils/style.h"
56  #include "gfx_utils/transform.h"
57  
58  namespace OHOS {
59  /* Enumerates view types. */
60  enum UIViewType : uint8_t {
61      UI_ROOT_VIEW = 0,
62      UI_VIEW_GROUP,
63      UI_LABEL,
64      UI_ARC_LABEL,
65      UI_EDIT_TEXT,
66      UI_LABEL_BUTTON,
67      UI_CHECK_BOX,
68      UI_TOGGLE_BUTTON,
69      UI_RADIO_BUTTON,
70      UI_IMAGE_VIEW,
71      UI_BOX_PROGRESS,
72      UI_SLIDER,
73      UI_CIRCLE_PROGRESS,
74      UI_SCROLL_VIEW,
75      UI_LIST,
76      UI_DIGITAL_CLOCK,
77      UI_ANALOG_CLOCK,
78      UI_PICKER,
79      UI_SWIPE_VIEW,
80      UI_TIME_PICKER,
81      UI_ABSTRACT_CLOCK,
82      UI_ABSTRACT_PROGRESS,
83      UI_ABSTRACT_SCROLL,
84      UI_AXIS,
85      UI_BUTTON,
86      UI_CANVAS,
87      UI_CHART,
88      UI_IMAGE_ANIMATOR_VIEW,
89      UI_REPEAT_BUTTON,
90      UI_TEXTURE_MAPPER,
91      UI_DIALOG,
92      UI_QRCODE,
93      UI_NUMBER_MAX
94  };
95  
96  #if ENABLE_DEBUG
97  const char* const VIEW_TYPE_STRING[UI_NUMBER_MAX] = {
98      "RootView",         "UIViewGroup",        "UILabel",          "UIArcLabel",
99      "UIEditText",       "UILabelButton",      "UICheckBox",       "UIToggleButton",
100      "UIRadioButton",    "UIImageView",        "UIBoxProgress",    "UISlider",
101      "UICircleProgress", "UIScrollView",       "UIList",           "UIDigitalClock",
102      "UIAnalogClock",    "UIPicker",           "UISwipeView",      "UITimePicker",
103      "UIAbstractClock",  "UIAbstractProgress", "UIAbstractScroll", "UIAxis",
104      "UIButton",         "UICanvas",           "UIChart",          "UIImageAnimatorView",
105      "UIRepeatButton",   "UITextureMapper",    "UIDialog",         "UIQrcode",
106  };
107  #endif // ENABLE_DEBUG
108  
109  /**
110   * @brief Defines the base class of a view, providing basic view attributes and operations. All views are derived
111   *        from this class.
112   *
113   * @since 1.0
114   * @version 1.0
115   */
116  class UIView : public HeapBase {
117  public:
118      /**
119       * @brief Defines a click event listener. You need to register this listener with the view to listen to
120       *        click events.
121       *
122       * @since 1.0
123       * @version 1.0
124       */
125      class OnClickListener : public HeapBase {
126      public:
127          /**
128           * @brief Called when a view is clicked.
129           * @param view Indicates the view clicked.
130           * @param event Indicates the click event.
131           * @return Returns <b>true</b> if the event is consumed; returns <b>false</b> otherwise.
132           *         (If an event is consumed, it is not transferred to the parent view. If an event is not consumed,
133           *         it is transferred to the parent view after local processing is complete.)
134           * @since 1.0
135           * @version 1.0
136           */
OnClick(UIView & view,const ClickEvent & event)137          virtual bool OnClick(UIView& view, const ClickEvent& event)
138          {
139              return false;
140          }
141  
142          /**
143           * @brief A destructor used to delete the <b>OnClickListener</b> instance.
144           * @since 1.0
145           * @version 1.0
146           */
~OnClickListener()147          virtual ~OnClickListener() {}
148      };
149  
150      /**
151       * @brief Defines a long-press event listener. You need to register this listener with the view to listen to
152       *        long-press events.
153       *
154       * @since 1.0
155       * @version 1.0
156       */
157      class OnLongPressListener : public HeapBase {
158      public:
159          /**
160           * @brief Called when a view is long pressed.
161           * @param view Indicates the view long pressed.
162           * @param event Indicates the long-press event.
163           * @return Returns <b>true</b> if the event is consumed; returns <b>false</b> otherwise.
164           *         (If an event is consumed, it is not transferred to the parent view. If an event is not consumed,
165           *         it is transferred to the parent view after local processing is complete.)
166           * @since 1.0
167           * @version 1.0
168           */
OnLongPress(UIView & view,const LongPressEvent & event)169          virtual bool OnLongPress(UIView& view, const LongPressEvent& event)
170          {
171              return false;
172          }
173  
174          /**
175           * @brief A destructor used to delete the <b>OnLongPressListener</b> instance.
176           * @since 1.0
177           * @version 1.0
178           */
~OnLongPressListener()179          virtual ~OnLongPressListener() {}
180      };
181  
182      /**
183       * @brief Defines a drag event listener. You need to register this listener with the view to listen to drag events.
184       *
185       * @since 1.0
186       * @version 1.0
187       */
188      class OnDragListener : public HeapBase {
189      public:
190          /**
191           * @brief Called when a view starts to drag.
192           * @param view Indicates the view dragged.
193           * @param event Indicates the drag event.
194           * @return Returns <b>true</b> if the event is consumed; returns <b>false</b> otherwise.
195           *         (If an event is consumed, it is not transferred to the parent view. If an event is not consumed,
196           *         it is transferred to the parent view after local processing is complete.)
197           * @since 1.0
198           * @version 1.0
199           */
OnDragStart(UIView & view,const DragEvent & event)200          virtual bool OnDragStart(UIView& view, const DragEvent& event)
201          {
202              return false;
203          }
204  
205          /**
206           * @brief Called when a view is being dragged.
207           * @param view Indicates the view dragged.
208           * @param event Indicates the drag event.
209           * @return Returns <b>true</b> if the event is consumed; returns <b>false</b> otherwise.
210           *         (If an event is consumed, it is not transferred to the parent view. If an event is not consumed,
211           *         it is transferred to the parent view after local processing is complete.)
212           * @since 1.0
213           * @version 1.0
214           */
OnDrag(UIView & view,const DragEvent & event)215          virtual bool OnDrag(UIView& view, const DragEvent& event)
216          {
217              return false;
218          }
219  
220          /**
221           * @brief Called when a view stops dragging.
222           * @param view Indicates the view dragged.
223           * @param event Indicates the drag event.
224           * @return Returns <b>true</b> if the event is consumed; returns <b>false</b> otherwise.
225           *         (If an event is consumed, it is not transferred to the parent view. If an event is not consumed,
226           *         it is transferred to the parent view after local processing is complete.)
227           * @since 1.0
228           * @version 1.0
229           */
OnDragEnd(UIView & view,const DragEvent & event)230          virtual bool OnDragEnd(UIView& view, const DragEvent& event)
231          {
232              return false;
233          }
234  
235          /**
236           * @brief A destructor used to delete the <b>OnDragListener</b> instance.
237           * @since 1.0
238           * @version 1.0
239           */
~OnDragListener()240          virtual ~OnDragListener() {}
241      };
242  
243      /**
244       * @brief Defines a touch event listener. You need to register this listener with the view to listen to touch
245       *        events.
246       *
247       * @since 1.0
248       * @version 1.0
249       */
250      class OnTouchListener : public HeapBase {
251      public:
252          /**
253           * @brief Called when a view is pressed.
254           * @param view Indicates the view pressed.
255           * @param event Indicates the press event.
256           * @return Returns <b>true</b> if the event is consumed; returns <b>false</b> otherwise.
257           *         (If an event is consumed, it is not transferred to the parent view. If an event is not consumed,
258           *         it is transferred to the parent view after local processing is complete.)
259           * @since 1.0
260           * @version 1.0
261           */
OnPress(UIView & view,const PressEvent & event)262          virtual bool OnPress(UIView& view, const PressEvent& event)
263          {
264              return false;
265          }
266  
267          /**
268           * @brief Called when a view is released.
269           * @param view Indicates the view released.
270           * @param event Indicates the release event.
271           * @return Returns <b>true</b> if the event is consumed; returns <b>false</b> otherwise.
272           *         (If an event is consumed, it is not transferred to the parent view. If an event is not consumed,
273           *         it is transferred to the parent view after local processing is complete.)
274           * @since 1.0
275           * @version 1.0
276           */
OnRelease(UIView & view,const ReleaseEvent & event)277          virtual bool OnRelease(UIView& view, const ReleaseEvent& event)
278          {
279              return false;
280          }
281  
282          /**
283           * @brief Called when a click event on a view is canceled.
284           * @param view Indicates the view on which a click event is canceled.
285           * @param event Indicates the cancel event.
286           * @return Returns <b>true</b> if the event is consumed; returns <b>false</b> otherwise.
287           *         (If an event is consumed, it is not transferred to the parent view. If an event is not consumed,
288           *         it is transferred to the parent view after local processing is complete.)
289           * @since 1.0
290           * @version 1.0
291           */
OnCancel(UIView & view,const CancelEvent & event)292          virtual bool OnCancel(UIView& view, const CancelEvent& event)
293          {
294              return false;
295          }
296  
297          /**
298           * @brief A destructor used to delete the <b>OnTouchListener</b> instance.
299           * @since 1.0
300           * @version 1.0
301           */
~OnTouchListener()302          virtual ~OnTouchListener() {}
303      };
304  
305  #if ENABLE_ROTATE_INPUT
306      /**
307       * @brief Defines a rotation event listener.
308       *        You need to register this listener with the view to listen for rotation events.
309       * @since 5.0
310       * @version 3.0
311       */
312      class OnRotateListener : public HeapBase {
313      public:
314          /**
315           * @brief Called when the view starts to rotate.
316           * @param view Indicates the view that responds to the rotation event.
317           * @param event Indicates the rotation event.
318           * @return Returns <b>true</b> if the rotation event is consumed; returns <b>false</b> otherwise.
319           * @since 6
320           */
OnRotateStart(UIView & view,const RotateEvent & event)321          virtual bool OnRotateStart(UIView& view, const RotateEvent& event)
322          {
323              return false;
324          }
325  
326          /**
327           * @brief Called when a rotation event occurs on a view.
328           * @param view Indicates the view that responds to the rotation event.
329           * @param event Indicates the rotation event.
330           * @return Returns <b>true</b> if the rotation event is consumed; returns <b>false</b> otherwise.
331           * @since 5.0
332           * @version 3.0
333           */
OnRotate(UIView & view,const RotateEvent & event)334          virtual bool OnRotate(UIView& view, const RotateEvent& event)
335          {
336              return false;
337          }
338  
339          /**
340           * @brief Called when the view stops rotating.
341           * @param view Indicates the view that responds to the rotation event.
342           * @param event Indicates the rotation event.
343           * @return Returns <b>true</b> if the rotation event is consumed; returns <b>false</b> otherwise.
344           * @since 6
345           */
OnRotateEnd(UIView & view,const RotateEvent & event)346          virtual bool OnRotateEnd(UIView& view, const RotateEvent& event)
347          {
348              return false;
349          }
350  
351          /**
352           * @brief A destructor used to delete an <b>OnRotateListener</b> instance.
353           * @since 5.0
354           * @version 3.0
355           */
~OnRotateListener()356          virtual ~OnRotateListener() {}
357      };
358  
359      /**
360       * @brief Called when the view starts to rotate.
361       * @param event Indicates the rotation event.
362       * @since 6
363       */
364      virtual bool OnRotateStartEvent(const RotateEvent& event);
365  
366      /**
367       * @brief Called when a rotation event occurs on the view.
368       * @param event Indicates the rotation event.
369       * @since 5.0
370       * @version 3.0
371       */
372      virtual bool OnRotateEvent(const RotateEvent& event);
373  
374      /**
375       * @brief Called when the view stops rotating.
376       * @param event Indicates the rotation event.
377       * @since 6
378       */
379      virtual bool OnRotateEndEvent(const RotateEvent& event);
380  
381      /**
382       * @brief Sets a rotation event listener for the view.
383       * @param onRotateListener Indicates the pointer to the rotation event listener to set.
384       * @since 5.0
385       * @version 3.0
386       */
387      void SetOnRotateListener(OnRotateListener* onRotateListener);
388  
389      /**
390       * @brief Obtains the rotation event listener for the view.
391       * @return Returns the rotation event listener.
392       * @since 5.0
393       * @version 3.0
394       */
GetOnRotateListener()395      OnRotateListener*& GetOnRotateListener()
396      {
397          return onRotateListener_;
398      }
399  #endif
400  
401      /**
402       * @brief Stores extra information about a <b>UIView</b> instance.
403       * @param elementPtr Indicates the void pointer to the extra information about the <b>UIView</b> instance.
404       * @since 5.0
405       * @version 3.0
406       */
407      struct ViewExtraMsg {
408          void* elementPtr;
409      };
410  
411      /**
412       * @brief A default constructor used to create an <b>UIView</b> instance.
413       * @since 1.0
414       * @version 1.0
415       */
416      UIView();
417  
418      /**
419       * @brief A constructor used to create an <b>UIView</b> instance.
420       * @param id Indicates the pointer to the view ID.
421       * @since 1.0
422       * @version 1.0
423       */
UIView(const char * id)424      explicit UIView(const char* id) : UIView()
425      {
426          id_ = id;
427      }
428  
429      /**
430       * @brief A destructor used to delete the <b>UIView</b> instance.
431       * @since 1.0
432       * @version 1.0
433       */
434      virtual ~UIView();
435  
436      /**
437       * @brief Called before a view is drawn. This function is used to check whether the invalidated area
438       *        can be fully cover by this view so as to optimize the drawing process.
439       * @param invalidatedArea Indicates the area to judge and returns the covered area when partly coverd.
440       * @return Returns <b>true</b> if the invalidated area is fully covered; returns <b>false</b> otherwise.
441       * @since 1.0
442       * @version 1.0
443       */
444      virtual bool OnPreDraw(Rect& invalidatedArea) const;
445  
446      /**
447       * @brief Called when a view is drawn.
448       * @param invalidatedArea Indicates the area to draw.
449       * @since 1.0
450       * @version 1.0
451       */
452      virtual void OnDraw(BufferInfo& gfxDstBuffer, const Rect& invalidatedArea);
453  
454      /**
455       * @brief Called after a view is drawn.
456       * @param invalidatedArea Indicates the area in which the view is drawn.
457       * @since 1.0
458       * @version 1.0
459       */
460      virtual void OnPostDraw(BufferInfo& gfxDstBuffer, const Rect& invalidatedArea);
461  
462      /**
463       * @brief Remeasures the view size.
464       * @since 1.0
465       * @version 1.0
466       */
ReMeasure()467      virtual void ReMeasure() {}
468  
469      /**
470       * @brief Refreshes the invalidated area of the view.
471       * @since 1.0
472       * @version 1.0
473       */
474      void Invalidate();
475  
476      /**
477       * @brief Refreshes a view in a specified invalidated area.
478       * @param invalidatedArea Indicates the area to refresh.
479       * @since 1.0
480       * @version 1.0
481       */
482      void InvalidateRect(const Rect& invalidatedArea, UIView* view = nullptr);
483  
484      /**
485       * @brief Called when the view is long pressed.
486       * @param event Indicates the long-press event.
487       * @return Returns <b>true</b> if the event is consumed; returns <b>false</b> otherwise.
488       *         (If an event is consumed, it is not transferred to the parent view. If an event is not consumed,
489       *         it is transferred to the parent view after local processing is complete.)
490       * @since 1.0
491       * @version 1.0
492       */
493      virtual bool OnLongPressEvent(const LongPressEvent& event);
494  
495      /**
496       * @brief Called when the view starts to drag.
497       * @param event Indicates the drag event.
498       * @return Returns <b>true</b> if the event is consumed; returns <b>false</b> otherwise.
499       *         (If an event is consumed, it is not transferred to the parent view. If an event is not consumed,
500       *         it is transferred to the parent view after local processing is complete.)
501       * @since 1.0
502       * @version 1.0
503       */
504      virtual bool OnDragStartEvent(const DragEvent& event);
505  
506      /**
507       * @brief Called when the view is being dragged.
508       * @param event Indicates the drag event.
509       * @return Returns <b>true</b> if the event is consumed; returns <b>false</b> otherwise.
510       *         (If an event is consumed, it is not transferred to the parent view. If an event is not consumed,
511       *         it is transferred to the parent view after local processing is complete.)
512       * @since 1.0
513       * @version 1.0
514       */
515      virtual bool OnDragEvent(const DragEvent& event);
516  
517      /**
518       * @brief Called when the view stops dragging.
519       * @param event Indicates the drag event.
520       * @return Returns <b>true</b> if the event is consumed; returns <b>false</b> otherwise.
521       *         (If an event is consumed, it is not transferred to the parent view. If an event is not consumed,
522       *         it is transferred to the parent view after local processing is complete.)
523       * @since 1.0
524       * @version 1.0
525       */
526      virtual bool OnDragEndEvent(const DragEvent& event);
527  
528      /**
529       * @brief Called when the view is clicked.
530       * @param event Indicates the click event.
531       * @return Returns <b>true</b> if the event is consumed; returns <b>false</b> otherwise.
532       *         (If an event is consumed, it is not transferred to the parent view. If an event is not consumed,
533       *         it is transferred to the parent view after local processing is complete.)
534       * @since 1.0
535       * @version 1.0
536       */
537      virtual bool OnClickEvent(const ClickEvent& event);
538  
539      /**
540       * @brief Called when the view is pressed.
541       * @param event Indicates the press event.
542       * @return Returns <b>true</b> if the event is consumed; returns <b>false</b> otherwise.
543       *         (If an event is consumed, it is not transferred to the parent view. If an event is not consumed,
544       *         it is transferred to the parent view after local processing is complete.)
545       * @since 1.0
546       * @version 1.0
547       */
548      virtual bool OnPressEvent(const PressEvent& event);
549  
550      /**
551       * @brief Called when the view is released.
552       * @param event Indicates the release event.
553       * @return Returns <b>true</b> if the event is consumed; returns <b>false</b> otherwise.
554       *         (If an event is consumed, it is not transferred to the parent view. If an event is not consumed,
555       *         it is transferred to the parent view after local processing is complete.)
556       * @since 1.0
557       * @version 1.0
558       */
559      virtual bool OnReleaseEvent(const ReleaseEvent& event);
560  
561      /**
562       * @brief Called when a click event on the view is canceled.
563       * @param event Indicates the cancel event.
564       * @return Returns <b>true</b> if the event is consumed; returns <b>false</b> otherwise.
565       *         (If an event is consumed, it is not transferred to the parent view. If an event is not consumed,
566       *         it is transferred to the parent view after local processing is complete.)
567       * @since 1.0
568       * @version 1.0
569       */
570      virtual bool OnCancelEvent(const CancelEvent& event);
571  
572      /**
573       * @brief Sets a drag event listener for the view.
574       * @param onDragListener Indicates the pointer to the drag event listener to set.
575       * @since 1.0
576       * @version 1.0
577       */
578      void SetOnDragListener(OnDragListener* onDragListener);
579  
580      /**
581       * @brief Obtains the drag event listener for the view.
582       * @return Returns the drag event listener.
583       * @since 1.0
584       * @version 1.0
585       */
586      OnDragListener*& GetOnDragListener();
587  
588      /**
589       * @brief Sets a click event listener for the view.
590       * @param onClickListener Indicates the pointer to the click event listener to set.
591       * @since 1.0
592       * @version 1.0
593       */
594      void SetOnClickListener(OnClickListener* onClickListener);
595  
596      /**
597       * @brief Obtains the click event listener for the view.
598       * @return Returns the click event listener.
599       * @since 1.0
600       * @version 1.0
601       */
602      OnClickListener*& GetOnClickListener();
603  
604      /**
605       * @brief Sets a long-press event listener for the view.
606       * @param onLongPressListener Indicates the pointer to the long-press event listener to set.
607       * @since 1.0
608       * @version 1.0
609       */
610      void SetOnLongPressListener(OnLongPressListener* onLongPressListener);
611  
612      /**
613       * @brief Obtains the long-press event listener for the view.
614       * @return Returns the long-press event listener.
615       * @since 1.0
616       * @version 1.0
617       */
618      OnLongPressListener*& GetOnLongPressListener();
619  
620      /**
621       * @brief Sets a touch event listener for the view.
622       * @param onTouchListener Indicates the pointer to the touch event listener to set.
623       * @since 1.0
624       * @version 1.0
625       */
626      void SetOnTouchListener(OnTouchListener* onTouchListener);
627  
628      /**
629       * @brief Obtains the touch event listener for the view.
630       * @return Returns the touch event listener.
631       * @since 1.0
632       * @version 1.0
633       */
634      OnTouchListener*& GetTouchListener();
635  
636      /**
637       * @brief Obtains the top-level view based on specified coordinates.
638       * @param point Indicates the coordinates to specify.
639       * @param last Indicates the double pointer to the view that contains the specified coordinates.
640       * @since 1.0
641       * @version 1.0
642       */
643      virtual void GetTargetView(const Point& point, UIView** last);
644  
645      /**
646       * @brief Obtains the current view and target view based on specified coordinates. The obtained current view must
647       *        include the specified coordinates and is a visible top view that can respond to touch events, and the
648       *        obtained target view must be the top view that includes the specified coordinates.
649       * @param point Indicates the specified coordinates.
650       * @param current Indicates the double pointer to the current view to obtain.
651       *        <b>nullptr</b> indicates that the target view fails to be obtained.
652       * @param target Indicates the double pointer to the target view to obtain.
653       *        <b>nullptr</b> indicates that the target view fails to be obtained.
654       * @since 5.0
655       * @version 3.0
656       */
657      virtual void GetTargetView(const Point& point, UIView** current, UIView** target);
658  
659      /**
660       * @brief Sets the parent view for the view.
661       * @param parent Indicates the pointer to the parent view to set.
662       * @since 1.0
663       * @version 1.0
664       */
665      void SetParent(UIView* parent);
666  
667      /**
668       * @brief Obtains the parent view of the view.
669       * @return Returns the pointer to the parent view.
670       * @since 1.0
671       * @version 1.0
672       */
673      UIView* GetParent() const;
674  
675      /**
676       * @brief Sets the next sibling view for the view.
677       * @param sibling Indicates the pointer to the next sibling view to set.
678       * @since 1.0
679       * @version 1.0
680       */
681      void SetNextSibling(UIView* sibling);
682  
683      /**
684       * @brief Obtains the next sibling view of the view.
685       * @return Returns the pointer to the next sibling view.
686       * @since 1.0
687       * @version 1.0
688       */
689      UIView* GetNextSibling() const;
690  
691      /**
692       * @brief Sets whether the view is visible.
693       * @param visible Specifies whether to set the view visible. Value <b>true</b> means to set the view visible,
694       *                and <b>false</b> means the opposite.
695       * @since 1.0
696       * @version 1.0
697       */
698      virtual void SetVisible(bool visible);
699  
700      /**
701       * @brief Checks whether the view is visible.
702       * @return Returns <b>true</b> if the view is visible; returns <b>false</b> otherwise.
703       * @since 1.0
704       * @version 1.0
705       */
706      bool IsVisible() const;
707  
708      /**
709       * @brief Sets whether the view is touchable.
710       * @param touchable Specifies whether to set the view touchable. Value <b>true</b> means to set the view touchable,
711       *                  and <b>false</b> means the opposite.
712       * @since 1.0
713       * @version 1.0
714       */
715      void SetTouchable(bool touch);
716  
717      /**
718       * @brief Checks whether the view is touchable.
719       * @return Returns <b>true</b> if the view is touchable; returns <b>false</b> otherwise.
720       * @since 1.0
721       * @version 1.0
722       */
723      bool IsTouchable() const;
724  
725      /**
726       * @brief Sets whether the view is draggable.
727       * @param draggable Specifies whether to set the view draggable. Value <b>true</b> means to set the view draggable,
728       *                  and <b>false</b> means the opposite.
729       * @since 1.0
730       * @version 1.0
731       */
732      void SetDraggable(bool draggable);
733  
734      /**
735       * @brief Checks whether the view is draggable.
736       * @return Returns <b>true</b> if the view is draggable; returns <b>false</b> otherwise.
737       * @since 1.0
738       * @version 1.0
739       */
740      bool IsDraggable() const;
741  
742      /**
743       * @brief Sets whether to transfer the drag event to the parent view for processing when the view is being dragged.
744       * @param dragParentInstead Specifies whether to transfer the event to the parent view for processing.
745       *                          Value <b>true</b> means to transfer the event to the parent view for processing,
746       *                          and <b>false</b> means the opposite.
747       * @since 1.0
748       * @version 1.0
749       */
750      void SetDragParentInstead(bool dragParentInstead);
751  
752      /**
753       * @brief Obtains whether the view transfers a drag event to the parent view for processing.
754       * @return Returns <b>true</b> if the view transfers the event to the parent view for processing;
755       *         returns <b>false</b> otherwise.
756       * @since 1.0
757       * @version 1.0
758       */
759      bool IsDragParentInstead() const;
760  
761      /**
762       * @brief Obtains the absolute rectangle area of the view. When the view has deformation such as rotation,
763       *        the rectangle area is the intersection set of the absolute rectangle area and deformation matrix.
764       * @return Returns the absolute rectangle area.
765       * @since 1.0
766       * @version 1.0
767       */
768      Rect GetRect() const;
769  
770      /**
771       * @brief Obtains the visible absolute rectangle area of the view.
772       * @return Returns the visible absolute rectangle area.
773       * @since 1.0
774       * @version 1.0
775       */
776      Rect GetVisibleRect() const;
777  
778      /**
779       * @brief Obtains the valid absolute rectangle area of the view. The valid area refers to the area where the view
780       *        can be displayed. Generally, the valid area is the same as the visible view area, but they may be
781       *        different in the grid layout.
782       * @return Returns the valid absolute rectangle area.
783       * @since 1.0
784       * @version 1.0
785       */
786      Rect GetMaskedRect() const;
787  
788      /**
789       * @brief Obtains the absolute rectangle area of the view.
790       * @return Returns the absolute rectangle area.
791       * @since 1.0
792       * @version 1.0
793       */
794      Rect GetOrigRect() const;
795  
796      /**
797       * @brief Obtains the content of the absolute rectangle area of the view. This area excludes padding.
798       * @return Returns the content of the absolute rectangle area.
799       * @since 1.0
800       * @version 1.0
801       */
802      virtual Rect GetContentRect();
803  
804      virtual Rect GetOrigContentRect();
805  
806      /**
807       * @brief Obtains the rectangular area of the view relative to the parent view, that is, the rectangular area
808       *        relative to the coordinates of the parent view.
809       * @return Returns the rectangle area relative to the parent view.
810       * @since 1.0
811       * @version 1.0
812       */
813      Rect GetRelativeRect() const;
814  
815      /**
816       * @brief Adjusts the size of the visible area. This operation may affect the final display size.
817       * @param x Indicates the new x-coordinate.
818       * @param y Indicates the new y-coordinate.
819       * @param width Indicates the new width.
820       * @param height Indicates the new height.
821       * @since 1.0
822       * @version 1.0
823       */
824      void ResizeVisibleArea(int16_t x, int16_t y, int16_t width, int16_t height);
825  
826      /**
827       * @brief Sets the width for the view.
828       * @param width Indicates the width to set.
829       * @since 1.0
830       * @version 1.0
831       */
832      virtual void SetWidth(int16_t width);
833  
834      /**
835       * @brief Sets a percentage that represents the proportion of the view's width to the parent view's width.
836       * @param widthPercent Indicates the percentage to set, the decimal form of which ranges from 0 to 1.
837       * @since 5.0
838       * @version 3.0
839       */
840      virtual void SetWidthPercent(float widthPercent);
841  
842      /**
843       * @brief Obtains the width for the view.
844       * @return Returns the view width.
845       * @since 1.0
846       * @version 1.0
847       */
848      virtual int16_t GetWidth();
849  
850      /**
851       * @brief Sets the height for the view.
852       * @param height Indicates the height to set.
853       * @since 1.0
854       * @version 1.0
855       */
856      virtual void SetHeight(int16_t height);
857  
858      /**
859       * @brief Sets a percentage that represents the proportion of the view's hieght to the parent view's hieght.
860       * @param widthPercent Indicates the percentage to set, the decimal form of which ranges from 0 to 1.
861       * @since 5.0
862       * @version 3.0
863       */
864      virtual void SetHeightPercent(float heightPercent);
865  
866      /**
867       * @brief Obtains the height for the view.
868       * @return Returns the view height.
869       * @since 1.0
870       * @version 1.0
871       */
872      virtual int16_t GetHeight();
873  
874      /**
875       * @brief Adjusts the size of the view.
876       * @param width Indicates the new width.
877       * @param height Indicates the new height.
878       * @since 1.0
879       * @version 1.0
880       */
881      virtual void Resize(int16_t width, int16_t height);
882  
883      /**
884       * @brief Adjusts the size of the view based on specified percentages.
885       * @param widthPercent Indicates the percentage that represents the proportion of the view's width
886       *        to the parent view's width to set, the decimal form of which ranges from 0 to 1.
887       * @param heightPercent Indicates the percentage that represents the proportion of the view's height
888       *        to the parent view's height to set, the decimal form of which ranges from 0 to 1.
889       * @since 5.0
890       * @version 3.0
891       */
892      virtual void ResizePercent(float widthPercent, float heightPercent);
893  
894      /**
895       * @brief Sets the x-coordinate for the view.
896       * @param x Indicates the x-coordinate to set.
897       * @since 1.0
898       * @version 1.0
899       */
900      virtual void SetX(int16_t x);
901  
902      /**
903       * @brief Sets a percentage that represents the proportion of the view's x-coordinate
904       *        to the parent view's x-coordinate.
905       * @param xPercent Indicates the percentage to set, the decimal form of which ranges from 0 to 1.
906       * @since 5.0
907       * @version 3.0
908       */
909      virtual void SetXPercent(float xPercent);
910  
911      /**
912       * @brief Obtains the x-coordinate for the view.
913       * @return Returns the x-coordinate.
914       * @since 1.0
915       * @version 1.0
916       */
917      int16_t GetX() const;
918  
919      /**
920       * @brief Sets the y-coordinate for the view.
921       * @param y Indicates the y-coordinate to set.
922       * @since 1.0
923       * @version 1.0
924       */
925      virtual void SetY(int16_t y);
926  
927      /**
928       * @brief Sets a percentage that represents the proportion of the view's y-coordinate
929       *        to the parent view's y-coordinate.
930       * @param yPercent Indicates the percentage to set, the decimal form of which ranges from 0 to 1.
931       * @since 5.0
932       * @version 3.0
933       */
934      virtual void SetYPercent(float yPercent);
935  
936      /**
937       * @brief Obtains the y-coordinate for the view.
938       * @return Returns the y-coordinate.
939       * @since 1.0
940       * @version 1.0
941       */
942      int16_t GetY() const;
943  
944      /**
945       * @brief 获取组件设置margin属性后margin的宽度,包括组件宽度加marginLeft 加 marginRight.
946       * @return margin的宽度
947       * @since 6
948       */
949      int16_t GetWidthWithMargin();
950  
951      /**
952       * @brief 获取组件设置margin属性后margin的高度度,包括组件宽度加marginTop 加 marginBottom.
953       * @return margin的高度
954       * @since 6
955       */
956      int16_t GetHeightWithMargin();
957  
958      /**
959       * @brief Sets the position for the view.
960       * @param x Indicates the x-coordinate to set.
961       * @param y Indicates the y-coordinate to set.
962       * @since 1.0
963       * @version 1.0
964       */
965      virtual void SetPosition(int16_t x, int16_t y);
966  
967      /**
968       * @brief Sets the position percentages for the view.
969       * @param xPercent Indicates the percentage that represents the proportion of the view's x-coordinate
970       *        to the parent view's x-coordinate to set, the decimal form of which ranges from 0 to 1.
971       * @param yPercent Indicates the percentage that represents the proportion of the view's y-coordinate
972       *        to the parent view's y-coordinate to set, the decimal form of which ranges from 0 to 1.
973       * @since 5.0
974       * @version 3.0
975       */
976      virtual void SetPositionPercent(float xPercent, float yPercent);
977  
978      /**
979       * @brief Adjusts the position and size of the view.
980       * @param x Indicates the new x-coordinate.
981       * @param y Indicates the new y-coordinate.
982       * @param width Indicates the new width.
983       * @param height Indicates the new height.
984       * @since 1.0
985       * @version 1.0
986       */
987      virtual void SetPosition(int16_t x, int16_t y, int16_t width, int16_t height);
988  
989      /**
990       * @brief Sets the position and size percentages for the view.
991       * @param xPercent Indicates the percentage that represents the proportion of the view's x-coordinate
992       *        to the parent view's x-coordinate to set, the decimal form of which ranges from 0 to 1.
993       * @param yPercent Indicates the percentage that represents the proportion of the view's y-coordinate
994       *        to the parent view's y-coordinate, the decimal form of which ranges from 0 to 1.
995       * @param widthPercent Indicates the percentage that represents the proportion of the view's width
996       *        to the parent view's width, the decimal form of which ranges from 0 to 1.
997       * @param heightPercent Indicates the percentage that represents the proportion of the view's height
998       *        to the parent view's height, the decimal form of which ranges from 0 to 1.
999       * @since 5.0
1000       * @version 3.0
1001       */
1002      virtual void SetPositionPercent(float xPercent, float yPercent, float widthPercent, float heightPercent);
1003  
1004      /**
1005       * @brief Checks whether the view is a container view.
1006       * @return Returns <b>true</b> if the view is a container view; returns <b>false</b> otherwise.
1007       * @since 1.0
1008       * @version 1.0
1009       */
1010      bool IsViewGroup() const;
1011  
1012      /**
1013       * @brief Sets whether to intercept the input event. If intercepted, the view does not transfer the input event to
1014       *        the parent view after local processing.
1015       * @param isIntercept Specifies whether to intercept the input event. Value <b>true</b> means to intercept the input
1016       *                    event, and <b>false</b> means the opposite.
1017       * @since 1.0
1018       * @version 1.0
1019       */
1020      void SetIntercept(bool isIntercept);
1021  
1022      /**
1023       * @brief Gets whether to intercept the input event. If intercepted, the view does not transfer the input event to
1024       *        the parent view after local processing.
1025       * @return Returns <b>true</b> if intercept the input event, and <b>false</b> means the opposite.
1026       * @since 1.0
1027       * @version 1.0
1028       */
1029      bool IsIntercept();
1030  
1031      /**
1032       * @brief Sets the affine transformation matrix.
1033       * @param transMap Indicates the transformation matrix.
1034       * @since 1.0
1035       * @version 1.0
1036       */
1037      void SetTransformMap(const TransformMap& transMap);
1038  
1039      /**
1040       * @brief Obtains an affine transformation matrix.
1041       * @return Returns the transform matrix.
1042       * @since 1.0
1043       * @version 1.0
1044       */
1045      TransformMap& GetTransformMap();
1046  
1047      /**
1048       * @brief Obtains the child view of a specified ID.
1049       * @return Returns the pointer to the child view.
1050       * @since 1.0
1051       * @version 1.0
1052       */
1053      virtual UIView* GetChildById(const char* id) const;
1054  
1055      /**
1056       * @brief Sets the view ID.
1057       * @param id Indicates the pointer to the view ID.
1058       * @since 1.0
1059       * @version 1.0
1060       */
1061      void SetViewId(const char* id);
1062  
1063      /**
1064       * @brief Obtains the view ID.
1065       * @return Returns the pointer to the view ID.
1066       * @since 1.0
1067       * @version 1.0
1068       */
1069      const char* GetViewId() const;
1070  
1071      /**
1072       * @brief Sets the view index.
1073       * @param index Indicates the view index to set.
1074       * @since 1.0
1075       * @version 1.0
1076       */
1077      void SetViewIndex(int16_t index);
1078  
1079      /**
1080       * @brief Obtains the view index.
1081       * @return Returns the view index.
1082       * @since 1.0
1083       * @version 1.0
1084       */
1085      int16_t GetViewIndex() const;
1086  
1087      /**
1088       * @brief Obtains the view type.
1089       * @return Returns the view type.
1090       * @since 1.0
1091       * @version 1.0
1092       */
1093      virtual UIViewType GetViewType() const;
1094  
1095      /**
1096       * @brief Lays out all child views according to the preset arrangement mode.
1097       * @param needInvalidate Specifies whether to refresh the invalidated area after the layout is complete.
1098       *                       Value <b>true</b> means to refresh the invalidated area after the layout is complete,
1099       *                       and <b>false</b> means the opposite.
1100       * @since 1.0
1101       * @version 1.0
1102       */
1103      virtual void LayoutChildren(bool neeInvalidate = false) {}
1104  
1105      /**
1106       * @brief Lays out the view in the center of the parent view.
1107       * @param xOffset Indicates the offset added to the x-axis after the view is placed. A positive number indicates
1108       *                the offset to the right, and a negative number indicates the offset to the left.
1109       * @param yOffset Indicates the offset added to the y-axis after the view is placed. A positive number indicates
1110       *                the offset to the bottom, and a negative number indicates the offset to the top.
1111       * @since 1.0
1112       * @version 1.0
1113       */
1114      void LayoutCenterOfParent(int16_t xOffSet = 0, int16_t yOffset = 0);
1115  
1116      /**
1117       * @brief Lays out the view on the left of the parent view.
1118       * @param offset Indicates the offset added to the x-axis after the view is placed. A positive number indicates
1119       *               the offset to the right, and a negative number indicates the offset to the left.
1120       * @since 1.0
1121       * @version 1.0
1122       */
1123      void LayoutLeftOfParent(int16_t offset = 0);
1124  
1125      /**
1126       * @brief Lays out the view on the right of the parent view.
1127       * @param offset Indicates the offset added to the x-axis after the view is placed. A positive number indicates
1128       *               the offset to the left, and a negative number indicates the offset to the right.
1129       * @since 1.0
1130       * @version 1.0
1131       */
1132      void LayoutRightOfParent(int16_t offset = 0);
1133  
1134      /**
1135       * @brief Lays out the view on the top of the parent view.
1136       * @param offset Indicates the offset added to the y-axis after the view is placed. A positive number indicates
1137       *               the offset to the bottom, and a negative number indicates the offset to the top.
1138       * @since 1.0
1139       * @version 1.0
1140       */
1141      void LayoutTopOfParent(int16_t offset = 0);
1142  
1143      /**
1144       * @brief Lays out the view on the bottom of the parent view.
1145       * @param offset Indicates the offset added to the y-axis after the view is placed. A positive number indicates
1146       *               the offset to the top, and a negative number indicates the offset to the bottom.
1147       * @since 1.0
1148       * @version 1.0
1149       */
1150      void LayoutBottomOfParent(int16_t offset = 0);
1151  
1152      /**
1153       * @brief Aligns the view with the left of a sibling view.
1154       * @param id Indicates the pointer to the ID of the sibling view.
1155       * @param offset Indicates the offset added to the x-axis after the view is placed. A positive number indicates
1156       *               the offset to the right, and a negative number indicates the offset to the left.
1157       * @since 1.0
1158       * @version 1.0
1159       */
1160      void AlignLeftToSibling(const char* id, int16_t offset = 0);
1161  
1162      /**
1163       * @brief Aligns the view with the right of a sibling view.
1164       * @param id Indicates the pointer to the ID of the sibling view.
1165       * @param offset Indicates the offset added to the x-axis after the view is placed. A positive number indicates
1166       *               the offset to the left, and a negative number indicates the offset to the right.
1167       * @since 1.0
1168       * @version 1.0
1169       */
1170      void AlignRightToSibling(const char* id, int16_t offset = 0);
1171  
1172      /**
1173       * @brief Aligns the view with the top of a sibling view.
1174       * @param id Indicates the pointer to the ID of the sibling view.
1175       * @param offset Indicates the offset added to the y-axis after the view is placed. A positive number indicates
1176       *               the offset to the bottom, and a negative number indicates the offset to the top.
1177       * @since 1.0
1178       * @version 1.0
1179       */
1180      void AlignTopToSibling(const char* id, int16_t offset = 0);
1181  
1182      /**
1183       * @brief Aligns the view with the bottom of a sibling view.
1184       * @param id Indicates the pointer to the ID of the sibling view.
1185       * @param offset Indicates the offset added to the y-axis after the view is placed. A positive number indicates
1186       *               the offset to the top, and a negative number indicates the offset to the bottom.
1187       * @since 1.0
1188       * @version 1.0
1189       */
1190      void AlignBottomToSibling(const char* id, int16_t offset = 0);
1191  
1192      /**
1193       * @brief Aligns the view with the center of a sibling view in the x-axis.
1194       * @param id Indicates the pointer to the ID of the sibling view.
1195       * @param offset Indicates the offset added to the x-axis after the view is placed. A positive number indicates
1196       *               the offset to the right, and a negative number indicates the offset to the left.
1197       * @since 1.0
1198       * @version 1.0
1199       */
1200      void AlignHorCenterToSibling(const char* id, int16_t offset = 0);
1201  
1202      /**
1203       * @brief Aligns the view with the center of a sibling view in the y-axis.
1204       * @param id Indicates the pointer to the ID of the sibling view.
1205       * @param offset Indicates the offset added to the y-axis after the view is placed. A positive number indicates
1206       *               the offset to the bottom, and a negative number indicates the offset to the top.
1207       * @since 1.0
1208       * @version 1.0
1209       */
1210      void AlignVerCenterToSibling(const char* id, int16_t offset = 0);
1211  
1212      /**
1213       * @brief Lays out the view on the left of a sibling view.
1214       * @param id Indicates the pointer to the ID of the sibling view.
1215       * @param offset Indicates the offset added to the x-axis after the view is placed. A positive number indicates
1216       *               the offset to the left, and a negative number indicates the offset to the right.
1217       * @since 1.0
1218       * @version 1.0
1219       */
1220      void LayoutLeftToSibling(const char* id, int16_t offset = 0);
1221  
1222      /**
1223       * @brief Lays out the view on the right of a sibling view.
1224       * @param id Indicates the pointer to the ID of the sibling view.
1225       * @param offset Indicates the offset added to the x-axis after the view is placed. A positive number indicates
1226       *               the offset to the right, and a negative number indicates the offset to the left.
1227       * @since 1.0
1228       * @version 1.0
1229       */
1230      void LayoutRightToSibling(const char* id, int16_t offset = 0);
1231  
1232      /**
1233       * @brief Lays out the view on the above of a sibling view.
1234       * @param id Indicates the pointer to the ID of the sibling view.
1235       * @param offset Indicates the offset added to the y-axis after the view is placed. A positive number indicates
1236       *               the offset to the top, and a negative number indicates the offset to the bottom.
1237       * @since 1.0
1238       * @version 1.0
1239       */
1240      void LayoutTopToSibling(const char* id, int16_t offset = 0);
1241  
1242      /**
1243       * @brief Lays out the view on the below of a sibling view.
1244       * @param id Indicates the pointer to the ID of the sibling view.
1245       * @param offset Indicates the offset added to the y-axis after the view is placed. A positive number indicates
1246       *               the offset to the bottom, and a negative number indicates the offset to the top.
1247       * @since 1.0
1248       * @version 1.0
1249       */
1250      void LayoutBottomToSibling(const char* id, int16_t offset = 0);
1251  
1252      /**
1253       * @brief Sets the view style.
1254       * @param style Indicates the view style.
1255       * @since 1.0
1256       * @version 1.0
1257       */
1258      virtual void SetStyle(Style& style);
1259  
1260      /**
1261       * @brief Sets a style.
1262       *
1263       * @param key Indicates the key of the style to set.
1264       * @param value Indicates the value matching the key.
1265       * @since 1.0
1266       * @version 1.0
1267       */
1268      virtual void SetStyle(uint8_t key, int64_t value);
1269  
1270      /**
1271       * @brief Obtains the value of a style.
1272       *
1273       * @param key Indicates the key of the style.
1274       * @return Returns the value of the style.
1275       * @since 1.0
1276       * @version 1.0
1277       */
1278      virtual int64_t GetStyle(uint8_t key) const;
1279  
1280      /**
1281       * @brief Obtains the view style. This function applies to scenarios where the style does not need to be modified,
1282       *        which saves memory.
1283       * @return Returns the view style.
1284       * @since 1.0
1285       * @version 1.0
1286       */
1287      const Style& GetStyleConst() const;
1288  
1289      /**
1290       * @brief Sets the opacity for the view.
1291       *
1292       * @param opaScale Indicates the opacity to set.
1293       * @since 1.0
1294       * @version 1.0
1295       */
1296      void SetOpaScale(uint8_t opaScale);
1297  
1298      /**
1299       * @brief Obtains the view opacity.
1300       *
1301       * @return Returns the view opacity.
1302       * @since 1.0
1303       * @version 1.0
1304       */
1305      uint8_t GetOpaScale() const;
1306  
1307      /**
1308       * @brief Obtains the extra message about a <b>UIView</b> instance. This field is ignored by the graphics
1309       *        framework and can be anything you set.
1310       *
1311       * @return Returns the pointer to the extra message about the <b>UIView</b> instance.
1312       * @since 5.0
1313       * @version 3.0
1314       */
1315      ViewExtraMsg* GetExtraMsg();
1316  
1317      /**
1318       * @brief Sets the extra message about a <b>UIView</b> instance. This field is ignored by the graphics
1319       *        framework and can be anything you set.
1320       *
1321       * @param extraMsg Indicates the extra message to set.
1322       * @since 5.0
1323       * @version 3.0
1324       */
1325      void SetExtraMsg(ViewExtraMsg* extraMsg);
1326  
1327      /**
1328       * @brief Rotates the view in 2d.
1329       * @param angle Indicates the rotation angle.
1330       * @param pivot Indicates the coordinates of the rotation pivot.
1331       * @since 5.0
1332       * @version 3.0
1333       */
1334      void Rotate(int16_t angle, const Vector2<float>& pivot);
1335  
1336      /**
1337       * @brief Rotates the view in 3d.
1338       * @param angle Indicates the rotation angle.
1339       * @param pivotStart Indicates the coordinates of the rotation start pivot.
1340       * @param pivotEnd Indicates the coordinates of the rotation end pivot.
1341       * @since 5.0
1342       * @version 3.0
1343       */
1344      void Rotate(int16_t angle, const Vector3<float>& pivotStart, const Vector3<float>& pivotEnd);
1345  
1346      /**
1347       * @brief Scales the view in 2d.
1348       *
1349       * @param scale Indicates the scale factor on x- and y- axes.
1350       * @param pivot Indicates the scaling pivot.
1351       * @since 5.0
1352       * @version 3.0
1353       */
1354      void Scale(const Vector2<float>& scale, const Vector2<float>& pivot);
1355  
1356      /**
1357       * @brief Scales the view in 3d.
1358       *
1359       * @param scale Indicates the scale factor on x- and y- axes.
1360       * @param pivot Indicates the scaling pivot.
1361       * @since 5.0
1362       * @version 3.0
1363       */
1364      void Scale(const Vector3<float>& scale, const Vector3<float>& pivot);
1365  
1366      /**
1367       * @brief Shears the view in 3d.
1368       *
1369       * @param shearX Indicates the shear parameters around x- axes,
1370       *               which means many it shears in y and z direction(current invalid).
1371       * @param shearY Indicates the shear parameters around y- axes,
1372       *               which means many it shears in x and z direction(current invalid).
1373       * @param shaerZ Indicates the shear parameters around z- axes,
1374       *               which means many it shears in x and y.
1375       * @since 5.0
1376       * @version 3.0
1377       */
1378      void Shear(const Vector2<float>& shearX, const Vector2<float>& shearY, const Vector2<float>& shearZ);
1379  
1380      void Translate(const Vector2<int16_t>& trans);
1381  
1382      void Translate(const Vector3<int16_t>& trans);
1383  
1384      bool IsTransInvalid();
1385  
1386      void SetCameraDistance(int16_t distance);
1387  
1388      void SetCameraPosition(const Vector2<float>& position);
1389  
1390      void ResetTransParameter();
1391  
1392  #if ENABLE_ROTATE_INPUT
1393      /**
1394       * @brief Requests the focus on the view.
1395       *
1396       * @since 5.0
1397       * @version 3.0
1398       */
1399      virtual void RequestFocus();
1400  
1401      /**
1402       * @brief Clears the focus on the view.
1403       *
1404       * @since 5.0
1405       * @version 3.0
1406       */
1407      virtual void ClearFocus();
1408  #endif
1409  #if ENABLE_FOCUS_MANAGER
1410      /**
1411       * @brief 设置视图是否可获焦.
1412       *
1413       * @param focusable 是否可获焦.
1414       * @since 5.0
1415       * @version 3.0
1416       */
1417      void SetFocusable(bool focusable);
1418  
1419      /**
1420       * @brief 获取视图是否可获焦.
1421       *
1422       * @return 是否可获焦.
1423       * @since 5.0
1424       * @version 3.0
1425       */
1426      bool IsFocusable() const;
1427  
1428      /**
1429       * @brief 组件获焦响应
1430       *
1431       * @since 5.0
1432       * @version 3.0
1433       */
1434      virtual void Focus();
1435  
1436      /**
1437       * @brief 组件失焦响应
1438       *
1439       * @since 5.0
1440       * @version 3.0
1441       */
1442      virtual void Blur();
1443  
1444      /**
1445       * @brief 焦点改变事件监听类,开发者需要向视图组件注册该类实现事件的监听.
1446       *
1447       * @since 5.0
1448       * @version 3.0
1449       */
1450      class OnFocusListener : public HeapBase {
1451      public:
1452          /**
1453           * @brief 回调函数,视图获焦时触发.
1454           * @param view 获焦的视图
1455           * @since 5.0
1456           * @version 3.0
1457           */
OnFocus(UIView & view)1458          virtual bool OnFocus(UIView& view)
1459          {
1460              return false;
1461          }
1462  
1463          /**
1464           * @brief 回调函数,视图失焦时触发.
1465           * @param view 失焦的视图
1466           * @since 5.0
1467           * @version 3.0
1468           */
OnBlur(UIView & view)1469          virtual bool OnBlur(UIView& view)
1470          {
1471              return false;
1472          }
1473  
1474          /**
1475           * @brief 析构函数.
1476           * @since 5.0
1477           * @version 3.0
1478           */
~OnFocusListener()1479          virtual ~OnFocusListener() {}
1480      };
1481  
1482      /**
1483       * @brief 设置当前视图焦点改变事件监听者.
1484       * @param onFocusListener 焦点改变事件监听者.
1485       * @since 5.0
1486       * @version 3.0
1487       */
1488      void SetOnFocusListener(OnFocusListener* onFocusListener);
1489  
1490      /**
1491       * @brief 获取当前视图焦点改变事件监听者.
1492       * @return 焦点改变事件监听者.
1493       * @since 5.0
1494       * @version 3.0
1495       */
1496      OnFocusListener* GetOnFocusListener() const;
1497  #endif
1498  
1499      /**
1500       * @brief 获取当前视图的bitmap截图.请注意该接口会申请内存,请在需要释放时使用{@link ImageCacheFree()}接口.
1501       * @param info bitmap存储对象,获取的截图将被存到该引用中.
1502       * @param colorMode 截图格式,默认状态下为带透明度的ARGB8888.
1503       * @return bitmap是否获取成功.
1504       * @since 5.0
1505       * @version 3.0
1506       */
1507      bool GetBitmap(ImageInfo& bitmap, ColorMode colorMode = ARGB8888);
1508  
1509      bool IsOnViewTree();
1510  
1511      /**
1512       * @brief Set view zIndex order
1513       * @param zIndex specifies the stack order of an view. The default is zero.
1514       *               The greater order is in front of the lower order.
1515       */
1516      void SetZIndex(int16_t zIndex);
1517  
1518      /**
1519       * @brief Get zIndex value of the view
1520       * @return the zIndex order value
1521       */
1522      int16_t GetZIndex();
1523  
1524      /**
1525       * @brief Sets the next render sibling view for the view.
1526       * @param sibling Indicates the pointer to the next render sibling view to set.
1527       */
1528      void SetNextRenderSibling(UIView* renderSibling);
1529  
1530      /**
1531       * @brief Obtains the next render sibling view of the view.
1532       * @return Returns the pointer to the next render sibling view.
1533       */
1534      UIView* GetNextRenderSibling() const;
1535  
1536  protected:
1537      bool touchable_ : 1;
1538      bool visible_ : 1;
1539      bool draggable_ : 1;
1540      bool dragParentInstead_ : 1;
1541      bool isViewGroup_ : 1;
1542      bool needRedraw_ : 1;
1543      bool styleAllocFlag_ : 1;
1544      bool isIntercept_ : 1;
1545  #if ENABLE_FOCUS_MANAGER
1546      bool focusable_ : 1;
1547  #endif
1548      uint8_t opaScale_;
1549      int16_t index_;
1550      int16_t zIndex_;
1551      const char* id_;
1552      UIView* parent_;
1553      UIView* nextSibling_;
1554      UIView* nextRenderSibling_;
1555      Style* style_;
1556      TransformMap* transMap_;
1557      OnClickListener* onClickListener_;
1558      OnLongPressListener* onLongPressListener_;
1559      OnDragListener* onDragListener_;
1560      OnTouchListener* onTouchListener_;
1561  #if ENABLE_FOCUS_MANAGER
1562      OnFocusListener* onFocusListener_;
1563  #endif
1564  #if ENABLE_ROTATE_INPUT
1565      OnRotateListener* onRotateListener_;
1566  #endif
1567      ViewExtraMsg* viewExtraMsg_;
1568  
1569      uint8_t GetMixOpaScale() const;
1570      bool IsInvalid(float percent);
1571      void DrawViewBounds(BufferInfo& gfxDstBuffer, const Rect& invalidatedArea);
1572      void UpdateRectInfo(uint8_t key, const Rect& rect);
1573  
1574  private:
1575      Rect rect_;
1576      Rect* visibleRect_;
1577      void SetupThemeStyles();
1578  };
1579  } // namespace OHOS
1580  #endif // GRAPHIC_LITE_UI_VIEW_H
1581