Logo
6.1.2
  • Get started
    • Live demos
    • Simulator on PC
      • Select an IDE
      • Set-up Eclipse CDT
        • Install Eclipse CDT
        • Install SDL 2
        • Pre-configured project
        • Add the pre-configured project to Eclipse CDT
        • Compile and Run
    • Quick overview
      • Add LittlevGL into your project
      • Learn the basics
        • Objects (Widgets)
        • Styles
        • Events
      • Examples
        • Button with label
        • Button with styles
        • Slider and object alignment
        • List and themes
        • Use LittlevGL from Micropython
      • Contributing
    • Micropython
      • What is Micropython?
        • Highlights of Micropython
      • Why Micropython + LittlevGL?
        • Here are some advantages of using LittlevGL in Micropython:
        • Micropython + LittlevGL could be used for:
      • So what does it look like?
        • A simple example
      • How can I use it?
        • Online Simulator
        • PC Simulator
        • Embedded platform
      • Where can I find more information?
  • Porting
    • System overview
    • Set-up a project
      • Get the library
      • Configuration file
      • Initialization
    • Display interface
      • Display buffer
      • Display driver
      • API
    • Input device interface
      • Types of input devices
        • Touchpad, mouse or any pointer
        • Keypad or keyboard
        • Encoder
        • Button
      • Other features
      • API
    • Tick interface
      • API
    • Task Handler
    • Sleep management
    • Operating system and interrupts
      • Tasks and threads
      • Interrupts
    • Logging
      • Log level
      • Logging with printf
      • Custom log function
      • Add logs
  • Overview
    • Objects
      • Object attributes
        • Basic attributes
        • Specific attributes
      • Object’s working mechanisms
        • Parent-child structure
        • Moving together
        • Visibility only on the parent
        • Create - delete objects
        • Screen – the most basic parent
    • Layers
      • Order of creation
      • Bring to the foreground
      • Top and sys layers
    • Events
      • Event types
        • Generic events
        • Special events
      • Custom data
      • Send events manually
    • Styles
      • Use the styles
      • Inherit styles
      • Style properties
        • Common properties
        • Body style properties
        • Text style properties
        • Image style properties
        • Line style properties
      • Built-in styles
      • Create new styles
      • Style animations
      • Style example
      • Themes
        • Live update
    • Input devices
      • Pointers
      • Keypad and encoder
        • Groups
        • Complete example
      • API
        • Input device
        • Groups
    • Displays
      • Using only one display
      • Mirror display
      • Split image
      • Screens
        • Opaque screen
      • Features of displays
        • Inactivity
      • Colors
        • Convert color
        • Swap 16 colors
        • Create and mix colors
        • Opacity
        • Built-in colors
      • API
        • Display
        • Colors
    • Fonts
      • Unicode support
      • Built-in fonts
      • Special features
        • Bidirectional support
        • Subpixel rendering
        • Compress fonts
      • Add new font
      • Add new symbols
      • Add a new font engine
    • Images
      • Store images
        • Variables
        • Files
      • Color formats
      • Add and use images
        • Online converter
        • Manually create an image
        • Use images
      • Image decoder
        • Custom image formats
        • Register an image decoder
        • Manually use an image decoder
      • Image caching
        • Cache size
        • Value of images
        • Memory usage
        • Clean the cache
      • API
        • Image decoder
        • Image cache
    • File system
      • Add a driver
      • Usage example
      • Use drivers for images
      • API
    • Animations
      • Create an animation
      • Animation path
      • Speed vs time
      • Delete animations
      • API
        • Input device
    • Tasks
      • Create a task
      • Ready and Reset
      • Set parameters
      • One-shot tasks
      • Measure idle time
      • Asynchronous calls
      • API
    • Drawing
      • Buffering types
      • Mechanism of screen refreshing
  • Object types (Widgets)
    • Base object (lv_obj)
      • Overview
        • Coordinates
        • Parents and children
        • Screens
        • Layers
        • Style
        • Events
        • Attributes
        • Opa scale
        • Protect
        • Groups
        • Extended click area
      • Styles
      • Events
      • Keys
      • Example
        • C
        • MicroPython
      • API
    • Arc (lv_arc)
      • Overview
        • Angles
        • Notes
      • Styles
      • Events
      • Keys
      • Example
        • C
        • MicroPython
      • API
    • Bar (lv_bar)
      • Overview
        • Value and range
        • Symmetrical
      • Styles
      • Events
      • Keys
      • Example
        • C
        • MicroPython
      • API
    • Button (lv_btn)
      • Overview
        • States
        • Toggle
        • Layout and Fit
        • Ink effect
      • Styles
      • Events
      • Keys
      • Example
        • C
        • MicroPython
      • API
    • Button matrix (lv_btnm)
      • Overview
        • Button’s text
        • Control buttons
        • One toggle
        • Recolor
        • Notes
      • Styles
      • Events
      • Keys
      • Example
        • C
        • MicroPython
      • API
    • Calendar (lv_calendar)
      • Overview
        • Current date
        • Shown date
        • Highlighted days
        • Name of the days
        • Name of the months
      • Styles
      • Events
      • Keys
      • Example
        • C
        • MicroPython
      • API
    • Canvas (lv_canvas)
      • Overview
        • Buffer
        • Palette
        • Drawing
        • Rotate
      • Styles
      • Events
      • Keys
      • Example
        • C
        • MicroPython
      • API
    • Checkbox (lv_cb)
      • Overview
        • Text
        • Check/Uncheck
        • Inactive
      • Styles
      • Events
      • Keys
      • Example
        • C
        • MicroPython
      • API
    • Chart (lv_chart)
      • Overview
        • Data series
        • Series’ type
        • Modify the data
        • Update modes
        • Number of points
        • Vertical range
        • Division lines
        • Series’ appearance
        • Tick marks and labels
      • Styles
      • Events
      • Keys
      • Example
        • C
        • MicroPython
      • API
    • Container (lv_cont)
      • Overview
        • Layout
        • Autofit
      • Styles
      • Events
      • Keys
      • Example
        • C
        • MicroPython
      • API
    • Color picker (lv_cpicker)
      • Overview
        • Types of color pickers
        • Notes
      • Styles
      • Events
      • Keys
      • Example
      • API
    • Drop-down list (lv_ddlist)
      • Overview
        • Set options
        • Get selected option
        • Align the options
        • Height and width
        • Scrollbars
        • Animation time
        • Decoration arrow
        • Manually open/close
        • Stay open
      • Styles
      • Events
      • Keys
      • Example
        • C
        • MicroPython
      • API
    • Gauge (lv_gauge)
      • Overview
        • Scale
        • Needles
        • Range
        • Critical value
      • Styles
      • Events
      • Keys
      • Example
        • C
        • MicroPython
      • API
    • Image (lv_img)
      • Overview
        • Image source
        • Label as an image
        • Transparency
        • Palette and Alpha index
        • Recolor
        • Auto-size
        • Mosaic
        • Offset
      • Styles
      • Events
      • Keys
      • Example
        • C
        • MicroPython
      • API
    • Image button (lv_imgbtn)
      • Overview
        • Image sources
        • States
        • Toggle
      • Style usage
      • Events
      • Keys
      • Example
        • C
        • MicroPython
      • API
    • Keyboard (lv_kb)
      • Overview
        • Modes
        • Assign Text area
        • New Keymap
      • Styles
      • Events
      • Keys
      • Examples
        • C
        • MicroPython
      • API
    • Label (lv_label)
      • Overview
        • Set text
        • Line break
        • Long modes
        • Text align
        • Draw background
        • Text recolor
        • Very long texts
        • Symbols
      • Styles
      • Events
      • Keys
      • Example
        • C
        • MicroPython
      • API
    • LED (lv_led)
      • Overview
        • Brightness
        • Toggle
      • Styles
      • Events
      • Keys
      • Example
        • C
        • MicroPython
      • API
    • Line (lv_line)
      • Overview
        • Set points
        • Auto-size
        • Invert y
      • Styles
      • Events
      • Keys
      • Example
        • C
        • MicroPython
      • API
    • List (lv_list)
      • Overview
        • Add buttons
        • Delete buttons
        • Manual navigation
        • Layout
        • Edge flash
        • Scroll propagation
      • Style usage
      • Events
      • Keys
      • Example
        • C
        • MicroPython
      • API
    • Line meter (lv_lmeter)
      • Overview
        • Set value
        • Range and Angles
        • Angle offset
      • Styles
      • Events
      • Keys
      • Example
        • C
        • MicroPython
      • API
    • Message box (lv_mbox)
      • Overview
        • Set text
        • Add buttons
        • Auto-close
      • Styles
      • Events
      • Example
        • C
        • MicroPython
      • API
    • Page (lv_page)
      • Overview
        • Scrollbars
        • Glue object
        • Focus object
        • Manual navigation
        • Edge flash
        • Scroll propagation
        • Scrollable API
        • Notes
      • Styles
      • Events
      • Example
        • C
        • MicroPython
      • API
    • Preloader (lv_preload)
      • Overview
        • Arc length
        • Spinning speed
        • Spin types
        • Spin direction
      • Styles
      • Events
      • Keys
      • Example
        • C
        • MicroPython
        • MicroPython
      • API
    • Roller (lv_roller)
      • Overview
        • Set options
        • Get selected option
        • Align the options
        • Height and width
        • Animation time
      • Styles
      • Events
      • Keys
      • Example
        • C
        • MicroPython
      • API
    • Slider (lv_slider)
      • Overview
      • Value and range
        • Symmetrical
        • Knob placement
      • Styles
      • Events
      • Keys
      • Example
        • C
        • MicroPython
      • API
    • Spinbox (lv_spinbox)
      • Overview
        • Set format
        • Value and ranges
      • Style usage
      • Events
      • Keys
      • Example
        • C
        • MicroPython
      • API
      • Example
    • Switch (lv_sw)
      • Overview
        • Change state
        • Animation time
      • Styles
      • Events
      • Keys
      • Example
        • C
        • MicroPython
      • API
    • Table (lv_table)
      • Overview
        • Rows and Columns
        • Width and Height
        • Set cell value
        • Align
        • Cell type
        • Merge cells
        • Crop text
        • Scroll
      • Styles
      • Events
      • Keys
      • Example
        • C
        • MicroPython
        • MicroPython
      • API
    • Tabview (lv_tabview)
      • Overview
        • Adding tab
        • Change tab
        • Tab button’s position
        • Hide the tabs
        • Animation time
      • Style usage
      • Events
      • Keys
      • Example
        • C
        • MicroPython
      • API
    • Text area (lv_ta)
      • Overview
        • Add text
        • Placeholder
        • Delete character
        • Move the cursor
        • Cursor types
        • One line mode
        • Password mode
        • Text align
        • Accepted characters
        • Max text length
        • Very long texts
        • Select text
        • Scrollbars
        • Scroll propagation
        • Edge flash
      • Style usage
      • Events
      • Keys
      • Example
        • C
        • MicroPython
      • API
    • Tile view (lv_tileview)
      • Overview
        • Valid positions
        • Add element
        • Set tile
        • Animation time
        • Edge flash
      • Styles
      • Events
      • Keys
      • Example
        • C
        • MicroPython
      • API
    • Window (lv_win)
      • Overview
        • Title
        • Control buttons
        • Scrollbars
        • Manual scroll and focus
        • Layout
      • Style usage
      • Events
      • Keys
      • Example
        • C
        • MicroPython
      • API
LittlevGL
  • Docs »
  • Object types (Widgets) »
  • Drop-down list (lv_ddlist)
  • Edit on GitHub

Drop-down list (lv_ddlist)¶

Overview¶

The drop-down list allows the user to select one value from a list. The drop-down list is closed (inactive) by default. When a drop-down list is inactive, it displays a single value. When activated (by click on the drop-down list), it displays a list of values from which the user may select one. When the user selects a new value, the drop-down list reverts to the inactive state and displays the new value.

Set options¶

The options are passed to the drop-down list as a string with lv_ddlist_set_options(ddlist, options). The options should be separated by \n. For example: "First\nSecond\nThird".

You can select an option manually with lv_ddlist_set_selected(ddlist, id), where id is the index of an option.

Get selected option¶

The get the currently selected option, use lv_ddlist_get_selected(ddlist). It will return the index of the selected option.

lv_ddlist_get_selected_str(ddlist, buf, buf_size) copies the name of the selected option to a buf.

Align the options¶

To align the label horizontally, use lv_ddlist_set_align(ddlist, LV_LABEL_ALIGN_LEFT/CENTER/RIGHT).

Height and width¶

By default, the list’s height is adjusted automatically to show all options. The lv_ddlist_set_fix_height(ddlist, height) sets a fixed height for the opened list. The user can put 0 to use auto height.

The width is also adjusted automatically. To prevent this, apply lv_ddlist_set_fix_width(ddlist, width). The user can put 0 to use auto width.

Scrollbars¶

Similarly to Page with fix height, the drop-down list supports various scrollbar display modes. It can be set by lv_ddlist_set_sb_mode(ddlist, LV_SB_MODE_...).

Animation time¶

The drop-down list’s open/close animation time is adjusted by lv_ddlist_set_anim_time(ddlist, anim_time). Zero animation time means no animation.

Decoration arrow¶

A down arrow can be added to the left side of the drop-down list with lv_ddlist_set_draw_arrow(ddlist, true).

Manually open/close¶

To manually open or close the drop-down list the lv_ddlist_open/close(ddlist) function can be used.

Stay open¶

You can force the drop-down list to stay opened, when an option is selected with lv_ddlist_set_stay_open(ddlist, true).

Styles¶

The lv_ddlist_set_style(ddlist, LV_DDLIST_STYLE_..., &style) set the styles of a drop-down list.

  • LV_DDLIST_STYLE_BG - Style of the background. All style.body properties are used. style.text is used for the option’s label. Default: lv_style_pretty.

  • LV_DDLIST_STYLE_SEL - Style of the selected option. The style.body properties are used. The selected option will be recolored with text.color. Default: lv_style_plain_color.

  • LV_DDLIST_STYLE_SB - Style of the scrollbar. The style.body properties are used. Default: lv_style_plain_color.

Events¶

Besides the Generic events, the following Special events are sent by the drop-down list:

  • LV_EVENT_VALUE_CHANGED - Sent when the new option is selected.

Learn more about Events.

Keys¶

The following Keys are processed by the Buttons:

  • LV_KEY_RIGHT/DOWN - Select the next option.

  • LV_KEY_LEFT/UP - Select the previous option.

  • LY_KEY_ENTER - Apply the selected option (Send LV_EVENT_VALUE_CHANGED event and close the drop-down list).

Example¶

C¶

Simple Drop down list¶

Simple Drop down list example in LittlevGL

code

#include "lvgl/lvgl.h"
#include <stdio.h>

static void event_handler(lv_obj_t * obj, lv_event_t event)
{
    if(event == LV_EVENT_VALUE_CHANGED) {
        char buf[32];
        lv_ddlist_get_selected_str(obj, buf, sizeof(buf));
        printf("Option: %s\n", buf);
    }
}

void lv_ex_ddlist_1(void)
{

    /*Create a drop down list*/
    lv_obj_t * ddlist = lv_ddlist_create(lv_scr_act(), NULL);
    lv_ddlist_set_options(ddlist, "Apple\n"
            "Banana\n"
            "Orange\n"
            "Melon\n"
            "Grape\n"
            "Raspberry");

    lv_ddlist_set_fix_width(ddlist, 150);
    lv_ddlist_set_draw_arrow(ddlist, true);
    lv_obj_align(ddlist, NULL, LV_ALIGN_IN_TOP_MID, 0, 20);
    lv_obj_set_event_cb(ddlist, event_handler);
}

Drop “up” list¶

Drop up list example in LittlevGL

code

#include "lvgl/lvgl.h"
#include <stdio.h>

/**
 * Create a drop UP list by applying auto realign
 */
void lv_ex_ddlist_2(void)
{

    /*Create a drop down list*/
    lv_obj_t * ddlist = lv_ddlist_create(lv_scr_act(), NULL);
    lv_ddlist_set_options(ddlist, "Apple\n"
            "Banana\n"
            "Orange\n"
            "Melon\n"
            "Grape\n"
            "Raspberry");

    lv_ddlist_set_fix_width(ddlist, 150);
    lv_ddlist_set_fix_height(ddlist, 150);
    lv_ddlist_set_draw_arrow(ddlist, true);

    /* Enable auto-realign when the size changes.
     * It will keep the bottom of the ddlist fixed*/
    lv_obj_set_auto_realign(ddlist, true);

    /*It will be called automatically when the size changes*/
    lv_obj_align(ddlist, NULL, LV_ALIGN_IN_BOTTOM_MID, 0, -20);
}

MicroPython¶

Simple Drop down list¶

Simple Drop down list example in LittlevGL with MicroPython

code

def event_handler(obj, event):
    if event == lv.EVENT.VALUE_CHANGED:
        option = " "*10 # should be large enough to store the option
        obj.get_selected_str(option, len(option))
        # .strip() removes trailing spaces
        print("Option: \"%s\"" % option.strip())

# Create a drop down list
ddlist = lv.ddlist(lv.scr_act())
ddlist.set_options("\n".join([
                    "Apple",
                    "Banana",
                    "Orange",
                    "Melon",
                    "Grape",
                    "Raspberry"]))

ddlist.set_fix_width(150)
ddlist.set_draw_arrow(True)
ddlist.align(None, lv.ALIGN.IN_TOP_MID, 0, 20)
ddlist.set_event_cb(event_handler)

Drop “up” list¶

Drop up list example in LittlevGL with MicroPython

code

# Create a drop UP list by applying auto realign

# Create a drop down list
ddlist = lv.ddlist(lv.scr_act())
ddlist.set_options("\n".join([
                    "Apple",
                    "Banana",
                    "Orange",
                    "Melon",
                    "Grape",
                    "Raspberry"]))


ddlist.set_fix_width(150)
ddlist.set_fix_height(150)
ddlist.set_draw_arrow(True)

# Enable auto-realign when the size changes.
# It will keep the bottom of the ddlist fixed
ddlist.set_auto_realign(True)

# It will be called automatically when the size changes
ddlist.align(None, lv.ALIGN.IN_BOTTOM_MID, 0, -20)

API¶

Typedefs

typedef uint8_t lv_ddlist_style_t¶

Enums

enum [anonymous]¶

Values:

enumerator LV_DDLIST_STYLE_BG¶
enumerator LV_DDLIST_STYLE_SEL¶
enumerator LV_DDLIST_STYLE_SB¶

Functions

lv_obj_t *lv_ddlist_create(lv_obj_t *par, const lv_obj_t *copy)¶

Create a drop down list objects

Return

pointer to the created drop down list

Parameters
  • par: pointer to an object, it will be the parent of the new drop down list

  • copy: pointer to a drop down list object, if not NULL then the new object will be copied from it

void lv_ddlist_set_options(lv_obj_t *ddlist, const char *options)¶

Set the options in a drop down list from a string

Parameters
  • ddlist: pointer to drop down list object

  • options: a string with ‘

    ’ separated options. E.g. “One\nTwo\nThree”

void lv_ddlist_set_selected(lv_obj_t *ddlist, uint16_t sel_opt)¶

Set the selected option

Parameters
  • ddlist: pointer to drop down list object

  • sel_opt: id of the selected option (0 … number of option - 1);

void lv_ddlist_set_fix_height(lv_obj_t *ddlist, lv_coord_t h)¶

Set a fix height for the drop down list If 0 then the opened ddlist will be auto. sized else the set height will be applied.

Parameters
  • ddlist: pointer to a drop down list

  • h: the height when the list is opened (0: auto size)

void lv_ddlist_set_fix_width(lv_obj_t *ddlist, lv_coord_t w)¶

Set a fix width for the drop down list

Parameters
  • ddlist: pointer to a drop down list

  • w: the width when the list is opened (0: auto size)

void lv_ddlist_set_draw_arrow(lv_obj_t *ddlist, bool en)¶

Set arrow draw in a drop down list

Parameters
  • ddlist: pointer to drop down list object

  • en: enable/disable a arrow draw. E.g. “true” for draw.

void lv_ddlist_set_stay_open(lv_obj_t *ddlist, bool en)¶

Leave the list opened when a new value is selected

Parameters
  • ddlist: pointer to drop down list object

  • en: enable/disable “stay open” feature

void lv_ddlist_set_sb_mode(lv_obj_t *ddlist, lv_sb_mode_t mode)¶

Set the scroll bar mode of a drop down list

Parameters
  • ddlist: pointer to a drop down list object

  • sb_mode: the new mode from ‘lv_page_sb_mode_t’ enum

void lv_ddlist_set_anim_time(lv_obj_t *ddlist, uint16_t anim_time)¶

Set the open/close animation time.

Parameters
  • ddlist: pointer to a drop down list

  • anim_time: open/close animation time [ms]

void lv_ddlist_set_style(lv_obj_t *ddlist, lv_ddlist_style_t type, const lv_style_t *style)¶

Set a style of a drop down list

Parameters
  • ddlist: pointer to a drop down list object

  • type: which style should be set

  • style: pointer to a style

void lv_ddlist_set_align(lv_obj_t *ddlist, lv_label_align_t align)¶

Set the alignment of the labels in a drop down list

Parameters
  • ddlist: pointer to a drop down list object

  • align: alignment of labels

const char *lv_ddlist_get_options(const lv_obj_t *ddlist)¶

Get the options of a drop down list

Return

the options separated by ‘

’-s (E.g. “Option1\nOption2\nOption3”)

Parameters
  • ddlist: pointer to drop down list object

uint16_t lv_ddlist_get_selected(const lv_obj_t *ddlist)¶

Get the selected option

Return

id of the selected option (0 … number of option - 1);

Parameters
  • ddlist: pointer to drop down list object

void lv_ddlist_get_selected_str(const lv_obj_t *ddlist, char *buf, uint16_t buf_size)¶

Get the current selected option as a string

Parameters
  • ddlist: pointer to ddlist object

  • buf: pointer to an array to store the string

  • buf_size: size of buf in bytes. 0: to ignore it.

lv_coord_t lv_ddlist_get_fix_height(const lv_obj_t *ddlist)¶

Get the fix height value.

Return

the height if the ddlist is opened (0: auto size)

Parameters
  • ddlist: pointer to a drop down list object

bool lv_ddlist_get_draw_arrow(lv_obj_t *ddlist)¶

Get arrow draw in a drop down list

Parameters
  • ddlist: pointer to drop down list object

bool lv_ddlist_get_stay_open(lv_obj_t *ddlist)¶

Get whether the drop down list stay open after selecting a value or not

Parameters
  • ddlist: pointer to drop down list object

lv_sb_mode_t lv_ddlist_get_sb_mode(const lv_obj_t *ddlist)¶

Get the scroll bar mode of a drop down list

Return

scrollbar mode from ‘lv_page_sb_mode_t’ enum

Parameters
  • ddlist: pointer to a drop down list object

uint16_t lv_ddlist_get_anim_time(const lv_obj_t *ddlist)¶

Get the open/close animation time.

Return

open/close animation time [ms]

Parameters
  • ddlist: pointer to a drop down list

const lv_style_t *lv_ddlist_get_style(const lv_obj_t *ddlist, lv_ddlist_style_t type)¶

Get a style of a drop down list

Return

style pointer to a style

Parameters
  • ddlist: pointer to a drop down list object

  • type: which style should be get

lv_label_align_t lv_ddlist_get_align(const lv_obj_t *ddlist)¶

Get the alignment of the labels in a drop down list

Return

alignment of labels

Parameters
  • ddlist: pointer to a drop down list object

void lv_ddlist_open(lv_obj_t *ddlist, lv_anim_enable_t anim)¶

Open the drop down list with or without animation

Parameters
  • ddlist: pointer to drop down list object

  • anim_en: LV_ANIM_ON: use animation; LV_ANOM_OFF: not use animations

void lv_ddlist_close(lv_obj_t *ddlist, lv_anim_enable_t anim)¶

Close (Collapse) the drop down list

Parameters
  • ddlist: pointer to drop down list object

  • anim_en: LV_ANIM_ON: use animation; LV_ANOM_OFF: not use animations

struct lv_ddlist_ext_t¶

Public Members

lv_page_ext_t page¶
lv_obj_t *label¶
const lv_style_t *sel_style¶
uint16_t option_cnt¶
uint16_t sel_opt_id¶
uint16_t sel_opt_id_ori¶
uint8_t opened¶
uint8_t force_sel¶
uint8_t draw_arrow¶
uint8_t stay_open¶
lv_coord_t fix_height¶
Next Previous

© Copyright 2020, Gabor Kiss-Vamosi Last updated on Nov 21, 2020.

Built with Sphinx using a theme provided by Read the Docs.