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

dropdown.md (4670B)

      1 ```eval_rst
      2 .. include:: /header.rst
      3 :github_url: |github_link_base|/widgets/core/dropdown.md
      4 ```
      5 # Drop-down list (lv_dropdown)
      6 
      7 
      8 ## Overview
      9 
     10 The drop-down list allows the user to select one value from a list.
     11 
     12 The drop-down list is closed by default and displays a single value or a predefined text.
     13 When activated (by click on the drop-down list), a list is created from which the user may select one option.
     14 When the user selects a new value, the list is deleted again.
     15 
     16 The Drop-down list is added to the default group (if it is set). Besides the Drop-down list is an editable object to allow selecting an option with encoder navigation too.
     17 
     18 ## Parts and Styles
     19 The Dropdown widget is built from the elements: "button" and "list" (both not related to the button and list widgets)
     20 
     21 ### Button
     22 - `LV_PART_MAIN` The background of the button. Uses the typical background properties and text properties for the text on it.
     23 - `LV_PART_INDICATOR` Typically an arrow symbol that can be an image or a text (`LV_SYMBOL`).
     24 
     25 The button goes to `LV_STATE_CHECKED` when it's opened.
     26 
     27 ### List
     28 - `LV_PART_MAIN` The list itself. Uses the typical background properties. `max_height` can be used to limit the height of the list.
     29 - `LV_PART_SCROLLBAR` The scrollbar background, border, shadow properties and width (for its own width) and right padding for the spacing on the right.
     30 - `LV_PART_SELECTED` Refers to the currently pressed, checked or pressed+checked option. Also uses the typical background properties.
     31 
     32 The list is hidden/shown on open/close. To add styles to it use `lv_dropdown_get_list(dropdown)`  to get the list object. For example:
     33 
     34 ```c
     35 lv_obj_t * list = lv_dropdown_get_list(dropdown) /*Get the list*/
     36 lv_obj_add_style(list, &my_style, ...)           /*Add the styles to the list*/}`
     37 ```
     38 
     39 Alternatively the theme can be extended with the new styles.
     40 
     41 ## Usage
     42 
     43 ## Overview
     44 
     45 ### Set options
     46 Options are passed to the drop-down list as a string with `lv_dropdown_set_options(dropdown, options)`. Options should be separated by `\n`. For example: `"First\nSecond\nThird"`. This string will be saved in the drop-down list, so it can in a local variable.
     47 
     48 The `lv_dropdown_add_option(dropdown, "New option", pos)` function inserts a new option to `pos` index.
     49 
     50 To save memory the options can set from a static(constant) string too with `lv_dropdown_set_static_options(dropdown, options)`.
     51 In this case the options string should be alive while the drop-down list exists and `lv_dropdown_add_option` can't be used
     52 
     53 You can select an option manually with `lv_dropdown_set_selected(dropdown, id)`, where `id` is the index of an option.
     54 
     55 ### Get selected option
     56 The get the *index* of the selected option, use `lv_dropdown_get_selected(dropdown)`.
     57 
     58 `lv_dropdown_get_selected_str(dropdown, buf, buf_size)` copies the *name* of the selected option to `buf`.
     59 
     60 ### Direction
     61 The list can be created on any side. The default `LV_DIR_BOTTOM` can be modified by `lv_dropdown_set_dir(dropdown, LV_DIR_LEFT/RIGHT/UP/BOTTOM)` function.
     62 
     63 If the list would be vertically out of the screen, it will be aligned to the edge.
     64 
     65 ### Symbol
     66 A symbol (typically an arrow) can be added to the dropdown list with `lv_dropdown_set_symbol(dropdown, LV_SYMBOL_...)`
     67 
     68 If the direction of the drop-down list is  `LV_DIR_LEFT` the symbol will be shown on the left, otherwise on the right.
     69 
     70 ### Show selected
     71 The main part can either show the selected option or a static text. If a static is set with `lv_dropdown_set_text(dropdown, "Some text")` it will be shown regardless to th selected option.
     72 If the text is `NULL` the selected option is displayed on the button.
     73 
     74 ### Manually open/close
     75 To manually open or close the drop-down list the `lv_dropdown_open/close(dropdown)` function can be used.
     76 
     77 ## Events
     78 Apart from the [Generic events](../overview/event.html#generic-events), the following [Special events](../overview/event.html#special-events) are sent by the drop-down list:
     79 - `LV_EVENT_VALUE_CHANGED` Sent when the new option is selected or the list is opened/closed.
     80 - `LV_EVENT_CANCEL`  Sent when the list is closed
     81 - `LV_EVENT_READY` Sent when the list is opened
     82 
     83 See the events of the [Base object](/widgets/obj) too.
     84 
     85 Learn more about [Events](/overview/event).
     86 
     87 ## Keys
     88 - `LV_KEY_RIGHT/DOWN` Select the next option.
     89 - `LV_KEY_LEFT/UP` Select the previous option.
     90 - `LY_KEY_ENTER` Apply the selected option (Sends `LV_EVENT_VALUE_CHANGED` event and closes the drop-down list).
     91 
     92 Learn more about [Keys](/overview/indev).
     93 
     94 ## Example
     95 
     96 ```eval_rst
     97 
     98 .. include:: ../../../examples/widgets/dropdown/index.rst
     99 
    100 ```
    101 
    102 ## API
    103 
    104 ```eval_rst
    105 
    106 .. doxygenfile:: lv_dropdown.h
    107   :project: lvgl
    108 
    109 ```