ui_view.h 55.4 KB
Newer Older
M
mamingshuai 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
/*
 * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/**
 * @addtogroup UI_Components
 * @{
 *
 * @brief Defines UI components such as buttons, texts, images, lists, and progress bars.
 *
 * @since 1.0
 * @version 1.0
 */

/**
 * @file ui_view.h
 *
 * @brief Declares the base class of a view, providing basic view attributes and operations. All views are derived
 *        from this class.
 *
 * @since 1.0
 * @version 1.0
 */

#ifndef GRAPHIC_LITE_UI_VIEW_H
#define GRAPHIC_LITE_UI_VIEW_H

#include "events/cancel_event.h"
#include "events/click_event.h"
#include "events/drag_event.h"
#include "events/event.h"
#include "events/long_press_event.h"
#include "events/press_event.h"
#include "events/release_event.h"
#if ENABLE_ROTATE_INPUT
#include "events/rotate_event.h"
#endif
Z
zhangguyuan 已提交
49 50
#include "gfx_utils/color.h"
#include "gfx_utils/geometry2d.h"
N
niulihua 已提交
51
#include "gfx_utils/graphic_buffer.h"
52
#include "gfx_utils/graphic_log.h"
Z
zhangguyuan 已提交
53
#include "gfx_utils/heap_base.h"
54
#include "gfx_utils/image_info.h"
Z
zhangguyuan 已提交
55 56
#include "gfx_utils/style.h"
#include "gfx_utils/transform.h"
M
mamingshuai 已提交
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138

namespace OHOS {
/* Enumerates view types. */
enum UIViewType : uint8_t {
    UI_ROOT_VIEW = 0,
    UI_VIEW_GROUP,
    UI_LABEL,
    UI_ARC_LABEL,
    UI_LABEL_BUTTON,
    UI_CHECK_BOX,
    UI_TOGGLE_BUTTON,
    UI_RADIO_BUTTON,
    UI_IMAGE_VIEW,
    UI_BOX_PROGRESS,
    UI_SLIDER,
    UI_CIRCLE_PROGRESS,
    UI_SCROLL_VIEW,
    UI_LIST,
    UI_DIGITAL_CLOCK,
    UI_ANALOG_CLOCK,
    UI_PICKER,
    UI_SWIPE_VIEW,
    UI_TIME_PICKER,
    UI_ABSTRACT_CLOCK,
    UI_ABSTRACT_PROGRESS,
    UI_ABSTRACT_SCROLL,
    UI_AXIS,
    UI_BUTTON,
    UI_CANVAS,
    UI_CHART,
    UI_IMAGE_ANIMATOR_VIEW,
    UI_REPEAT_BUTTON,
    UI_TEXTURE_MAPPER,
    UI_DIALOG,
    UI_QRCODE,
    UI_NUMBER_MAX
};

#if ENABLE_DEBUG
const char* const VIEW_TYPE_STRING[UI_NUMBER_MAX] = {
    "RootView",         "UIViewGroup",     "UILabel",
    "UIArcLabel",       "UILabelButton",   "UICheckBox",
    "UIToggleButton",   "UIRadioButton",   "UIImageView",
    "UIBoxProgress",    "UISlider",        "UICircleProgress",
    "UIScrollView",     "UIList",          "UIDigitalClock",
    "UIAnalogClock",    "UIPicker",        "UISwipeView",
    "UITimePicker",     "UIAbstractClock", "UIAbstractProgress",
    "UIAbstractScroll", "UIAxis",          "UIButton",
    "UICanvas",         "UIChart",         "UIImageAnimatorView",
    "UIRepeatButton",   "UITextureMapper", "UIDialog",
    "UIQrcode",
};
#endif // ENABLE_DEBUG

/**
 * @brief Defines the base class of a view, providing basic view attributes and operations. All views are derived
 *        from this class.
 *
 * @since 1.0
 * @version 1.0
 */
class UIView : public HeapBase {
public:
    /**
     * @brief Defines a click event listener. You need to register this listener with the view to listen to
     *        click events.
     *
     * @since 1.0
     * @version 1.0
     */
    class OnClickListener : public HeapBase {
    public:
        /**
         * @brief Called when a view is clicked.
         * @param view Indicates the view clicked.
         * @param event Indicates the click event.
         * @return Returns <b>true</b> if the event is consumed; returns <b>false</b> otherwise.
         *         (If an event is consumed, it is not transferred to the parent view. If an event is not consumed,
         *         it is transferred to the parent view after local processing is complete.)
         * @since 1.0
         * @version 1.0
         */
P
pssea 已提交
139 140 141 142
        virtual bool OnClick(UIView& view, const ClickEvent& event)
        {
            return false;
        }
M
mamingshuai 已提交
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170

        /**
         * @brief A destructor used to delete the <b>OnClickListener</b> instance.
         * @since 1.0
         * @version 1.0
         */
        virtual ~OnClickListener() {}
    };

    /**
     * @brief Defines a long-press event listener. You need to register this listener with the view to listen to
     *        long-press events.
     *
     * @since 1.0
     * @version 1.0
     */
    class OnLongPressListener : public HeapBase {
    public:
        /**
         * @brief Called when a view is long pressed.
         * @param view Indicates the view long pressed.
         * @param event Indicates the long-press event.
         * @return Returns <b>true</b> if the event is consumed; returns <b>false</b> otherwise.
         *         (If an event is consumed, it is not transferred to the parent view. If an event is not consumed,
         *         it is transferred to the parent view after local processing is complete.)
         * @since 1.0
         * @version 1.0
         */
P
pssea 已提交
171 172 173 174
        virtual bool OnLongPress(UIView& view, const LongPressEvent& event)
        {
            return false;
        }
M
mamingshuai 已提交
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201

        /**
         * @brief A destructor used to delete the <b>OnLongPressListener</b> instance.
         * @since 1.0
         * @version 1.0
         */
        virtual ~OnLongPressListener() {}
    };

    /**
     * @brief Defines a drag event listener. You need to register this listener with the view to listen to drag events.
     *
     * @since 1.0
     * @version 1.0
     */
    class OnDragListener : public HeapBase {
    public:
        /**
         * @brief Called when a view starts to drag.
         * @param view Indicates the view dragged.
         * @param event Indicates the drag event.
         * @return Returns <b>true</b> if the event is consumed; returns <b>false</b> otherwise.
         *         (If an event is consumed, it is not transferred to the parent view. If an event is not consumed,
         *         it is transferred to the parent view after local processing is complete.)
         * @since 1.0
         * @version 1.0
         */
P
pssea 已提交
202 203 204 205
        virtual bool OnDragStart(UIView& view, const DragEvent& event)
        {
            return false;
        }
M
mamingshuai 已提交
206 207 208 209 210 211 212 213 214 215 216

        /**
         * @brief Called when a view is being dragged.
         * @param view Indicates the view dragged.
         * @param event Indicates the drag event.
         * @return Returns <b>true</b> if the event is consumed; returns <b>false</b> otherwise.
         *         (If an event is consumed, it is not transferred to the parent view. If an event is not consumed,
         *         it is transferred to the parent view after local processing is complete.)
         * @since 1.0
         * @version 1.0
         */
P
pssea 已提交
217 218 219 220
        virtual bool OnDrag(UIView& view, const DragEvent& event)
        {
            return false;
        }
M
mamingshuai 已提交
221 222 223 224 225 226 227 228 229 230 231

        /**
         * @brief Called when a view stops dragging.
         * @param view Indicates the view dragged.
         * @param event Indicates the drag event.
         * @return Returns <b>true</b> if the event is consumed; returns <b>false</b> otherwise.
         *         (If an event is consumed, it is not transferred to the parent view. If an event is not consumed,
         *         it is transferred to the parent view after local processing is complete.)
         * @since 1.0
         * @version 1.0
         */
P
pssea 已提交
232 233 234 235
        virtual bool OnDragEnd(UIView& view, const DragEvent& event)
        {
            return false;
        }
M
mamingshuai 已提交
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263

        /**
         * @brief A destructor used to delete the <b>OnDragListener</b> instance.
         * @since 1.0
         * @version 1.0
         */
        virtual ~OnDragListener() {}
    };

    /**
     * @brief Defines a touch event listener. You need to register this listener with the view to listen to touch
     *        events.
     *
     * @since 1.0
     * @version 1.0
     */
    class OnTouchListener : public HeapBase {
    public:
        /**
         * @brief Called when a view is pressed.
         * @param view Indicates the view pressed.
         * @param event Indicates the press event.
         * @return Returns <b>true</b> if the event is consumed; returns <b>false</b> otherwise.
         *         (If an event is consumed, it is not transferred to the parent view. If an event is not consumed,
         *         it is transferred to the parent view after local processing is complete.)
         * @since 1.0
         * @version 1.0
         */
P
pssea 已提交
264 265 266 267
        virtual bool OnPress(UIView& view, const PressEvent& event)
        {
            return false;
        }
M
mamingshuai 已提交
268 269 270 271 272 273 274 275 276 277 278

        /**
         * @brief Called when a view is released.
         * @param view Indicates the view released.
         * @param event Indicates the release event.
         * @return Returns <b>true</b> if the event is consumed; returns <b>false</b> otherwise.
         *         (If an event is consumed, it is not transferred to the parent view. If an event is not consumed,
         *         it is transferred to the parent view after local processing is complete.)
         * @since 1.0
         * @version 1.0
         */
P
pssea 已提交
279 280 281 282
        virtual bool OnRelease(UIView& view, const ReleaseEvent& event)
        {
            return false;
        }
M
mamingshuai 已提交
283 284 285 286 287 288 289 290 291 292 293

        /**
         * @brief Called when a click event on a view is canceled.
         * @param view Indicates the view on which a click event is canceled.
         * @param event Indicates the cancel event.
         * @return Returns <b>true</b> if the event is consumed; returns <b>false</b> otherwise.
         *         (If an event is consumed, it is not transferred to the parent view. If an event is not consumed,
         *         it is transferred to the parent view after local processing is complete.)
         * @since 1.0
         * @version 1.0
         */
P
pssea 已提交
294 295 296 297
        virtual bool OnCancel(UIView& view, const CancelEvent& event)
        {
            return false;
        }
M
mamingshuai 已提交
298 299 300 301 302 303 304 305 306 307 308

        /**
         * @brief A destructor used to delete the <b>OnTouchListener</b> instance.
         * @since 1.0
         * @version 1.0
         */
        virtual ~OnTouchListener() {}
    };

#if ENABLE_ROTATE_INPUT
    /**
Y
YueBiang 已提交
309 310
     * @brief Defines a rotation event listener.
     *        You need to register this listener with the view to listen for rotation events.
M
mamingshuai 已提交
311 312 313 314 315
     * @since 5.0
     * @version 3.0
     */
    class OnRotateListener : public HeapBase {
    public:
Y
YueBiang 已提交
316 317 318 319 320 321 322 323 324 325 326 327
        /**
         * @brief Called when the view starts to rotate.
         * @param view Indicates the view that responds to the rotation event.
         * @param event Indicates the rotation event.
         * @return Returns <b>true</b> if the rotation event is consumed; returns <b>false</b> otherwise.
         * @since 6
         */
        virtual bool OnRotateStart(UIView& view, const RotateEvent& event)
        {
            return false;
        }

M
mamingshuai 已提交
328
        /**
Y
YueBiang 已提交
329 330 331 332
         * @brief Called when a rotation event occurs on a view.
         * @param view Indicates the view that responds to the rotation event.
         * @param event Indicates the rotation event.
         * @return Returns <b>true</b> if the rotation event is consumed; returns <b>false</b> otherwise.
M
mamingshuai 已提交
333 334 335
         * @since 5.0
         * @version 3.0
         */
P
pssea 已提交
336 337
        virtual bool OnRotate(UIView& view, const RotateEvent& event)
        {
Y
YueBiang 已提交
338 339 340 341 342 343 344 345 346 347 348 349 350
            return false;
        }

        /**
         * @brief Called when the view stops rotating.
         * @param view Indicates the view that responds to the rotation event.
         * @param event Indicates the rotation event.
         * @return Returns <b>true</b> if the rotation event is consumed; returns <b>false</b> otherwise.
         * @since 6
         */
        virtual bool OnRotateEnd(UIView& view, const RotateEvent& event)
        {
            return false;
P
pssea 已提交
351
        }
Y
YueBiang 已提交
352

M
mamingshuai 已提交
353
        /**
Y
YueBiang 已提交
354
         * @brief A destructor used to delete an <b>OnRotateListener</b> instance.
M
mamingshuai 已提交
355 356 357 358 359 360
         * @since 5.0
         * @version 3.0
         */
        virtual ~OnRotateListener() {}
    };

Y
YueBiang 已提交
361 362 363 364 365 366 367
    /**
     * @brief Called when the view starts to rotate.
     * @param event Indicates the rotation event.
     * @since 6
     */
    virtual bool OnRotateStartEvent(const RotateEvent& event);

M
mamingshuai 已提交
368
    /**
Y
YueBiang 已提交
369 370
     * @brief Called when a rotation event occurs on the view.
     * @param event Indicates the rotation event.
M
mamingshuai 已提交
371 372 373 374 375
     * @since 5.0
     * @version 3.0
     */
    virtual bool OnRotateEvent(const RotateEvent& event);

Y
YueBiang 已提交
376 377 378 379 380 381 382
    /**
     * @brief Called when the view stops rotating.
     * @param event Indicates the rotation event.
     * @since 6
     */
    virtual bool OnRotateEndEvent(const RotateEvent& event);

M
mamingshuai 已提交
383
    /**
Y
YueBiang 已提交
384 385
     * @brief Sets a rotation event listener for the view.
     * @param onRotateListener Indicates the pointer to the rotation event listener to set.
M
mamingshuai 已提交
386 387 388
     * @since 5.0
     * @version 3.0
     */
P
pssea 已提交
389 390 391 392
    void SetOnRotateListener(OnRotateListener* onRotateListener)
    {
        onRotateListener_ = onRotateListener;
    }
M
mamingshuai 已提交
393 394

    /**
Y
YueBiang 已提交
395 396
     * @brief Obtains the rotation event listener for the view.
     * @return Returns the rotation event listener.
M
mamingshuai 已提交
397 398 399
     * @since 5.0
     * @version 3.0
     */
P
pssea 已提交
400 401 402 403
    OnRotateListener*& GetOnRotateListener()
    {
        return onRotateListener_;
    }
M
mamingshuai 已提交
404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456
#endif

    /**
     * @brief Stores extra information about a <b>UIView</b> instance.
     * @param elementPtr Indicates the void pointer to the extra information about the <b>UIView</b> instance.
     * @since 5.0
     * @version 3.0
     */
    struct ViewExtraMsg {
        void* elementPtr;
    };

    /**
     * @brief A default constructor used to create an <b>UIView</b> instance.
     * @since 1.0
     * @version 1.0
     */
    UIView();

    /**
     * @brief A constructor used to create an <b>UIView</b> instance.
     * @param id Indicates the pointer to the view ID.
     * @since 1.0
     * @version 1.0
     */
    UIView(const char* id) : UIView()
    {
        id_ = id;
    }

    /**
     * @brief A destructor used to delete the <b>UIView</b> instance.
     * @since 1.0
     * @version 1.0
     */
    virtual ~UIView();

    /**
     * @brief Called before a view is drawn. This function is used to check whether the invalidated area
     *        can be fully cover by this view so as to optimize the drawing process.
     * @param invalidatedArea Indicates the area to judge and returns the covered area when partly coverd.
     * @return Returns <b>true</b> if the invalidated area is fully covered; returns <b>false</b> otherwise.
     * @since 1.0
     * @version 1.0
     */
    virtual bool OnPreDraw(Rect& invalidatedArea) const;

    /**
     * @brief Called when a view is drawn.
     * @param invalidatedArea Indicates the area to draw.
     * @since 1.0
     * @version 1.0
     */
N
niulihua 已提交
457
    virtual void OnDraw(BufferInfo& gfxDstBuffer, const Rect& invalidatedArea);
M
mamingshuai 已提交
458 459 460 461 462 463 464

    /**
     * @brief Called after a view is drawn.
     * @param invalidatedArea Indicates the area in which the view is drawn.
     * @since 1.0
     * @version 1.0
     */
P
pssea 已提交
465
    virtual void OnPostDraw(BufferInfo& gfxDstBuffer, const Rect& invalidatedArea);
M
mamingshuai 已提交
466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582

    /**
     * @brief Remeasures the view size.
     * @since 1.0
     * @version 1.0
     */
    virtual void ReMeasure() {}

    /**
     * @brief Refreshes the invalidated area of the view.
     * @since 1.0
     * @version 1.0
     */
    void Invalidate();

    /**
     * @brief Refreshes a view in a specified invalidated area.
     * @param invalidatedArea Indicates the area to refresh.
     * @since 1.0
     * @version 1.0
     */
    void InvalidateRect(const Rect& invalidatedArea);

    /**
     * @brief Called when the view is long pressed.
     * @param event Indicates the long-press event.
     * @return Returns <b>true</b> if the event is consumed; returns <b>false</b> otherwise.
     *         (If an event is consumed, it is not transferred to the parent view. If an event is not consumed,
     *         it is transferred to the parent view after local processing is complete.)
     * @since 1.0
     * @version 1.0
     */
    virtual bool OnLongPressEvent(const LongPressEvent& event);

    /**
     * @brief Called when the view starts to drag.
     * @param event Indicates the drag event.
     * @return Returns <b>true</b> if the event is consumed; returns <b>false</b> otherwise.
     *         (If an event is consumed, it is not transferred to the parent view. If an event is not consumed,
     *         it is transferred to the parent view after local processing is complete.)
     * @since 1.0
     * @version 1.0
     */
    virtual bool OnDragStartEvent(const DragEvent& event);

    /**
     * @brief Called when the view is being dragged.
     * @param event Indicates the drag event.
     * @return Returns <b>true</b> if the event is consumed; returns <b>false</b> otherwise.
     *         (If an event is consumed, it is not transferred to the parent view. If an event is not consumed,
     *         it is transferred to the parent view after local processing is complete.)
     * @since 1.0
     * @version 1.0
     */
    virtual bool OnDragEvent(const DragEvent& event);

    /**
     * @brief Called when the view stops dragging.
     * @param event Indicates the drag event.
     * @return Returns <b>true</b> if the event is consumed; returns <b>false</b> otherwise.
     *         (If an event is consumed, it is not transferred to the parent view. If an event is not consumed,
     *         it is transferred to the parent view after local processing is complete.)
     * @since 1.0
     * @version 1.0
     */
    virtual bool OnDragEndEvent(const DragEvent& event);

    /**
     * @brief Called when the view is clicked.
     * @param event Indicates the click event.
     * @return Returns <b>true</b> if the event is consumed; returns <b>false</b> otherwise.
     *         (If an event is consumed, it is not transferred to the parent view. If an event is not consumed,
     *         it is transferred to the parent view after local processing is complete.)
     * @since 1.0
     * @version 1.0
     */
    virtual bool OnClickEvent(const ClickEvent& event);

    /**
     * @brief Called when the view is pressed.
     * @param event Indicates the press event.
     * @return Returns <b>true</b> if the event is consumed; returns <b>false</b> otherwise.
     *         (If an event is consumed, it is not transferred to the parent view. If an event is not consumed,
     *         it is transferred to the parent view after local processing is complete.)
     * @since 1.0
     * @version 1.0
     */
    virtual bool OnPressEvent(const PressEvent& event);

    /**
     * @brief Called when the view is released.
     * @param event Indicates the release event.
     * @return Returns <b>true</b> if the event is consumed; returns <b>false</b> otherwise.
     *         (If an event is consumed, it is not transferred to the parent view. If an event is not consumed,
     *         it is transferred to the parent view after local processing is complete.)
     * @since 1.0
     * @version 1.0
     */
    virtual bool OnReleaseEvent(const ReleaseEvent& event);

    /**
     * @brief Called when a click event on the view is canceled.
     * @param event Indicates the cancel event.
     * @return Returns <b>true</b> if the event is consumed; returns <b>false</b> otherwise.
     *         (If an event is consumed, it is not transferred to the parent view. If an event is not consumed,
     *         it is transferred to the parent view after local processing is complete.)
     * @since 1.0
     * @version 1.0
     */
    virtual bool OnCancelEvent(const CancelEvent& event);

    /**
     * @brief Sets a drag event listener for the view.
     * @param onDragListener Indicates the pointer to the drag event listener to set.
     * @since 1.0
     * @version 1.0
     */
P
pssea 已提交
583 584 585 586
    void SetOnDragListener(OnDragListener* onDragListener)
    {
        onDragListener_ = onDragListener;
    }
M
mamingshuai 已提交
587 588 589 590 591 592 593

    /**
     * @brief Obtains the drag event listener for the view.
     * @return Returns the drag event listener.
     * @since 1.0
     * @version 1.0
     */
P
pssea 已提交
594 595 596 597
    OnDragListener*& GetOnDragListener()
    {
        return onDragListener_;
    }
M
mamingshuai 已提交
598 599 600 601 602 603 604

    /**
     * @brief Sets a click event listener for the view.
     * @param onClickListener Indicates the pointer to the click event listener to set.
     * @since 1.0
     * @version 1.0
     */
P
pssea 已提交
605 606 607 608
    void SetOnClickListener(OnClickListener* onClickListener)
    {
        onClickListener_ = onClickListener;
    }
M
mamingshuai 已提交
609 610 611 612 613 614 615

    /**
     * @brief Obtains the click event listener for the view.
     * @return Returns the click event listener.
     * @since 1.0
     * @version 1.0
     */
P
pssea 已提交
616 617 618 619
    OnClickListener*& GetOnClickListener()
    {
        return onClickListener_;
    }
M
mamingshuai 已提交
620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637

    /**
     * @brief Sets a long-press event listener for the view.
     * @param onLongPressListener Indicates the pointer to the long-press event listener to set.
     * @since 1.0
     * @version 1.0
     */
    void SetOnLongPressListener(OnLongPressListener* onLongPressListener)
    {
        onLongPressListener_ = onLongPressListener;
    }

    /**
     * @brief Obtains the long-press event listener for the view.
     * @return Returns the long-press event listener.
     * @since 1.0
     * @version 1.0
     */
P
pssea 已提交
638 639 640 641
    OnLongPressListener*& GetOnLongPressListener()
    {
        return onLongPressListener_;
    }
M
mamingshuai 已提交
642 643 644 645 646 647 648

    /**
     * @brief Sets a touch event listener for the view.
     * @param onTouchListener Indicates the pointer to the touch event listener to set.
     * @since 1.0
     * @version 1.0
     */
P
pssea 已提交
649 650 651 652
    void SetOnTouchListener(OnTouchListener* onTouchListener)
    {
        onTouchListener_ = onTouchListener;
    }
M
mamingshuai 已提交
653 654 655 656 657 658 659

    /**
     * @brief Obtains the touch event listener for the view.
     * @return Returns the touch event listener.
     * @since 1.0
     * @version 1.0
     */
P
pssea 已提交
660 661 662 663
    OnTouchListener*& GetTouchListener()
    {
        return onTouchListener_;
    }
M
mamingshuai 已提交
664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693

    /**
     * @brief Obtains the top-level view based on specified coordinates.
     * @param point Indicates the coordinates to specify.
     * @param last Indicates the double pointer to the view that contains the specified coordinates.
     * @since 1.0
     * @version 1.0
     */
    virtual void GetTargetView(const Point& point, UIView** last);

    /**
     * @brief Obtains the current view and target view based on specified coordinates. The obtained current view must
     *        include the specified coordinates and is a visible top view that can respond to touch events, and the
     *        obtained target view must be the top view that includes the specified coordinates.
     * @param point Indicates the specified coordinates.
     * @param current Indicates the double pointer to the current view to obtain.
     *        <b>nullptr</b> indicates that the target view fails to be obtained.
     * @param target Indicates the double pointer to the target view to obtain.
     *        <b>nullptr</b> indicates that the target view fails to be obtained.
     * @since 5.0
     * @version 3.0
     */
    virtual void GetTargetView(const Point& point, UIView** current, UIView** target);

    /**
     * @brief Sets the parent view for the view.
     * @param parent Indicates the pointer to the parent view to set.
     * @since 1.0
     * @version 1.0
     */
P
pssea 已提交
694 695 696 697
    void SetParent(UIView* parent)
    {
        parent_ = parent;
    }
M
mamingshuai 已提交
698 699 700 701 702 703 704

    /**
     * @brief Obtains the parent view of the view.
     * @return Returns the pointer to the parent view.
     * @since 1.0
     * @version 1.0
     */
P
pssea 已提交
705 706 707 708
    UIView* GetParent() const
    {
        return parent_;
    }
M
mamingshuai 已提交
709 710 711 712 713 714 715

    /**
     * @brief Sets the next sibling view for the view.
     * @param sibling Indicates the pointer to the next sibling view to set.
     * @since 1.0
     * @version 1.0
     */
P
pssea 已提交
716 717 718 719
    void SetNextSibling(UIView* sibling)
    {
        nextSibling_ = sibling;
    }
M
mamingshuai 已提交
720 721 722 723 724 725 726

    /**
     * @brief Obtains the next sibling view of the view.
     * @return Returns the pointer to the next sibling view.
     * @since 1.0
     * @version 1.0
     */
P
pssea 已提交
727 728 729 730
    UIView* GetNextSibling() const
    {
        return nextSibling_;
    }
M
mamingshuai 已提交
731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753

    /**
     * @brief Sets whether the view is visible.
     * @param visible Specifies whether to set the view visible. Value <b>true</b> means to set the view visible,
     *                and <b>false</b> means the opposite.
     * @since 1.0
     * @version 1.0
     */
    virtual void SetVisible(bool visible)
    {
        if (visible_ != visible) {
            visible_ = visible;
            needRedraw_ = true;
            Invalidate();
        }
    }

    /**
     * @brief Checks whether the view is visible.
     * @return Returns <b>true</b> if the view is visible; returns <b>false</b> otherwise.
     * @since 1.0
     * @version 1.0
     */
P
pssea 已提交
754 755 756 757
    bool IsVisible() const
    {
        return visible_;
    }
M
mamingshuai 已提交
758 759 760 761 762 763 764 765

    /**
     * @brief Sets whether the view is touchable.
     * @param touchable Specifies whether to set the view touchable. Value <b>true</b> means to set the view touchable,
     *                  and <b>false</b> means the opposite.
     * @since 1.0
     * @version 1.0
     */
P
pssea 已提交
766 767 768 769
    void SetTouchable(bool touch)
    {
        touchable_ = touch;
    }
M
mamingshuai 已提交
770 771 772 773 774 775 776

    /**
     * @brief Checks whether the view is touchable.
     * @return Returns <b>true</b> if the view is touchable; returns <b>false</b> otherwise.
     * @since 1.0
     * @version 1.0
     */
P
pssea 已提交
777 778 779 780
    bool IsTouchable() const
    {
        return touchable_;
    }
M
mamingshuai 已提交
781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800

    /**
     * @brief Sets whether the view is draggable.
     * @param draggable Specifies whether to set the view draggable. Value <b>true</b> means to set the view draggable,
     *                  and <b>false</b> means the opposite.
     * @since 1.0
     * @version 1.0
     */
    void SetDraggable(bool draggable)
    {
        draggable_ = draggable;
        dragParentInstead_ = !draggable;
    }

    /**
     * @brief Checks whether the view is draggable.
     * @return Returns <b>true</b> if the view is draggable; returns <b>false</b> otherwise.
     * @since 1.0
     * @version 1.0
     */
P
pssea 已提交
801 802 803 804
    bool IsDraggable() const
    {
        return draggable_;
    }
M
mamingshuai 已提交
805 806 807 808 809 810 811 812 813

    /**
     * @brief Sets whether to transfer the drag event to the parent view for processing when the view is being dragged.
     * @param dragParentInstead Specifies whether to transfer the event to the parent view for processing.
     *                          Value <b>true</b> means to transfer the event to the parent view for processing,
     *                          and <b>false</b> means the opposite.
     * @since 1.0
     * @version 1.0
     */
P
pssea 已提交
814 815 816 817
    void SetDragParentInstead(bool dragParentInstead)
    {
        dragParentInstead_ = dragParentInstead;
    }
M
mamingshuai 已提交
818 819 820 821 822 823 824 825

    /**
     * @brief Obtains whether the view transfers a drag event to the parent view for processing.
     * @return Returns <b>true</b> if the view transfers the event to the parent view for processing;
     *         returns <b>false</b> otherwise.
     * @since 1.0
     * @version 1.0
     */
P
pssea 已提交
826 827 828 829
    bool IsDragParentInstead() const
    {
        return dragParentInstead_;
    }
M
mamingshuai 已提交
830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880

    /**
     * @brief Obtains the absolute rectangle area of the view. When the view has deformation such as rotation,
     *        the rectangle area is the intersection set of the absolute rectangle area and deformation matrix.
     * @return Returns the absolute rectangle area.
     * @since 1.0
     * @version 1.0
     */
    Rect GetRect() const;

    /**
     * @brief Obtains the visible absolute rectangle area of the view.
     * @return Returns the visible absolute rectangle area.
     * @since 1.0
     * @version 1.0
     */
    Rect GetVisibleRect() const;

    /**
     * @brief Obtains the valid absolute rectangle area of the view. The valid area refers to the area where the view
     *        can be displayed. Generally, the valid area is the same as the visible view area, but they may be
     *        different in the grid layout.
     * @return Returns the valid absolute rectangle area.
     * @since 1.0
     * @version 1.0
     */
    Rect GetMaskedRect() const;

    /**
     * @brief Obtains the absolute rectangle area of the view.
     * @return Returns the absolute rectangle area.
     * @since 1.0
     * @version 1.0
     */
    Rect GetOrigRect() const;

    /**
     * @brief Obtains the content of the absolute rectangle area of the view. This area excludes padding.
     * @return Returns the content of the absolute rectangle area.
     * @since 1.0
     * @version 1.0
     */
    virtual Rect GetContentRect();

    /**
     * @brief Obtains the rectangular area of the view relative to the parent view, that is, the rectangular area
     *        relative to the coordinates of the parent view.
     * @return Returns the rectangle area relative to the parent view.
     * @since 1.0
     * @version 1.0
     */
P
pssea 已提交
881 882 883 884
    Rect GetRelativeRect() const
    {
        return rect_;
    }
M
mamingshuai 已提交
885 886 887 888 889 890 891 892 893 894

    /**
     * @brief Adjusts the size of the visible area. This operation may affect the final display size.
     * @param x Indicates the new x-coordinate.
     * @param y Indicates the new y-coordinate.
     * @param width Indicates the new width.
     * @param height Indicates the new height.
     * @since 1.0
     * @version 1.0
     */
895 896 897 898 899 900 901 902 903 904 905 906 907
    void ResizeVisibleArea(int16_t x, int16_t y, int16_t width, int16_t height)
    {
        if (visibleRect_ == nullptr) {
            visibleRect_ = new Rect();
            if (visibleRect_ == nullptr) {
                GRAPHIC_LOGE("new Rect fail");
                return;
            }
        }
        visibleRect_->SetWidth(width);
        visibleRect_->SetHeight(height);
        visibleRect_->SetPosition(x, y);
    }
M
mamingshuai 已提交
908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008

    /**
     * @brief Sets the width for the view.
     * @param width Indicates the width to set.
     * @since 1.0
     * @version 1.0
     */
    virtual void SetWidth(int16_t width)
    {
        if (GetWidth() != width) {
            int16_t newWidth = width + style_->paddingLeft_ + style_->paddingRight_ +
                               (style_->borderWidth_ * 2); /* 2: left and right border */
            rect_.SetWidth(newWidth);
        }
    }

    /**
     * @brief Sets a percentage that represents the proportion of the view's width to the parent view's width.
     * @param widthPercent Indicates the percentage to set, the decimal form of which ranges from 0 to 1.
     * @since 5.0
     * @version 3.0
     */
    virtual void SetWidthPercent(float widthPercent);

    /**
     * @brief Obtains the width for the view.
     * @return Returns the view width.
     * @since 1.0
     * @version 1.0
     */
    virtual int16_t GetWidth()
    {
        return rect_.GetWidth() - (style_->paddingLeft_ + style_->paddingRight_) -
               (style_->borderWidth_ * 2); /* 2: left and right border */
    }

    /**
     * @brief Sets the height for the view.
     * @param height Indicates the height to set.
     * @since 1.0
     * @version 1.0
     */
    virtual void SetHeight(int16_t height)
    {
        if (GetHeight() != height) {
            int16_t newHeight = height + style_->paddingTop_ + style_->paddingBottom_ +
                                (style_->borderWidth_ * 2); /* 2: top and bottom border */
            rect_.SetHeight(newHeight);
        }
    }

    /**
     * @brief Sets a percentage that represents the proportion of the view's hieght to the parent view's hieght.
     * @param widthPercent Indicates the percentage to set, the decimal form of which ranges from 0 to 1.
     * @since 5.0
     * @version 3.0
     */
    virtual void SetHeightPercent(float heightPercent);

    /**
     * @brief Obtains the height for the view.
     * @return Returns the view height.
     * @since 1.0
     * @version 1.0
     */
    virtual int16_t GetHeight()
    {
        return rect_.GetHeight() - (style_->paddingTop_ + style_->paddingBottom_) -
               (style_->borderWidth_ * 2); /* 2: top and bottom border */
    }

    /**
     * @brief Adjusts the size of the view.
     * @param width Indicates the new width.
     * @param height Indicates the new height.
     * @since 1.0
     * @version 1.0
     */
    virtual void Resize(int16_t width, int16_t height)
    {
        SetWidth(width);
        SetHeight(height);
    }

    /**
     * @brief Adjusts the size of the view based on specified percentages.
     * @param widthPercent Indicates the percentage that represents the proportion of the view's width
     *        to the parent view's width to set, the decimal form of which ranges from 0 to 1.
     * @param heightPercent Indicates the percentage that represents the proportion of the view's height
     *        to the parent view's height to set, the decimal form of which ranges from 0 to 1.
     * @since 5.0
     * @version 3.0
     */
    virtual void ResizePercent(float widthPercent, float heightPercent);

    /**
     * @brief Sets the x-coordinate for the view.
     * @param x Indicates the x-coordinate to set.
     * @since 1.0
     * @version 1.0
     */
1009 1010 1011 1012 1013 1014
    virtual void SetX(int16_t x)
    {
        if (GetX() != x) {
            rect_.SetX(x + GetStyle(STYLE_MARGIN_LEFT));
        }
    }
M
mamingshuai 已提交
1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030

    /**
     * @brief Sets a percentage that represents the proportion of the view's x-coordinate
     *        to the parent view's x-coordinate.
     * @param xPercent Indicates the percentage to set, the decimal form of which ranges from 0 to 1.
     * @since 5.0
     * @version 3.0
     */
    virtual void SetXPercent(float xPercent);

    /**
     * @brief Obtains the x-coordinate for the view.
     * @return Returns the x-coordinate.
     * @since 1.0
     * @version 1.0
     */
1031 1032 1033 1034
    int16_t GetX() const
    {
        return rect_.GetX() - GetStyle(STYLE_MARGIN_LEFT);
    }
M
mamingshuai 已提交
1035 1036 1037 1038 1039 1040 1041

    /**
     * @brief Sets the y-coordinate for the view.
     * @param y Indicates the y-coordinate to set.
     * @since 1.0
     * @version 1.0
     */
1042 1043 1044 1045 1046 1047
    virtual void SetY(int16_t y)
    {
        if (GetY() != y) {
            rect_.SetY(y + GetStyle(STYLE_MARGIN_TOP));
        }
    }
M
mamingshuai 已提交
1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063

    /**
     * @brief Sets a percentage that represents the proportion of the view's y-coordinate
     *        to the parent view's y-coordinate.
     * @param yPercent Indicates the percentage to set, the decimal form of which ranges from 0 to 1.
     * @since 5.0
     * @version 3.0
     */
    virtual void SetYPercent(float yPercent);

    /**
     * @brief Obtains the y-coordinate for the view.
     * @return Returns the y-coordinate.
     * @since 1.0
     * @version 1.0
     */
1064 1065 1066 1067 1068 1069 1070 1071
    int16_t GetY() const
    {
        return rect_.GetY() - GetStyle(STYLE_MARGIN_TOP);
    }

    /**
     * @brief 获取组件设置margin属性后margin的宽度,包括组件宽度加marginLeft 加 marginRight.
     * @return margin的宽度
B
benb365 已提交
1072
     * @since 6
1073 1074 1075 1076 1077 1078 1079 1080 1081
     */
    int16_t GetWidthWithMargin()
    {
        return GetRelativeRect().GetWidth() + GetStyle(STYLE_MARGIN_LEFT) + GetStyle(STYLE_MARGIN_RIGHT);
    }

    /**
     * @brief 获取组件设置margin属性后margin的高度度,包括组件宽度加marginTop 加 marginBottom.
     * @return margin的高度
B
benb365 已提交
1082
     * @since 6
1083 1084 1085 1086 1087
     */
    int16_t GetHeightWithMargin()
    {
        return GetRelativeRect().GetHeight() + GetStyle(STYLE_MARGIN_TOP) + GetStyle(STYLE_MARGIN_BOTTOM);
    }
M
mamingshuai 已提交
1088 1089 1090 1091 1092 1093 1094 1095

    /**
     * @brief Sets the position for the view.
     * @param x Indicates the x-coordinate to set.
     * @param y Indicates the y-coordinate to set.
     * @since 1.0
     * @version 1.0
     */
1096 1097 1098 1099 1100
    virtual void SetPosition(int16_t x, int16_t y)
    {
        SetX(x);
        SetY(y);
    }
M
mamingshuai 已提交
1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149

    /**
     * @brief Sets the position percentages for the view.
     * @param xPercent Indicates the percentage that represents the proportion of the view's x-coordinate
     *        to the parent view's x-coordinate to set, the decimal form of which ranges from 0 to 1.
     * @param yPercent Indicates the percentage that represents the proportion of the view's y-coordinate
     *        to the parent view's y-coordinate to set, the decimal form of which ranges from 0 to 1.
     * @since 5.0
     * @version 3.0
     */
    virtual void SetPositionPercent(float xPercent, float yPercent);

    /**
     * @brief Adjusts the position and size of the view.
     * @param x Indicates the new x-coordinate.
     * @param y Indicates the new y-coordinate.
     * @param width Indicates the new width.
     * @param height Indicates the new height.
     * @since 1.0
     * @version 1.0
     */
    virtual void SetPosition(int16_t x, int16_t y, int16_t width, int16_t height)
    {
        SetPosition(x, y);
        SetWidth(width);
        SetHeight(height);
    }

    /**
     * @brief Sets the position and size percentages for the view.
     * @param xPercent Indicates the percentage that represents the proportion of the view's x-coordinate
     *        to the parent view's x-coordinate to set, the decimal form of which ranges from 0 to 1.
     * @param yPercent Indicates the percentage that represents the proportion of the view's y-coordinate
     *        to the parent view's y-coordinate, the decimal form of which ranges from 0 to 1.
     * @param widthPercent Indicates the percentage that represents the proportion of the view's width
     *        to the parent view's width, the decimal form of which ranges from 0 to 1.
     * @param heightPercent Indicates the percentage that represents the proportion of the view's height
     *        to the parent view's height, the decimal form of which ranges from 0 to 1.
     * @since 5.0
     * @version 3.0
     */
    virtual void SetPositionPercent(float xPercent, float yPercent, float widthPercent, float heightPercent);

    /**
     * @brief Checks whether the view is a container view.
     * @return Returns <b>true</b> if the view is a container view; returns <b>false</b> otherwise.
     * @since 1.0
     * @version 1.0
     */
P
pssea 已提交
1150 1151 1152 1153
    bool IsViewGroup() const
    {
        return isViewGroup_;
    }
M
mamingshuai 已提交
1154 1155

    /**
1156
     * @brief Sets whether to intercept the input event. If intercepted, the view does not transfer the input event to
M
mamingshuai 已提交
1157
     *        the parent view after local processing.
1158
     * @param isIntercept Specifies whether to intercept the input event. Value <b>true</b> means to intercept the input
M
mamingshuai 已提交
1159 1160 1161 1162
     *                    event, and <b>false</b> means the opposite.
     * @since 1.0
     * @version 1.0
     */
P
pssea 已提交
1163 1164 1165 1166
    void SetIntercept(bool isIntercept)
    {
        isIntercept_ = isIntercept;
    }
1167 1168 1169 1170 1171 1172 1173 1174

    /**
     * @brief Gets whether to intercept the input event. If intercepted, the view does not transfer the input event to
     *        the parent view after local processing.
     * @return Returns <b>true</b> if intercept the input event, and <b>false</b> means the opposite.
     * @since 1.0
     * @version 1.0
     */
P
pssea 已提交
1175 1176 1177 1178
    bool IsIntercept()
    {
        return isIntercept_;
    }
M
mamingshuai 已提交
1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207

    /**
     * @brief Sets the affine transformation matrix.
     * @param transMap Indicates the transformation matrix.
     * @since 1.0
     * @version 1.0
     */
    void SetTransformMap(const TransformMap& transMap);

    /**
     * @brief Obtains an affine transformation matrix.
     * @return Returns the transform matrix.
     * @since 1.0
     * @version 1.0
     */
    TransformMap& GetTransformMap()
    {
        if (transMap_ == nullptr) {
            transMap_ = new TransformMap();
        }
        return *transMap_;
    }

    /**
     * @brief Obtains the child view of a specified ID.
     * @return Returns the pointer to the child view.
     * @since 1.0
     * @version 1.0
     */
P
pssea 已提交
1208 1209 1210 1211
    virtual UIView* GetChildById(const char* id) const
    {
        return nullptr;
    }
M
mamingshuai 已提交
1212 1213 1214 1215 1216 1217 1218

    /**
     * @brief Sets the view ID.
     * @param id Indicates the pointer to the view ID.
     * @since 1.0
     * @version 1.0
     */
P
pssea 已提交
1219 1220 1221 1222
    void SetViewId(const char* id)
    {
        id_ = id;
    }
M
mamingshuai 已提交
1223 1224 1225 1226 1227 1228 1229

    /**
     * @brief Obtains the view ID.
     * @return Returns the pointer to the view ID.
     * @since 1.0
     * @version 1.0
     */
P
pssea 已提交
1230 1231 1232 1233
    const char* GetViewId() const
    {
        return id_;
    }
M
mamingshuai 已提交
1234 1235 1236 1237 1238 1239 1240

    /**
     * @brief Sets the view index.
     * @param index Indicates the view index to set.
     * @since 1.0
     * @version 1.0
     */
P
pssea 已提交
1241 1242 1243 1244
    void SetViewIndex(int16_t index)
    {
        index_ = index;
    }
M
mamingshuai 已提交
1245 1246 1247 1248 1249 1250 1251

    /**
     * @brief Obtains the view index.
     * @return Returns the view index.
     * @since 1.0
     * @version 1.0
     */
P
pssea 已提交
1252 1253 1254 1255
    int16_t GetViewIndex() const
    {
        return index_;
    }
M
mamingshuai 已提交
1256 1257 1258 1259 1260 1261 1262

    /**
     * @brief Obtains the view type.
     * @return Returns the view type.
     * @since 1.0
     * @version 1.0
     */
P
pssea 已提交
1263 1264 1265 1266
    virtual UIViewType GetViewType() const
    {
        return UI_NUMBER_MAX;
    }
M
mamingshuai 已提交
1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450

    /**
     * @brief Lays out all child views according to the preset arrangement mode.
     * @param needInvalidate Specifies whether to refresh the invalidated area after the layout is complete.
     *                       Value <b>true</b> means to refresh the invalidated area after the layout is complete,
     *                       and <b>false</b> means the opposite.
     * @since 1.0
     * @version 1.0
     */
    virtual void LayoutChildren(bool neeInvalidate = false) {}

    /**
     * @brief Lays out the view in the center of the parent view.
     * @param xOffset Indicates the offset added to the x-axis after the view is placed. A positive number indicates
     *                the offset to the right, and a negative number indicates the offset to the left.
     * @param yOffset Indicates the offset added to the y-axis after the view is placed. A positive number indicates
     *                the offset to the bottom, and a negative number indicates the offset to the top.
     * @since 1.0
     * @version 1.0
     */
    void LayoutCenterOfParent(int16_t xOffSet = 0, int16_t yOffset = 0);

    /**
     * @brief Lays out the view on the left of the parent view.
     * @param offset Indicates the offset added to the x-axis after the view is placed. A positive number indicates
     *               the offset to the right, and a negative number indicates the offset to the left.
     * @since 1.0
     * @version 1.0
     */
    void LayoutLeftOfParent(int16_t offset = 0);

    /**
     * @brief Lays out the view on the right of the parent view.
     * @param offset Indicates the offset added to the x-axis after the view is placed. A positive number indicates
     *               the offset to the left, and a negative number indicates the offset to the right.
     * @since 1.0
     * @version 1.0
     */
    void LayoutRightOfParent(int16_t offset = 0);

    /**
     * @brief Lays out the view on the top of the parent view.
     * @param offset Indicates the offset added to the y-axis after the view is placed. A positive number indicates
     *               the offset to the bottom, and a negative number indicates the offset to the top.
     * @since 1.0
     * @version 1.0
     */
    void LayoutTopOfParent(int16_t offset = 0);

    /**
     * @brief Lays out the view on the bottom of the parent view.
     * @param offset Indicates the offset added to the y-axis after the view is placed. A positive number indicates
     *               the offset to the top, and a negative number indicates the offset to the bottom.
     * @since 1.0
     * @version 1.0
     */
    void LayoutBottomOfParent(int16_t offset = 0);

    /**
     * @brief Aligns the view with the left of a sibling view.
     * @param id Indicates the pointer to the ID of the sibling view.
     * @param offset Indicates the offset added to the x-axis after the view is placed. A positive number indicates
     *               the offset to the right, and a negative number indicates the offset to the left.
     * @since 1.0
     * @version 1.0
     */
    void AlignLeftToSibling(const char* id, int16_t offset = 0);

    /**
     * @brief Aligns the view with the right of a sibling view.
     * @param id Indicates the pointer to the ID of the sibling view.
     * @param offset Indicates the offset added to the x-axis after the view is placed. A positive number indicates
     *               the offset to the left, and a negative number indicates the offset to the right.
     * @since 1.0
     * @version 1.0
     */
    void AlignRightToSibling(const char* id, int16_t offset = 0);

    /**
     * @brief Aligns the view with the top of a sibling view.
     * @param id Indicates the pointer to the ID of the sibling view.
     * @param offset Indicates the offset added to the y-axis after the view is placed. A positive number indicates
     *               the offset to the bottom, and a negative number indicates the offset to the top.
     * @since 1.0
     * @version 1.0
     */
    void AlignTopToSibling(const char* id, int16_t offset = 0);

    /**
     * @brief Aligns the view with the bottom of a sibling view.
     * @param id Indicates the pointer to the ID of the sibling view.
     * @param offset Indicates the offset added to the y-axis after the view is placed. A positive number indicates
     *               the offset to the top, and a negative number indicates the offset to the bottom.
     * @since 1.0
     * @version 1.0
     */
    void AlignBottomToSibling(const char* id, int16_t offset = 0);

    /**
     * @brief Aligns the view with the center of a sibling view in the x-axis.
     * @param id Indicates the pointer to the ID of the sibling view.
     * @param offset Indicates the offset added to the x-axis after the view is placed. A positive number indicates
     *               the offset to the right, and a negative number indicates the offset to the left.
     * @since 1.0
     * @version 1.0
     */
    void AlignHorCenterToSibling(const char* id, int16_t offset = 0);

    /**
     * @brief Aligns the view with the center of a sibling view in the y-axis.
     * @param id Indicates the pointer to the ID of the sibling view.
     * @param offset Indicates the offset added to the y-axis after the view is placed. A positive number indicates
     *               the offset to the bottom, and a negative number indicates the offset to the top.
     * @since 1.0
     * @version 1.0
     */
    void AlignVerCenterToSibling(const char* id, int16_t offset = 0);

    /**
     * @brief Lays out the view on the left of a sibling view.
     * @param id Indicates the pointer to the ID of the sibling view.
     * @param offset Indicates the offset added to the x-axis after the view is placed. A positive number indicates
     *               the offset to the left, and a negative number indicates the offset to the right.
     * @since 1.0
     * @version 1.0
     */
    void LayoutLeftToSibling(const char* id, int16_t offset = 0);

    /**
     * @brief Lays out the view on the right of a sibling view.
     * @param id Indicates the pointer to the ID of the sibling view.
     * @param offset Indicates the offset added to the x-axis after the view is placed. A positive number indicates
     *               the offset to the right, and a negative number indicates the offset to the left.
     * @since 1.0
     * @version 1.0
     */
    void LayoutRightToSibling(const char* id, int16_t offset = 0);

    /**
     * @brief Lays out the view on the above of a sibling view.
     * @param id Indicates the pointer to the ID of the sibling view.
     * @param offset Indicates the offset added to the y-axis after the view is placed. A positive number indicates
     *               the offset to the top, and a negative number indicates the offset to the bottom.
     * @since 1.0
     * @version 1.0
     */
    void LayoutTopToSibling(const char* id, int16_t offset = 0);

    /**
     * @brief Lays out the view on the below of a sibling view.
     * @param id Indicates the pointer to the ID of the sibling view.
     * @param offset Indicates the offset added to the y-axis after the view is placed. A positive number indicates
     *               the offset to the bottom, and a negative number indicates the offset to the top.
     * @since 1.0
     * @version 1.0
     */
    void LayoutBottomToSibling(const char* id, int16_t offset = 0);

    /**
     * @brief Sets the view style.
     * @param style Indicates the view style.
     * @since 1.0
     * @version 1.0
     */
    virtual void SetStyle(Style& style);

    /**
     * @brief Sets a style.
     *
     * @param key Indicates the key of the style to set.
     * @param value Indicates the value matching the key.
     * @since 1.0
     * @version 1.0
     */
    virtual void SetStyle(uint8_t key, int64_t value);

    /**
     * @brief Obtains the value of a style.
     *
     * @param key Indicates the key of the style.
     * @return Returns the value of the style.
     * @since 1.0
     * @version 1.0
     */
P
pssea 已提交
1451 1452 1453 1454
    virtual int64_t GetStyle(uint8_t key) const
    {
        return style_->GetStyle(key);
    }
M
mamingshuai 已提交
1455 1456 1457 1458 1459 1460 1461 1462

    /**
     * @brief Obtains the view style. This function applies to scenarios where the style does not need to be modified,
     *        which saves memory.
     * @return Returns the view style.
     * @since 1.0
     * @version 1.0
     */
P
pssea 已提交
1463 1464 1465 1466
    const Style& GetStyleConst() const
    {
        return *style_;
    }
M
mamingshuai 已提交
1467 1468 1469 1470 1471 1472 1473 1474

    /**
     * @brief Sets the opacity for the view.
     *
     * @param opaScale Indicates the opacity to set.
     * @since 1.0
     * @version 1.0
     */
P
pssea 已提交
1475 1476 1477 1478
    void SetOpaScale(uint8_t opaScale)
    {
        opaScale_ = opaScale;
    }
M
mamingshuai 已提交
1479 1480 1481 1482 1483 1484 1485 1486

    /**
     * @brief Obtains the view opacity.
     *
     * @return Returns the view opacity.
     * @since 1.0
     * @version 1.0
     */
P
pssea 已提交
1487 1488 1489 1490
    uint8_t GetOpaScale() const
    {
        return opaScale_;
    }
M
mamingshuai 已提交
1491 1492 1493 1494 1495 1496 1497 1498 1499

    /**
     * @brief Obtains the extra message about a <b>UIView</b> instance. This field is ignored by the graphics
     *        framework and can be anything you set.
     *
     * @return Returns the pointer to the extra message about the <b>UIView</b> instance.
     * @since 5.0
     * @version 3.0
     */
P
pssea 已提交
1500 1501 1502 1503
    ViewExtraMsg* GetExtraMsg()
    {
        return viewExtraMsg_;
    }
M
mamingshuai 已提交
1504 1505 1506 1507 1508 1509 1510 1511 1512

    /**
     * @brief Sets the extra message about a <b>UIView</b> instance. This field is ignored by the graphics
     *        framework and can be anything you set.
     *
     * @param extraMsg Indicates the extra message to set.
     * @since 5.0
     * @version 3.0
     */
P
pssea 已提交
1513 1514 1515 1516
    void SetExtraMsg(ViewExtraMsg* extraMsg)
    {
        viewExtraMsg_ = extraMsg;
    }
M
mamingshuai 已提交
1517 1518

    /**
L
liqiang 已提交
1519
     * @brief Rotates the view in 2d.
M
mamingshuai 已提交
1520 1521 1522 1523 1524 1525 1526 1527
     * @param angle Indicates the rotation angle.
     * @param pivot Indicates the coordinates of the rotation pivot.
     * @since 5.0
     * @version 3.0
     */
    void Rotate(int16_t angle, const Vector2<float>& pivot);

    /**
L
liqiang 已提交
1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538
     * @brief Rotates the view in 3d.
     * @param angle Indicates the rotation angle.
     * @param pivotStart Indicates the coordinates of the rotation start pivot.
     * @param pivotEnd Indicates the coordinates of the rotation end pivot.
     * @since 5.0
     * @version 3.0
     */
    void Rotate(int16_t angle, const Vector3<float>& pivotStart, const Vector3<float>& pivotEnd);

    /**
     * @brief Scales the view in 2d.
M
mamingshuai 已提交
1539 1540 1541 1542 1543 1544 1545 1546
     *
     * @param scale Indicates the scale factor on x- and y- axes.
     * @param pivot Indicates the scaling pivot.
     * @since 5.0
     * @version 3.0
     */
    void Scale(const Vector2<float>& scale, const Vector2<float>& pivot);

L
liqiang 已提交
1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570
    /**
     * @brief Scales the view in 3d.
     *
     * @param scale Indicates the scale factor on x- and y- axes.
     * @param pivot Indicates the scaling pivot.
     * @since 5.0
     * @version 3.0
     */
    void Scale(const Vector3<float>& scale, const Vector3<float>& pivot);

    /**
     * @brief Shears the view in 3d.
     *
     * @param shearX Indicates the shear parameters around x- axes,
     *               which means many it shears in y and z direction(current invalid).
     * @param shearY Indicates the shear parameters around y- axes,
     *               which means many it shears in x and z direction(current invalid).
     * @param shaerZ Indicates the shear parameters around z- axes,
     *               which means many it shears in x and y.
     * @since 5.0
     * @version 3.0
     */
    void Shear(const Vector2<float>& shearX, const Vector2<float>& shearY, const Vector2<float>& shearZ);

M
mamingshuai 已提交
1571 1572
    void Translate(const Vector2<int16_t>& trans);

L
liqiang 已提交
1573 1574
    void Translate(const Vector3<int16_t>& trans);

M
mamingshuai 已提交
1575 1576
    bool IsTransInvalid();

L
liqiang 已提交
1577 1578 1579 1580
    void SetCameraDistance(int16_t distance);

    void SetCameraPosition(const Vector2<float>& position);

M
mamingshuai 已提交
1581 1582 1583 1584
    void ResetTransParameter();

#if ENABLE_ROTATE_INPUT
    /**
Y
YueBiang 已提交
1585
     * @brief Requests the focus on the view.
M
mamingshuai 已提交
1586 1587 1588 1589 1590 1591 1592
     *
     * @since 5.0
     * @version 3.0
     */
    virtual void RequestFocus();

    /**
Y
YueBiang 已提交
1593
     * @brief Clears the focus on the view.
M
mamingshuai 已提交
1594 1595 1596 1597 1598 1599
     *
     * @since 5.0
     * @version 3.0
     */
    virtual void ClearFocus();
#endif
S
suyue 已提交
1600 1601 1602 1603 1604 1605 1606 1607
#if ENABLE_FOCUS_MANAGER
    /**
     * @brief 设置视图是否可获焦.
     *
     * @param focusable 是否可获焦.
     * @since 5.0
     * @version 3.0
     */
P
pssea 已提交
1608 1609 1610 1611
    void SetFocusable(bool focusable)
    {
        focusable_ = focusable;
    }
S
suyue 已提交
1612 1613 1614 1615 1616 1617 1618 1619

    /**
     * @brief 获取视图是否可获焦.
     *
     * @return 是否可获焦.
     * @since 5.0
     * @version 3.0
     */
P
pssea 已提交
1620 1621 1622 1623
    bool IsFocusable() const
    {
        return focusable_;
    }
S
suyue 已提交
1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654

    /**
     * @brief 组件获焦响应
     *
     * @since 5.0
     * @version 3.0
     */
    void Focus();

    /**
     * @brief 组件失焦响应
     *
     * @since 5.0
     * @version 3.0
     */
    void Blur();

    /**
     * @brief 焦点改变事件监听类,开发者需要向视图组件注册该类实现事件的监听.
     *
     * @since 5.0
     * @version 3.0
     */
    class OnFocusListener : public HeapBase {
    public:
        /**
         * @brief 回调函数,视图获焦时触发.
         * @param view 获焦的视图
         * @since 5.0
         * @version 3.0
         */
P
pssea 已提交
1655 1656 1657 1658
        virtual bool OnFocus(UIView& view)
        {
            return false;
        }
S
suyue 已提交
1659 1660 1661 1662 1663 1664 1665

        /**
         * @brief 回调函数,视图失焦时触发.
         * @param view 失焦的视图
         * @since 5.0
         * @version 3.0
         */
P
pssea 已提交
1666 1667 1668 1669
        virtual bool OnBlur(UIView& view)
        {
            return false;
        }
S
suyue 已提交
1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684

        /**
         * @brief 析构函数.
         * @since 5.0
         * @version 3.0
         */
        virtual ~OnFocusListener() {}
    };

    /**
     * @brief 设置当前视图焦点改变事件监听者.
     * @param onFocusListener 焦点改变事件监听者.
     * @since 5.0
     * @version 3.0
     */
P
pssea 已提交
1685 1686 1687 1688
    void SetOnFocusListener(OnFocusListener* onFocusListener)
    {
        onFocusListener_ = onFocusListener;
    }
S
suyue 已提交
1689 1690 1691 1692 1693 1694 1695

    /**
     * @brief 获取当前视图焦点改变事件监听者.
     * @return 焦点改变事件监听者.
     * @since 5.0
     * @version 3.0
     */
P
pssea 已提交
1696 1697 1698 1699
    OnFocusListener* GetOnFocusListener() const
    {
        return onFocusListener_;
    }
S
suyue 已提交
1700
#endif
M
mamingshuai 已提交
1701

1702 1703 1704 1705 1706 1707 1708
    /**
     * @brief 获取当前视图的bitmap截图.请注意该接口会申请内存,请在需要释放时使用{@link ImageCacheFree()}接口.
     * @param info bitmap存储对象,获取的截图将被存到该引用中.
     * @return bitmap是否获取成功.
     * @since 5.0
     * @version 3.0
     */
1709 1710
    bool GetBitmap(ImageInfo& bitmap);

L
liqiang 已提交
1711 1712
    bool IsOnViewTree();

M
mamingshuai 已提交
1713 1714 1715 1716 1717 1718 1719 1720 1721
protected:
    bool touchable_ : 1;
    bool visible_ : 1;
    bool draggable_ : 1;
    bool dragParentInstead_ : 1;
    bool isViewGroup_ : 1;
    bool needRedraw_ : 1;
    bool styleAllocFlag_ : 1;
    bool isIntercept_ : 1;
S
suyue 已提交
1722 1723 1724
#if ENABLE_FOCUS_MANAGER
    bool focusable_ : 1;
#endif
M
mamingshuai 已提交
1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735
    uint8_t opaScale_;
    int16_t index_;
    const char* id_;
    UIView* parent_;
    UIView* nextSibling_;
    Style* style_;
    TransformMap* transMap_;
    OnClickListener* onClickListener_;
    OnLongPressListener* onLongPressListener_;
    OnDragListener* onDragListener_;
    OnTouchListener* onTouchListener_;
S
suyue 已提交
1736 1737 1738
#if ENABLE_FOCUS_MANAGER
    OnFocusListener* onFocusListener_;
#endif
M
mamingshuai 已提交
1739 1740 1741 1742 1743
#if ENABLE_ROTATE_INPUT
    OnRotateListener* onRotateListener_;
#endif
    ViewExtraMsg* viewExtraMsg_;

L
l00417912 已提交
1744
    uint8_t GetMixOpaScale() const;
M
mamingshuai 已提交
1745
    bool IsInvalid(float percent);
P
pssea 已提交
1746
    void DrawViewBounds(BufferInfo& gfxDstBuffer, const Rect& invalidatedArea);
1747
    void UpdateRectInfo(uint8_t key, const Rect& rect);
M
mamingshuai 已提交
1748 1749 1750 1751 1752 1753 1754 1755

private:
    Rect rect_;
    Rect* visibleRect_;
    void SetupThemeStyles();
};
} // namespace OHOS
#endif // GRAPHIC_LITE_UI_VIEW_H