1e41f4b71Sopenharmony_ci# Overview of Small-System Graphics 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ci## Overview 4e41f4b71Sopenharmony_ciThe small-system graphics framework, a lightweight graphics framework, includes lightweight UI components, animations, events, 2D graphics libraries, font layout engines, multi-backend rendering, and window manager modules. It is mainly used for UI display on small-system devices with screens, such as sports watches and smart home devices. 5e41f4b71Sopenharmony_ci 6e41f4b71Sopenharmony_ci### Relationship Between UIs in OpenHarmony 7e41f4b71Sopenharmony_ciYou may have learned different development paradigms of OpenHarmony. What is the relationship between them and the small-system graphics framework? 8e41f4b71Sopenharmony_ci 9e41f4b71Sopenharmony_ciCurrently, the [ace_engine repository](https://gitee.com/openharmony/arkui_ace_engine) implements two development frameworks: ArkUI declarative development paradigm and ArkUI web-like development paradigm. For details about their differences, see [ArkUI Overview](../../application-dev/ui/arkui-overview.md). Based on the characteristics of the small system, the [ace_engine_lite repository](https://gitee.com/openharmony/arkui_ace_engine_lite) implements the lightweight ArkUI web-like development paradigm, which is named ArkUI web-like development paradigm lite. Its capabilities are a subset of the ArkUI web-like development paradigm. 10e41f4b71Sopenharmony_ci 11e41f4b71Sopenharmony_ciOpenHarmony supports the following development modes by system type: 12e41f4b71Sopenharmony_ci- Standard system: 13e41f4b71Sopenharmony_ci - ArkUI declarative development paradigm (recommended) 14e41f4b71Sopenharmony_ci - ArkUI web-like development paradigm 15e41f4b71Sopenharmony_ci- Small system: 16e41f4b71Sopenharmony_ci - ArkUI web-like development paradigm lite 17e41f4b71Sopenharmony_ci - C++ development (for system applications) 18e41f4b71Sopenharmony_ci 19e41f4b71Sopenharmony_ciThe figure below shows the code implementation relationship between [ui_lite](https://gitee.com/openharmony/arkui_ui_lite), [ace_engine_lite](https://gitee.com/openharmony/arkui_ace_engine_lite), and [ace_engine](https://gitee.com/openharmony/arkui_ace_engine) in the small-system graphics framework. 20e41f4b71Sopenharmony_ci 21e41f4b71Sopenharmony_ci 22e41f4b71Sopenharmony_ci 23e41f4b71Sopenharmony_ciWhen determining the API suite used for your application development, preferentially select the ArkUI declarative development paradigm for the standard system and the ArkUI web-like development paradigm lite for the small system. When developing a system application on devices with low configurations, you can use C++ APIs for higher performance and better flexibility. 24e41f4b71Sopenharmony_ci 25e41f4b71Sopenharmony_ci 26e41f4b71Sopenharmony_ci### UI Components 27e41f4b71Sopenharmony_ciThe small-system graphics framework implements basic components, such as button, text, and progress bar. 28e41f4b71Sopenharmony_ci 29e41f4b71Sopenharmony_ciIt also provides complex components such as list, swiper, and image sequence frame. 30e41f4b71Sopenharmony_ci 31e41f4b71Sopenharmony_ci### Layouts 32e41f4b71Sopenharmony_ciThe framework implements grid layout and flexible layout (such as centered, left-aligned, and right-aligned). 33e41f4b71Sopenharmony_ci 34e41f4b71Sopenharmony_ciAs each layout is a one-off, the positions of components in a specific layout are calculated each time related functions are called on the layout. However, if the position of a component changes with an operation (dragging for example), the positions of other associated components do not automatically change. 35e41f4b71Sopenharmony_ci 36e41f4b71Sopenharmony_ci### Animations 37e41f4b71Sopenharmony_ciThe framework supports custom animations. All animations are managed by AnimatorManager. Based on the screen refresh event, AnimatorManager periodically calls the callback functions to process attribute changes and then triggers component re-rendering to achieve the animation effect. 38e41f4b71Sopenharmony_ci 39e41f4b71Sopenharmony_ciYou can call related functions to start, stop, pause, resume, create, and destroy an animation. 40e41f4b71Sopenharmony_ci 41e41f4b71Sopenharmony_ci### Events 42e41f4b71Sopenharmony_ciInput events include touchscreen and physical key input events. Each time the GUI engine runs, InputManager reads the input of all registered hardware devices and converts the input into various events for UI components to use. 43e41f4b71Sopenharmony_ci 44e41f4b71Sopenharmony_ci### Rendering 45e41f4b71Sopenharmony_ci2D graphics rendering: Draws lines, rectangles, triangles, and arcs. 46e41f4b71Sopenharmony_ci 47e41f4b71Sopenharmony_ciImage rendering: Draws images of various types, such as RGB565, RGB888, ARGB8888, PNG, and JPG. 48e41f4b71Sopenharmony_ci 49e41f4b71Sopenharmony_ciFont rendering: Draws vector fonts in real time. 50e41f4b71Sopenharmony_ci 51e41f4b71Sopenharmony_ci## Implementation Principles 52e41f4b71Sopenharmony_ci 53e41f4b71Sopenharmony_ciIn the small-system graphics framework, the task queue is driven by the screen refresh signal. The task queue stores every task. A periodic screen refresh signal triggers a periodic callback to cyclically drive the execution of a task in the task queue. Operations such as input events, animations, and rendering are executed as independent tasks. 54e41f4b71Sopenharmony_ci 55e41f4b71Sopenharmony_ci### Event Interaction 56e41f4b71Sopenharmony_ci 57e41f4b71Sopenharmony_ciThe small-system graphics framework supports the touch event (PointerInputDevice), key event (KeyInputDevice), and crown rotation event (RotateInputDevice). 58e41f4b71Sopenharmony_ci 59e41f4b71Sopenharmony_ci```mermaid 60e41f4b71Sopenharmony_ciclassDiagram 61e41f4b71Sopenharmony_ci 62e41f4b71Sopenharmony_ciclass InputDevice { 63e41f4b71Sopenharmony_ci +Read(DeviceData& data): bool 64e41f4b71Sopenharmony_ci} 65e41f4b71Sopenharmony_ci 66e41f4b71Sopenharmony_ciclass PointerInputDevice { 67e41f4b71Sopenharmony_ci +Read(DeviceData& data): bool 68e41f4b71Sopenharmony_ci} 69e41f4b71Sopenharmony_ci 70e41f4b71Sopenharmony_ciclass RotateInputDevice { 71e41f4b71Sopenharmony_ci +Read(DeviceData& data): bool 72e41f4b71Sopenharmony_ci} 73e41f4b71Sopenharmony_ci 74e41f4b71Sopenharmony_ciclass KeyInputDevice { 75e41f4b71Sopenharmony_ci +Read(DeviceData& data): bool 76e41f4b71Sopenharmony_ci} 77e41f4b71Sopenharmony_ci 78e41f4b71Sopenharmony_ci 79e41f4b71Sopenharmony_ciclass InputManager { 80e41f4b71Sopenharmony_ci -deviceList_: List<InputDevice*> 81e41f4b71Sopenharmony_ci} 82e41f4b71Sopenharmony_ci 83e41f4b71Sopenharmony_ciInputDevice <|-- PointerInputDevice 84e41f4b71Sopenharmony_ciInputDevice <|-- RotateInputDevice 85e41f4b71Sopenharmony_ciInputDevice <|-- KeyInputDevice 86e41f4b71Sopenharmony_ciTask <|-- InputManager 87e41f4b71Sopenharmony_ciInputManager *-- InputDevice 88e41f4b71Sopenharmony_ci``` 89e41f4b71Sopenharmony_ci 90e41f4b71Sopenharmony_ciThe figure above shows the input event classes. Each type of input event overrides the **Read** function of the **InputDevice** base class based on its own features, reads input data, generates an event based on the input data, and distributes the event to the corresponding UI component. For example, **PointerInputDevice** reads the touch coordinates, searches for the component corresponding to the coordinates from the component tree, generates a touch, touch and hold, or drag event, and distributes the event to that component. 91e41f4b71Sopenharmony_ci 92e41f4b71Sopenharmony_ci### Animation Framework 93e41f4b71Sopenharmony_ci 94e41f4b71Sopenharmony_ci```mermaid 95e41f4b71Sopenharmony_ciclassDiagram 96e41f4b71Sopenharmony_ci 97e41f4b71Sopenharmony_ciclass AnimatorCallback { 98e41f4b71Sopenharmony_ci +Callback(UIView* view): void 99e41f4b71Sopenharmony_ci} 100e41f4b71Sopenharmony_ci 101e41f4b71Sopenharmony_ciclass Animator { 102e41f4b71Sopenharmony_ci +Start(): void 103e41f4b71Sopenharmony_ci +Stop(): void 104e41f4b71Sopenharmony_ci -callback_: AnimatorCallback* 105e41f4b71Sopenharmony_ci} 106e41f4b71Sopenharmony_ci 107e41f4b71Sopenharmony_ciclass AnimatorManager { 108e41f4b71Sopenharmony_ci -list_: List<Animator*> 109e41f4b71Sopenharmony_ci} 110e41f4b71Sopenharmony_ci 111e41f4b71Sopenharmony_ciTask <|-- AnimatorManager 112e41f4b71Sopenharmony_ciAnimatorManager *-- Animator 113e41f4b71Sopenharmony_ciAnimator *-- AnimatorCallback 114e41f4b71Sopenharmony_ci``` 115e41f4b71Sopenharmony_ci 116e41f4b71Sopenharmony_ciTo implement a custom animation, you need to inherit from the **Animator** class and implement the callback function of **AnimatorCallback**. All animations are managed by **AnimatorManager** in a unified manner. The input parameter of the callback function is **view** (component) of the current animation. You can modify the component attributes to generate the animation effect, such as the coordinate change, color change, and zoom effect. 117e41f4b71Sopenharmony_ci 118e41f4b71Sopenharmony_ci### Rendering Framework 119e41f4b71Sopenharmony_ci 120e41f4b71Sopenharmony_ci```mermaid 121e41f4b71Sopenharmony_ciclassDiagram 122e41f4b71Sopenharmony_ci 123e41f4b71Sopenharmony_ciclass WindowImpl { 124e41f4b71Sopenharmony_ci Render: void 125e41f4b71Sopenharmony_ci} 126e41f4b71Sopenharmony_ci 127e41f4b71Sopenharmony_ciclass UIView { 128e41f4b71Sopenharmony_ci OnDraw: void 129e41f4b71Sopenharmony_ci Invalidate : void 130e41f4b71Sopenharmony_ci} 131e41f4b71Sopenharmony_ci 132e41f4b71Sopenharmony_ciclass RootView { 133e41f4b71Sopenharmony_ci Measure: void 134e41f4b71Sopenharmony_ci Render : void 135e41f4b71Sopenharmony_ci} 136e41f4b71Sopenharmony_ci 137e41f4b71Sopenharmony_ciclass RenderManager { 138e41f4b71Sopenharmony_ci +Callback: void 139e41f4b71Sopenharmony_ci -winList_: List<Window*> 140e41f4b71Sopenharmony_ci} 141e41f4b71Sopenharmony_ci 142e41f4b71Sopenharmony_ciTask <|-- RenderManager 143e41f4b71Sopenharmony_ciWindow <|-- WindowImpl 144e41f4b71Sopenharmony_ciUIView <|-- RootView 145e41f4b71Sopenharmony_ciWindowImpl *-- RootView 146e41f4b71Sopenharmony_ciRenderManager *-- Window 147e41f4b71Sopenharmony_ci``` 148e41f4b71Sopenharmony_ci 149e41f4b71Sopenharmony_ci - Each window has a **RootView**. 150e41f4b71Sopenharmony_ci - **RootView** is the root node of a window. All components in a window can be displayed only after being mounted to **RootView**. 151e41f4b71Sopenharmony_ci - **UIView** is the base class of all components. Each component implements its own **OnDraw** function. 152e41f4b71Sopenharmony_ci - When the display of a component changes, the **Invalidate** function is called to mark the current area as a dirty area. 153e41f4b71Sopenharmony_ci - **RootView** manages information about all dirty areas in a window. 154e41f4b71Sopenharmony_ci - Each time a screen refresh signal is triggered, all windows are traversed and rendered. For each window, the **Measure** function is called for layout from **RootView**, and then the **Render** function is called to render the components in all the dirty areas. 155