[English]

Image button (图像按钮)(lv_imagebutton)

Overview(概述)

显示原文

The Image button is very similar to the simple 'Button' object. The only difference is that it displays user-defined images in each state instead of drawing a rectangle.

You can set a left, right and center image, and the center image will be repeated to match the width of the object.


图像按钮与简单的 “Button” 对象非常相似。唯一的区别是,它在每个状态下显示用户定义的图像,而不是绘制矩形。

可以设置左、右和中心图像,中心图像将重复以匹配对象的宽度。

Parts and Styles(部分和样式)

显示原文
  • LV_PART_MAIN Refers to the image(s). If background style properties are used, a rectangle will be drawn behind the image button.


  • LV_PART_MAIN 指图像。如果使用背景样式属性,将在图像按钮后面绘制一个矩形。

Usage(用法)

Image sources(图片来源)

显示原文

To set the image in a state, use the lv_imagebutton_set_src(imagebutton, LV_IMAGEBUTTON_STATE_..., src_left, src_center, src_right).

The image sources work the same as described in the Image object except that "Symbols" are not supported by the Image button. Any of the sources can NULL.

If only src_center is specified, the width of the widget will be set automatically to the width of the image. However, if all three sources are set, the width needs to be set by the user (using e.g. lv_obj_set_width) and the center image will be tiled to fill the given size.

The possible states are:

If you set sources only in LV_IMAGEBUTTON_STATE_RELEASED, these sources will be used in other states too. If you set e.g. LV_IMAGEBUTTON_STATE_PRESSED they will be used in pressed state instead of the released images.


要将图像设置为某个状态,请使用 lv_imagebutton_set_src(imagebutton, LV_IMAGEBUTTON_STATE_..., src_left, src_center, src_right)

图像源的工作原理与 图片对象 中所述的相同,但是 "图像" 按钮不支持 "Symbols(符号)" 。任何源都可以为 NULL

如果只指定了 src_center ,则控件的宽度将自动设置为图像的宽度。但是,如果设置了所有三个源,则宽度需要由用户设置(例如使用 lv_obj_set_width ),并且中心图像将被平铺以填充给定的大小。

状态可以是:

如果只给状态 LV_IMAGEBUTTON_STATE_RELEASED 设置源,这些源也将在其他状态使用。如果设置了例如 LV_IMAGEBUTTON_STATE_PRESSED ,它们将在按下状态下使用图像源,而不是在 LV_IMAGEBUTTON_STATE_RELEASED 中使用。

States(状态)

显示原文

Instead of the regular lv_obj_add_state() and lv_obj_remove_state() functions, the lv_imagebutton_set_state(imagebutton, LV_IMAGEBUTTON_STATE_...) function should be used to manually set a state.


应使用 lv_imagebutton_set_state(imagebutton, LV_IMAGEBUTTON_STATE_...) 函数来手动设置状态,而不是常规的 lv_obj_add_state()lv_obj_remove_state() 函数。

Events(事件)

显示原文

Learn more about Events(事件).


详细了解更多阅读 Events(事件)

Keys(按键)

显示原文

Learn more about Keys(按键).


Example

API

lv_imagebutton.h

lv_types.h