Overview

The Check Box objects are built from a Button background which contains an also Button bullet and a label to realize a classical check box.

The text can be modified by the lv_cb_set_text(cb, "New text") function.

An action can assigned by lv_cb_set_action(cb, action)

You can manually check / un-check the Check box via lv_cb_set_checked(cb, state)

Style usage

The Check box styles can be modified with lv_cb_set_style(cb, LV_CB_STYLE_..., &style)

  • LV_CB_STYLE_BG Background style. Uses all style.body properties. The label's style comes from style.text. Default: lv_style_transp
  • LV_CB_STYLE_BOX_REL Style of the released box. Uses the style.body properties. Default: lv_style_btn_rel
  • LV_CB_STYLE_BOX_PR Style of the pressed box. Uses the style.body properties. Default: lv_style_btn_pr
  • LV_CB_STYLE_BOX_TGL_REL Style of the checked released box. Uses the style.body properties. Default: lv_style_btn_tgl_rel
  • LV_CB_STYLE_BOX_TGL_PR Style of the checked released box. Uses the style.body properties. Default: lv_style_btn_tgl_pr

Notes

Example of Check box in Littlev Graphics Library

						static lv_res_t cb_release_action(lv_obj_t * cb)
{
    /*A check box is clicked*/
    printf("%s state: %d\n", lv_cb_get_text(cb), lv_cb_is_checked(cb));

    return LV_RES_OK;
}

.
.
.


/********************************************
 * Create a container for the check boxes
 ********************************************/

/*Create  border style*/
static lv_style_t style_border;
lv_style_copy(&style_border, &lv_style_pretty_color);
style_border.glass = 1;
style_border.body.empty = 1;

/*Create a container*/
lv_obj_t * cont;
cont = lv_cont_create(lv_scr_act(), NULL);
lv_cont_set_layout(cont, LV_LAYOUT_COL_L);      /*Arrange the children in a column*/
lv_cont_set_fit(cont, true, true);              /*Fit the size to the content*/
lv_obj_set_style(cont, &style_border);

/**************************
 * Create check boxes
 *************************/

/*Create check box*/
lv_obj_t * cb;
cb = lv_cb_create(cont, NULL);
lv_cb_set_text(cb, "Potato");
lv_cb_set_action(cb, cb_release_action);

/*Copy the previous check box*/
cb = lv_cb_create(cont, cb);
lv_cb_set_text(cb, "Onion");

/*Copy the previous check box*/
cb = lv_cb_create(cont, cb);
lv_cb_set_text(cb, "Carrot");

/*Copy the previous check box*/
cb = lv_cb_create(cont, cb);
lv_cb_set_text(cb, "Salad");

/*Align the container to the middle*/
lv_obj_align(cont, NULL, LV_ALIGN_CENTER, 0, 0);

lv_obj_t *

lv_cb_create

(lv_obj_t * par, lv_obj_t * copy);

Create a check box objects

par pointer to an object, it will be the parent of the new check box

copy pointer to a check box object, if not NULL then the new object will be copied from it

return pointer to the created check box

void

lv_cb_set_text

(lv_obj_t * cb, const char * txt);

Set the text of a check box

cb pointer to a check box

txt the text of the check box

void

lv_cb_set_checked

(lv_obj_t * cb, bool checked);

Set the state of the check box

cb pointer to a check box object

checked true: make the check box checked; false: make it unchecked

void

lv_cb_set_inactive

(lv_obj_t * cb);

Make the check box inactive (disabled)

cb pointer to a check box object

void

lv_cb_set_action

(lv_obj_t * cb, lv_action_t action);

Set a function to call when the check box is clicked

cb pointer to a check box object

void

lv_cb_set_style

(lv_obj_t * cb, lv_cb_style_t type, lv_style_t *style);

Set a style of a check box

cb pointer to check box object

type which style should be set

style pointer to a style

const

char

* lv_cb_get_text(lv_obj_t * cb);

Get the text of a check box

cb pointer to check box object

return pointer to the text of the check box

bool

lv_cb_is_checked

(lv_obj_t * cb);

Get the current state of the check box

cb pointer to a check box object

return true: checked; false: not checked

lv_action_t

lv_cb_get_action

(lv_obj_t * cb);

Get the action of a check box

cb pointer to a button object

return pointer to the action function

lv_style_t *

lv_cb_get_style

(lv_obj_t * cb, lv_cb_style_t type);

Get a style of a button

cb pointer to check box object

type which style should be get

return style pointer to the style

LittlevGL - Open-source Embedded GUI Library

LittlevGL is a free and open-source graphics library providing everything you need to create embedded GUI with easy-to-use graphical elements, beautiful visual effects and low memory footprint.

If you like LittlevGL, please
support its deveopment!


The founder of Littlev Graphics Library (LittlevGL) and related software modules is:
Gábor Kiss-Vámosi
All Rights Reserved ©  2018 Hungary