Skip to content

Latest commit

 

History

History
115 lines (84 loc) · 3.51 KB

file_explorer.rst

File metadata and controls

115 lines (84 loc) · 3.51 KB

File Explorer

lv_file_explorer provides an API to browse the contents of the file system. lv_file_explorer only provides the file browsing function, but does not provide the actual file operation function. In other words, you can't click a picture file to open and view the picture like a PC. lv_file_explorer will tell you the full path and name of the currently clicked file. The file operation function needs to be implemented by the user.

The file list in lv_file_explorer is based on lv_table, and the quick access bar is based on lv_list. Therefore, care should be taken to ensure that lv_table and lv_list are enabled.

Usage

Enable :cLV_USE_FILE_EXPLORER in lv_conf.h.

First use :cpplv_file_explorer_create(lv_screen_active()) to create a file explorer, The default size is the screen size. After that, you can customize the style like widget.

Quick access

The quick access bar is optional. You can turn off :cLV_FILE_EXPLORER_QUICK_ACCESS in lv_conf.h so that the quick access bar will not be created. This can save some memory, but not much. After the quick access bar is created, it can be hidden by clicking the button at the top left corner of the browsing area, which is very useful for small screen devices.

You can use :cpplv_file_explorer_set_quick_access_path(file_explorer, LV_FILE_EXPLORER_QA_XX, "path") to set the path of the quick access bar. The items of the quick access bar are fixed. Currently, there are the following items:

  • :cppLV_FILE_EXPLORER_QA_HOME
  • :cppLV_FILE_EXPLORER_QA_MUSIC
  • :cppLV_FILE_EXPLORER_QA_PICTURES
  • :cppLV_FILE_EXPLORER_QA_VIDEO
  • :cppLV_FILE_EXPLORER_QA_DOCS
  • :cppLV_FILE_EXPLORER_QA_MNT
  • :cppLV_FILE_EXPLORER_QA_FS

Sort

You can use :cpplv_file_explorer_set_sort(file_explorer, LV_EXPLORER_SORT_XX) to set sorting method.

There are the following sorting methods:

  • :cppLV_EXPLORER_SORT_NONE
  • :cppLV_EXPLORER_SORT_KIND

You can customize the sorting. Before custom sort, please set the default sorting to :cppLV_EXPLORER_SORT_NONE. The default is :cppLV_EXPLORER_SORT_NONE.

Events

  • :cppLV_EVENT_READY Sent when a directory is opened. You can customize the sort.
  • :cppLV_EVENT_VALUE_CHANGED Sent when an item (file) in the file list is clicked.

You can use :cpplv_file_explorer_get_cur_path to get the current path and :cpplv_file_explorer_get_sel_fn to get the name of the currently selected file in the event processing function. For example:

static void file_explorer_event_handler(lv_event_t * e)
{
    lv_event_code_t code = lv_event_get_code(e);
    lv_obj_t * obj = lv_event_get_target(e);

    if(code == LV_EVENT_VALUE_CHANGED) {
        char * cur_path =  lv_file_explorer_get_cur_path(obj);
        char * sel_fn = lv_file_explorer_get_sel_fn(obj);
        LV_LOG_USER("%s%s", cur_path, sel_fn);
    }
}

You can also save the obtained path and file name into an array through functions such as :cppstrcpy and :cppstrcat for later use.

Example

API