窗口 (Win)

此控件为开发者提供了一个虚拟区域,用于放置应用程序所需的控件。开发者可以根据需求创建相对于屏幕的空间。 例如,图1创建了一个与屏幕尺寸相同的区域,而开发者也可以创建不同尺寸的空间,如图2所示。

https://foruda.gitee.com/images/1701081169144847122/2f0a8469_13671147.png
https://foruda.gitee.com/images/1701081183476854396/dec93062_13671147.png

下图中的控件将以窗口控件的左上角作为初始坐标。

https://foruda.gitee.com/images/1701081206134160709/80ae8874_13671147.png

使用方法

创建窗口控件

可以通过 gui_win_create() 函数创建一个窗口控件。

设定动画

开发者可以调用函数 gui_win_set_animate() 来设置动画并在相应的回调函数中实现动画效果。

注册回调函数

使用以下的函数来给窗口控件注册左/右/上/下滑动事件:gui_win_left() , gui_win_right() , gui_win_up() , gui_win_down()。 并且也可以使用以下的函数来给窗口控件注册按下/释放/长按/点击事件:gui_win_press() , gui_win_release() , gui_win_long() , gui_win_click()

设置触摸保持状态

使用函数 gui_win_hold_tp() 来设置触摸保持’hold_tp’的状态。

获取进度

通过函数 gui_win_get_animation_progress_percent() 来获取动画进度。

缩放设定

通过函数 gui_win_set_scale_rate() 设置窗口控件在水平方向和垂直方向的缩放比例。

允许/禁止

使用函数 gui_win_set_scope() 来设定允许或禁止窗口控件。

不透明度

可以使用函数 gui_win_set_opacity() 来设定窗口控件的不透明度。

动画检查

使用函数 gui_win_is_animation_end_frame() 来检查动画是否到了最后一帧。

启动动画

使用函数 gui_win_start_animation() 来启动动画。

停止动画

通过函数 gui_win_stop_animation() 来停止动画。

准备

窗口控件的准备处理函数 gui_win_prepare()

添加动画

使用函数 gui_win_append_animate() 将动画添加到GUI窗口。

API

Functions

gui_win_t *gui_win_create(void *parent, const char *name, int16_t x, int16_t y, int16_t w, int16_t h)

create a window widget.

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

  • filename – the window widget name.

  • x – the X-axis coordinate.

  • x – the Y-axis coordinate.

  • w – the width.

  • h – the hight.

返回:

return the widget object pointer

void gui_win_set_animate(gui_win_t *_this, uint32_t dur, int repeat_count, gui_animate_callback_t callback, void *p)

set animate.

参数:
  • _this – widget object pointer.

  • dur – animation duration.

  • repeat_count – repeat play times, -1 means play on repeat forever.

  • callback – animate frame callback.

  • p – parameter.

void gui_win_left(gui_win_t *_this, void *callback, void *parameter)

register a callback function for the left slide event of the win widget.

参数:
  • _this – win pointer.

  • callback – callback func.

  • parameter – callback parameter.

void gui_win_right(gui_win_t *_this, void *callback, void *parameter)

register a callback function for the right slide event of the win widget.

参数:
  • _this – win pointer.

  • callback – callback func.

  • parameter – callback parameter.

void gui_win_up(gui_win_t *_this, void *callback, void *parameter)

register a callback function for the up slide event of the win widget.

参数:
  • _this – win pointer.

  • callback – callback func.

  • parameter – callback parameter.

void gui_win_down(gui_win_t *_this, void *callback, void *parameter)

register a callback function for the down slide event of the win widget.

参数:
  • _this – win pointer.

  • callback – callback func.

  • parameter – callback parameter.

void gui_win_press(gui_win_t *_this, gui_event_cb_t callback, void *parameter)

register a callback function for the press event of the win widget.

参数:
  • _this – win pointer.

  • callback – callback func.

  • parameter – callback parameter.

void gui_win_release(gui_win_t *_this, gui_event_cb_t callback, void *parameter)

register a callback function for the release event of the win widget.

参数:
  • _this – win pointer.

  • callback – callback func (void *obj, gui_event_t e, void *param).

  • parameter – callback parameter.

void gui_win_long(gui_win_t *_this, void *callback, void *parameter)

register a callback function for a long press event of the win widget.

参数:
  • _this – win pointer.

  • callback – callback func.

  • parameter – callback parameter.

void gui_win_click(gui_win_t *_this, gui_event_cb_t callback, void *parameter)

register a callback function for a click event of the win widget.

参数:
  • _this – win pointer.

  • callback – callback func (void *obj, gui_event_t e, void *param).

  • parameter – callback parameter.

void gui_win_hold_tp(gui_win_t *_this, bool hold_tp)

set the hold_tp state.

参数:
  • _this – win pointer.

  • hold_tp – a boolean value to set the state to true or false.

float gui_win_get_animation_progress_percent(gui_win_t *win)

get the animation progress percentage.

参数:

win – pointer to the window structure that contains the animation.

返回:

the current animation progress percentage.

void gui_win_set_scale_rate(gui_win_t *win, float scale_rate_horizontal, float scale_rate_vertical)

set the scale rate for the window both horizontally and vertically.

参数:
  • win – pointer to the window structure.

  • scale_rate_horizontal – the horizontal scale rate.

  • scale_rate_vertical – the vertical scale rate.

void gui_win_set_scope(gui_win_t *win, bool enable)

enable or disable the scope for the window.

参数:
  • win – pointer to the window structure.

  • enable – a boolean value to enable or disable the scope.

void gui_win_set_opacity(gui_win_t *win, unsigned char opacity_value)

set the opacity value for the window.

参数:
  • win – pointer to the window structure.

  • opacity_value – the desired opacity value to set.

bool gui_win_is_animation_end_frame(gui_win_t *win)

check if the animation is at its end frame.

参数:

win – pointer to the window structure that contains the animation.

返回:

true if the end_frame is not 0, false otherwise.

void gui_win_start_animation(gui_win_t *win)

start the animation by setting the animate field to 1.

参数:

win – pointer to the window structure that contains the animation. If win or win->animate is NULL, the function will log an error message.

void gui_win_stop_animation(gui_win_t *win)

stop the animation by setting the animate field to 0.

参数:

win – pointer to the window structure that contains the animation. If win or win->animate is NULL, the function will log an error message.

void gui_win_prepare(gui_obj_t *obj)

window widget prepare.

参数:

obj – pointer.

void gui_win_append_animate(gui_win_t *win, uint32_t dur, int repeat_count, void *callback, void *p, const char *name)

append an animation to a GUI window.

This function appends an animation to the specified GUI window. The animation will run for the specified duration, repeat the specified number of times, and call the provided callback function at each frame.

备注

The callback function should match the expected signature for animation callbacks in the GUI library being used. The p parameter allows the passing of additional data to the callback function.

参数:
  • win – pointer to the GUI window object.

  • dur – duration of the animation in milliseconds.

  • repeat_count – number of times the animation should repeat.

  • callback – function to be called at each frame.

  • p – user data to be passed to the callback function.

  • name – aniamte name.

void gui_win_move(gui_win_t *win, int x, int y)

Move the GUI window to the specified coordinates.

This function repositions a GUI window to the specified (x, y) coordinates on the screen.

参数:
  • win – Pointer to the GUI window that needs to be moved.

  • x – The new x-coordinate for the window.

  • y – The new y-coordinate for the window.

int gui_win_get_x(gui_win_t *win)

Get the current x-coordinate of the GUI window.

This function returns the current x-coordinate of the specified GUI window.

参数:

win – Pointer to the GUI window.

返回:

The current x-coordinate of the window.

int gui_win_get_y(gui_win_t *win)

Get the current y-coordinate of the GUI window.

This function returns the current y-coordinate of the specified GUI window.

参数:

win – Pointer to the GUI window.

返回:

The current y-coordinate of the window.

struct gui_win_t

window structure

Public Members

gui_obj_t base
gui_animate_t *animate
gui_animate_t **animate_array
float scale
float scale_y
bool press_flag
bool long_flag
bool release_flag
bool enter_auto_scale
bool event5_flag
uint8_t checksum
bool scope
bool hold_tp
uint8_t animate_array_length