LVGL 库提交
This commit is contained in:
@@ -0,0 +1,141 @@
|
||||
/**
|
||||
* @file lv_list.c
|
||||
*
|
||||
*/
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#include "../../core/lv_obj_class_private.h"
|
||||
#include "lv_list.h"
|
||||
#include "../../layouts/flex/lv_flex.h"
|
||||
#include "../../display/lv_display.h"
|
||||
#include "../label/lv_label.h"
|
||||
#include "../image/lv_image.h"
|
||||
#include "../button/lv_button.h"
|
||||
|
||||
#if LV_USE_LIST
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
#define MY_CLASS (&lv_list_class)
|
||||
#define MY_CLASS_BUTTON (&lv_list_button_class)
|
||||
#define MY_CLASS_TEXT (&lv_list_text_class)
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* STATIC PROTOTYPES
|
||||
**********************/
|
||||
const lv_obj_class_t lv_list_class = {
|
||||
.base_class = &lv_obj_class,
|
||||
.width_def = (LV_DPI_DEF * 3) / 2,
|
||||
.height_def = LV_DPI_DEF * 2,
|
||||
.name = "lv_list",
|
||||
};
|
||||
|
||||
const lv_obj_class_t lv_list_button_class = {
|
||||
.base_class = &lv_button_class,
|
||||
.width_def = LV_PCT(100),
|
||||
.height_def = LV_SIZE_CONTENT,
|
||||
.name = "lv_list_button",
|
||||
};
|
||||
|
||||
const lv_obj_class_t lv_list_text_class = {
|
||||
.base_class = &lv_label_class,
|
||||
.width_def = LV_PCT(100),
|
||||
.height_def = LV_SIZE_CONTENT,
|
||||
.name = "lv_list_text",
|
||||
};
|
||||
|
||||
/**********************
|
||||
* STATIC VARIABLES
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL FUNCTIONS
|
||||
**********************/
|
||||
|
||||
lv_obj_t * lv_list_create(lv_obj_t * parent)
|
||||
{
|
||||
LV_LOG_INFO("begin");
|
||||
lv_obj_t * obj = lv_obj_class_create_obj(MY_CLASS, parent);
|
||||
lv_obj_class_init_obj(obj);
|
||||
lv_obj_set_flex_flow(obj, LV_FLEX_FLOW_COLUMN);
|
||||
return obj;
|
||||
}
|
||||
|
||||
lv_obj_t * lv_list_add_text(lv_obj_t * list, const char * txt)
|
||||
{
|
||||
LV_LOG_INFO("begin");
|
||||
|
||||
lv_obj_t * obj = lv_obj_class_create_obj(MY_CLASS_TEXT, list);
|
||||
lv_obj_class_init_obj(obj);
|
||||
lv_label_set_text(obj, txt);
|
||||
return obj;
|
||||
}
|
||||
|
||||
lv_obj_t * lv_list_add_button(lv_obj_t * list, const void * icon, const char * txt)
|
||||
{
|
||||
LV_LOG_INFO("begin");
|
||||
lv_obj_t * obj = lv_obj_class_create_obj(MY_CLASS_BUTTON, list);
|
||||
lv_obj_class_init_obj(obj);
|
||||
lv_obj_set_flex_flow(obj, LV_FLEX_FLOW_ROW);
|
||||
|
||||
#if LV_USE_IMAGE == 1
|
||||
if(icon) {
|
||||
lv_obj_t * img = lv_image_create(obj);
|
||||
lv_image_set_src(img, icon);
|
||||
}
|
||||
#endif
|
||||
|
||||
if(txt) {
|
||||
lv_obj_t * label = lv_label_create(obj);
|
||||
lv_label_set_text(label, txt);
|
||||
lv_label_set_long_mode(label, LV_LABEL_LONG_MODE_SCROLL_CIRCULAR);
|
||||
lv_obj_set_flex_grow(label, 1);
|
||||
}
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
const char * lv_list_get_button_text(lv_obj_t * list, lv_obj_t * btn)
|
||||
{
|
||||
LV_UNUSED(list);
|
||||
uint32_t i;
|
||||
for(i = 0; i < lv_obj_get_child_count(btn); i++) {
|
||||
lv_obj_t * child = lv_obj_get_child(btn, i);
|
||||
if(lv_obj_check_type(child, &lv_label_class)) {
|
||||
return lv_label_get_text(child);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
void lv_list_set_button_text(lv_obj_t * list, lv_obj_t * btn, const char * txt)
|
||||
{
|
||||
LV_UNUSED(list);
|
||||
uint32_t i;
|
||||
for(i = 0; i < lv_obj_get_child_count(btn); i++) {
|
||||
lv_obj_t * child = lv_obj_get_child(btn, i);
|
||||
if(lv_obj_check_type(child, &lv_label_class)) {
|
||||
lv_label_set_text(child, txt);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**********************
|
||||
* STATIC FUNCTIONS
|
||||
**********************/
|
||||
|
||||
#endif /*LV_USE_LIST*/
|
||||
@@ -0,0 +1,89 @@
|
||||
/**
|
||||
* @file lv_list.h
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef LV_LIST_H
|
||||
#define LV_LIST_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#include "../../core/lv_obj.h"
|
||||
|
||||
#if LV_USE_LIST
|
||||
|
||||
#if LV_USE_FLEX == 0
|
||||
#error "lv_list: lv_flex is required. Enable it in lv_conf.h (LV_USE_FLEX 1)"
|
||||
#endif
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
LV_ATTRIBUTE_EXTERN_DATA extern const lv_obj_class_t lv_list_class;
|
||||
LV_ATTRIBUTE_EXTERN_DATA extern const lv_obj_class_t lv_list_text_class;
|
||||
LV_ATTRIBUTE_EXTERN_DATA extern const lv_obj_class_t lv_list_button_class;
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
|
||||
/**
|
||||
* Create a list object
|
||||
* @param parent pointer to an object, it will be the parent of the new list
|
||||
* @return pointer to the created list
|
||||
*/
|
||||
lv_obj_t * lv_list_create(lv_obj_t * parent);
|
||||
|
||||
/**
|
||||
* Add text to a list
|
||||
* @param list pointer to a list, it will be the parent of the new label
|
||||
* @param txt text of the new label
|
||||
* @return pointer to the created label
|
||||
*/
|
||||
lv_obj_t * lv_list_add_text(lv_obj_t * list, const char * txt);
|
||||
|
||||
/**
|
||||
* Add button to a list
|
||||
* @param list pointer to a list, it will be the parent of the new button
|
||||
* @param icon icon for the button, when NULL it will have no icon
|
||||
* @param txt text of the new button, when NULL no text will be added
|
||||
* @return pointer to the created button
|
||||
*/
|
||||
lv_obj_t * lv_list_add_button(lv_obj_t * list, const void * icon, const char * txt);
|
||||
|
||||
/**
|
||||
* Get text of a given list button
|
||||
* @param list pointer to a list
|
||||
* @param btn pointer to the button
|
||||
* @return text of btn, if btn doesn't have text "" will be returned
|
||||
*/
|
||||
const char * lv_list_get_button_text(lv_obj_t * list, lv_obj_t * btn);
|
||||
|
||||
/**
|
||||
* Set text of a given list button
|
||||
* @param list pointer to a list
|
||||
* @param btn pointer to the button
|
||||
* @param txt pointer to the text
|
||||
*/
|
||||
void lv_list_set_button_text(lv_obj_t * list, lv_obj_t * btn, const char * txt);
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
#endif /*LV_USE_LIST*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /*extern "C"*/
|
||||
#endif
|
||||
|
||||
#endif /*LV_LIST_H*/
|
||||
Reference in New Issue
Block a user