acid-drop

- Hacking the planet from a LilyGo T-Deck using custom firmware
git clone git://git.acid.vegas/acid-drop.git
Log | Files | Refs | Archive | README | LICENSE

lv_list.c (2758B)

      1 /**
      2  * @file lv_list.c
      3  *
      4  */
      5 
      6 /*********************
      7  *      INCLUDES
      8  *********************/
      9 #include "lv_list.h"
     10 #include "../../../core/lv_disp.h"
     11 #include "../../../widgets/lv_label.h"
     12 #include "../../../widgets/lv_img.h"
     13 #include "../../../widgets/lv_btn.h"
     14 
     15 #if LV_USE_LIST
     16 
     17 /*********************
     18  *      DEFINES
     19  *********************/
     20 #define MV_CLASS &lv_list
     21 
     22 /**********************
     23  *      TYPEDEFS
     24  **********************/
     25 
     26 /**********************
     27  *  STATIC PROTOTYPES
     28  **********************/
     29 
     30 const lv_obj_class_t lv_list_class = {
     31     .base_class = &lv_obj_class,
     32     .width_def = (LV_DPI_DEF * 3) / 2,
     33     .height_def = LV_DPI_DEF * 2
     34 };
     35 
     36 const lv_obj_class_t lv_list_btn_class = {
     37     .base_class = &lv_btn_class,
     38 };
     39 
     40 const lv_obj_class_t lv_list_text_class = {
     41     .base_class = &lv_label_class,
     42 };
     43 
     44 /**********************
     45  *  STATIC VARIABLES
     46  **********************/
     47 
     48 /**********************
     49  *      MACROS
     50  **********************/
     51 
     52 /**********************
     53  *   GLOBAL FUNCTIONS
     54  **********************/
     55 
     56 lv_obj_t * lv_list_create(lv_obj_t * parent)
     57 {
     58     LV_LOG_INFO("begin");
     59     lv_obj_t * obj = lv_obj_class_create_obj(&lv_list_class, parent);
     60     lv_obj_class_init_obj(obj);
     61     lv_obj_set_flex_flow(obj, LV_FLEX_FLOW_COLUMN);
     62     return obj;
     63 }
     64 
     65 lv_obj_t * lv_list_add_text(lv_obj_t * list, const char * txt)
     66 {
     67     LV_LOG_INFO("begin");
     68     lv_obj_t * obj = lv_obj_class_create_obj(&lv_list_text_class, list);
     69     lv_obj_class_init_obj(obj);
     70     lv_label_set_text(obj, txt);
     71     lv_label_set_long_mode(obj, LV_LABEL_LONG_SCROLL_CIRCULAR);
     72     lv_obj_set_width(obj, LV_PCT(100));
     73     return obj;
     74 }
     75 
     76 lv_obj_t * lv_list_add_btn(lv_obj_t * list, const void * icon, const char * txt)
     77 {
     78     LV_LOG_INFO("begin");
     79     lv_obj_t * obj = lv_obj_class_create_obj(&lv_list_btn_class, list);
     80     lv_obj_class_init_obj(obj);
     81     lv_obj_set_size(obj, LV_PCT(100), LV_SIZE_CONTENT);
     82     lv_obj_set_flex_flow(obj, LV_FLEX_FLOW_ROW);
     83 
     84 #if LV_USE_IMG == 1
     85     if(icon) {
     86         lv_obj_t * img = lv_img_create(obj);
     87         lv_img_set_src(img, icon);
     88     }
     89 #endif
     90 
     91     if(txt) {
     92         lv_obj_t * label = lv_label_create(obj);
     93         lv_label_set_text(label, txt);
     94         lv_label_set_long_mode(label, LV_LABEL_LONG_SCROLL_CIRCULAR);
     95         lv_obj_set_flex_grow(label, 1);
     96     }
     97 
     98     return obj;
     99 }
    100 
    101 const char * lv_list_get_btn_text(lv_obj_t * list, lv_obj_t * btn)
    102 {
    103     LV_UNUSED(list);
    104     uint32_t i;
    105     for(i = 0; i < lv_obj_get_child_cnt(btn); i++) {
    106         lv_obj_t * child = lv_obj_get_child(btn, i);
    107         if(lv_obj_check_type(child, &lv_label_class)) {
    108             return lv_label_get_text(child);
    109         }
    110 
    111     }
    112 
    113     return "";
    114 }
    115 
    116 /**********************
    117  *   STATIC FUNCTIONS
    118  **********************/
    119 
    120 #endif /*LV_USE_LIST*/