对象 (Obj)

对象控件实现了屏幕上控件的基本属性。屏幕控件是控件树的根节点。极坐标的原点在 Y 轴的负方向,极坐标的正方向为顺时针方向,屏幕坐标系设置如下所示。



用法

Gui_Obj 表格

描述

API

构建控件

gui_obj_ctor

创建控件

gui_obj_create()

添加事件

gui_obj_add_event_cb

设置事件

gui_obj_enable_event

释放树(从根节点到叶节点,递归地释放控件树)

gui_obj_tree_free

打印树(从根节点到叶节点,递归地打印控件树)

gui_obj_tree_print

获取树中某种类型控件的数量

gui_obj_tree_count_by_type

隐藏/显示

gui_obj_tree_show

能否显示

gui_obj_show()

获取根节点

gui_obj_tree_get_root

获取子节点

gui_obj_get_child_handle

判断是否在矩形范围内

gui_obj_in_rect()

跳过父对象控件的所有操作(左/右/下/上拖动保持动作)

  • gui_obj_skip_all_parent_left_hold

  • gui_obj_skip_all_parent_right_hold

  • gui_obj_skip_all_parent_down_hold

  • gui_obj_skip_all_parent_up_hold

跳过子对象控件的所有操作(左/右/下/上拖动保持动作)

  • gui_obj_skip_all_child_left_hold

  • gui_obj_skip_all_child_right_hold

  • gui_obj_skip_all_child_down_hold

  • gui_obj_skip_all_child_up_hold

跳过其他对象控件的所有操作(左/右/下/上拖动保持动作)

  • gui_obj_skip_other_left_hold

  • gui_obj_skip_other_right_hold

  • gui_obj_skip_other_down_hold

  • gui_obj_skip_other_up_hold

获取显示区域

gui_obj_get_area()

矩形范围内的点检测

gui_obj_point_in_obj_rect()

CRC校验

gui_obj_checksum()

通过名称在树中获取控件

gui_obj_tree_get_widget_by_name

通过类型在树中获取控件

gui_obj_tree_get_widget_by_type

刷新动画效果

animate_frame_update

设定动画效果

gui_obj_set_animate

以广度优先搜索的方式打印树

gui_obj_tree_print_bfs

API

Functions

gui_obj_t *gui_obj_get_root(void)

Get the root GUI object.

This function returns a pointer to the root GUI object in the widget tree.

返回:

A pointer to the root GUI object.

gui_obj_t *gui_obj_get_fake_root(void)

Get the fake_root GUI object, which would not be drawn.

This function returns a pointer to the fake_root GUI object in the widget tree.

返回:

A pointer to the fake_root GUI object.

gui_obj_t *gui_obj_create(void *parent, const char *name, int16_t x, int16_t y, int16_t w, int16_t h)

creat an obj widget.

参数:
  • parent – the father widget it nested in.

  • filename – the obj widget name.

  • x – the X-axis coordinate of the widget.

  • y – the Y-axis coordinate of the widget.

  • w – the width of the widget.

  • h – the hight of the widget.

返回:

gui_obj_t*.

void gui_obj_show(void *obj, bool enable)

set object show or not.

参数:
  • obj – the root of the widget tree.

  • enable – true for show, false for hide.

    • Example usage

      static void app_main_task(gui_app_t *app)
      {
          gui_img_t *hour;
          gui_obj_show(hour,false);
          gui_obj_show(hour,true);
      
      }
      

bool gui_obj_out_screen(gui_obj_t *obj)

judge the obj if out of screen.

void gui_obj_get_clip_rect(gui_obj_t *obj, gui_rect_t *rect)

Calculate the clipping rectangle of a GUI object relative to its top-level ancestor.

参数:
  • obj – The GUI object for which the clipping rectangle is calculated.

  • rect – The output rectangle that will contain the calculated clipping area.

bool gui_obj_in_rect(gui_obj_t *obj, int16_t x, int16_t y, int16_t w, int16_t h)

judge the obj if in range of this_widget rect.

参数:
  • obj – pointer to the GUI object.

  • x – the X-axis coordinate of the widget.

  • y – the Y-axis coordinate of the widget.

  • w – the width of the widget.

  • h – the hight of the widget.

返回:

true.

返回:

false.

void gui_obj_enable_this_parent_short(gui_obj_t *obj)

enable all short click actions from parent object to the root object.

enable all long press actions from parent object to the root object.

参数:

obj – the root of the widget tree.

void gui_obj_get_area(gui_obj_t *obj, int16_t *x, int16_t *y, int16_t *w, int16_t *h)

get the area of this_widget obj.

参数:
  • obj – pointer to the GUI object.

  • x – the X-axis coordinate of the widget.

  • y – the Y-axis coordinate of the widget.

  • w – the width of the widget.

  • h – the hight of the widget.

bool gui_obj_point_in_obj_rect(gui_obj_t *obj, int16_t x, int16_t y)

judge the point if in range of this_widget obj rect.

参数:
  • obj – widget object pointer.

  • x – the X-axis coordinate.

  • y – the Y-axis coordinate.

返回:

true.

返回:

false.

bool gui_obj_point_in_obj_circle(gui_obj_t *obj, int16_t x, int16_t y)

judge the point if in range of this_widget obj circle.

参数:
  • obj – widget object pointer.

  • x – the X-axis coordinate.

  • y – the Y-axis coordinate.

返回:

true.

返回:

false.

uint8_t gui_obj_checksum(uint8_t seed, uint8_t *data, uint8_t len)

do crc check.

参数:
  • seed – the initial value to start the checksum calculation.

  • data – pointer to the array of bytes for which the checksum is to be calculated.

  • len – the number of bytes in the array.

返回:

uint8_t.

gui_obj_t *gui_get_root(gui_obj_t *object)

print name by bfs order.

参数:

object – widget pointer.

返回:

gui_obj_t * root.

void gui_obj_absolute_xy(gui_obj_t *obj, int *absolute_x, int *absolute_y)

calculate the absolute coordinates of a GUI object.

This function calculates the absolute (global) X and Y coordinates of a given GUI object based on its local position within the parent hierarchy.

备注

This function assumes that obj is a valid pointer and that absolute_x and absolute_y are valid pointers to integers.

参数:
  • obj – pointer to the GUI object for which to calculate absolute coordinates.

  • absolute_x – pointer to an integer where the absolute X coordinate will be stored.

  • absolute_y – pointer to an integer where the absolute Y coordinate will be stored.

void gui_obj_hidden(gui_obj_t *obj, bool hidden)

set the visibility of a GUI object.

This function sets the visibility of a given GUI object by adjusting its hidden state.

参数:
  • obj – pointer to the GUI object that will be updated.

  • hidden – boolean flag indicating whether the object should be hidden (true) or shown (false).

const char *gui_widget_name(gui_obj_t *widget, const char *name)

set or retrieve the name of a GUI widget.

This function sets the name of a given GUI widget if the provided name is valid. It returns the current name of the widget.

参数:
  • widget – pointer to the GUI widget whose name will be set or retrieved.

  • name – pointer to a string containing the new name for the widget. If the name is valid, it will be set as the widget’s name.

返回:

the current name of the widget.

void gui_update_speed(int *speed, int speed_recode[])

update touch pad speed vertical.

This function updates the current speed and records the speed change history.

参数:
  • speed – pointer to the current speed, which will be updated by the function.

  • speed_recode – array to record speed changes, which will be updated by the function.

void gui_inertial(int *speed, int end_speed, int *offset)

inertial calculation.

This function performs inertial calculations based on the current speed, end speed, and offset.

参数:
  • speed – pointer to the current speed, which will be updated by the function.

  • end_speed – target end speed.

  • offset – pointer to the offset, which will be updated by the function.

uint32_t gui_get_obj_count(void)

get widget count.

void gui_set_location(gui_obj_t *obj, uint16_t x, uint16_t y)

Set the location of a GUI object.

This function sets the X and Y coordinates of the specified GUI object.

参数:
  • obj – Pointer to the GUI object to set location for.

  • x – The X coordinate to set.

  • y – The Y coordinate to set.

void gui_dom_create_tree_nest(const char *xml, gui_obj_t *parent_widget)

API to create a widget tree structure from an XML file and associate it with a parent widget.

参数:
  • xml – The path to the XML file to be parsed.

  • parent_widget – The parent widget to which the tree structure is to be associated.

char *gui_dom_get_preview_image_file(const char *xml)

Extracts the preview image file path from an XML file.

This function parses the given XML file and attempts to find the preview image file path by looking for specific tags within the XML.

参数:

xml_file – The path to the XML file to be parsed.

返回:

A string containing the path to the preview image file. If the XML file cannot be loaded or the preview image file path cannot be found, returns NULL.

void gui_update_speed_by_displacement(int *speed, int speed_recode[], int displacement)

Update the speed based on displacement.

This function updates the speed value based on the given displacement. It also uses a speed record array to achieve this.

参数:
  • speed – Pointer to the speed variable to update.

  • speed_recode – Array holding the speed records.

  • displacement – The displacement value to consider for speed update.

void gui_obj_move(gui_obj_t *obj, int x, int y)

Move a widget object to specified coordinates.

This function moves the specified widget object to a new (x, y) coordinate position.

参数:
  • obj – Pointer to the widget object to be moved.

  • x – The new x-coordinate for the widget object.

  • y – The new y-coordinate for the widget object.

void gui_obj_create_timer(gui_obj_t *obj, uint32_t interval, bool reload, void (*callback)(void*))

Set a timer for a GUI object.

This function sets a timer for the specified GUI object with a given interval. The timer can be configured to reload automatically or run only once. When the timer expires, the provided callback function is called.

参数:
  • obj – Pointer to the GUI object to set the timer for.

  • interval – The interval in milliseconds for the timer.

  • reload – Boolean flag indicating whether the timer should reload automatically (true) or run only once (false).

  • callback – Pointer to the callback function to be called when the timer expires.

void gui_obj_delete_timer(gui_obj_t *obj)
void gui_obj_start_timer(gui_obj_t *obj)
void gui_obj_stop_timer(gui_obj_t *obj)