Overview

The windows are one of the most complex container-like objects. They are built from two main parts: a header Container on the top and a Page for the content below the header.

On the header there is title which can be modified by: lv_win_set_title(win, "New title"). The title always inherits the style of the header.

You can add control buttons to the right side of the header with: lv_win_add_btn(win, "U:/close", my_close_action). The second parameter is an image file path, the third parameter is a function to call when the button is released. You can use symbols as images as well like: lv_win_add_btn(win, SYMBOL_CLOSE, my_close_action).

You can modify the size of the control buttons with the lv_win_set_btn_size(win, new_size) function.

The scrollbar behavior can be set by lv_win_set_sb_mode(win, LV_SB_MODE_...).

To set a layout for the content use lv_win_set_layout(win, LV_LAYOUT_...).

Style usage

Use lv_win_set_style(win, LV_WIN_STYLE_..., &style) to set a new style for an element of the window:

  • LV_WIN_STYE_BG main background which uses all style.body properties (header and content page are placed on it) (default: lv_style_plain)
  • LV_WIN_STYLE_CONTENT_BG content page's background which uses all style.body properties (default: lv_style_transp)
  • LV_WIN_STYLE_CONTENT_SCRL content page's scrollable part which uses all style.body properties (default: lv_style_transp)
  • LV_WIN_STYLE_SB scroll bar's style which uses all style.body properties. hor/ver* padding sets the scrollbars' padding respectively and the inner padding sets the scrollbar's width. (default: lv_style_pretty_color)
  • LV_WIN_STYLE_HEADER header's style which uses all style.body properties (default: lv_style_plain_color)
  • LV_WIN_STYLE_BTN_REL released button's style (on header) which uses all style.body properties (default: lv_style_btn_rel)
  • LV_WIN_STYLE_BTN_PR released button's style (on header) which uses all style.body properties (default: lv_style_btn_pr)

Notes

Example of Window in Littlev Graphics Library

						/*Create a scroll bar style*/
static lv_style_t style_sb;
lv_style_copy(&style_sb, &lv_style_plain);
style_sb.body.main_color = LV_COLOR_BLACK;
style_sb.body.grad_color = LV_COLOR_BLACK;
style_sb.body.border.color = LV_COLOR_WHITE;
style_sb.body.border.width = 1;
style_sb.body.border.opa = LV_OPA_70;
style_sb.body.radius = LV_RADIUS_CIRCLE;
style_sb.body.opa = LV_OPA_60;

/*Create a window*/
lv_obj_t * win = lv_win_create(lv_scr_act(), NULL);
lv_win_set_title(win, "Example window");                        /*Set the title*/
lv_win_set_style(win, LV_WIN_STYLE_SB, &style_sb);              /*Set the scroll bar style*/


/*Add control button to the header*/
lv_win_add_btn(win, SYMBOL_SETTINGS, my_setup_action);            /*Add a setup button*/
lv_win_add_btn(win, SYMBOL_CLOSE, lv_win_close_action);           /*Add close button and use built-in close action*/


/*Add some dummy content*/
lv_obj_t * txt = lv_label_create(win, NULL);
lv_label_set_text(txt, "This is the content of the window\n\n"
                       "You can add control buttons to\nthe window header\n\n"
                       "You can scroll it\n\n"
                       "See the scroll bar on the right!");

lv_obj_t *

lv_win_create

(lv_obj_t * par, lv_obj_t * copy);

Create a window objects

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

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

return pointer to the created window

lv_obj_t *

lv_win_add_btn

(lv_obj_t * win, const void * img_src, lv_action_t rel_action);

Add control button to the header of the window

win pointer to a window object

img_src an image source ('lv_img_t' variable, path to file or a symbol)

rel_action a function pointer to call when the button is released

return pointer to the created button object

lv_res_t

lv_win_close_action

(lv_obj_t * btn);

A release action which can be assigned to a window control button to close it

btn pointer to the released button

return always LV_ACTION_RES_INV because the button is deleted with the window

void

lv_win_set_title

(lv_obj_t * win, const char * title);

Set the title of a window

win pointer to a window object

title string of the new title

void

lv_win_set_btn_size

(lv_obj_t * win, lv_coord_t size);

Set the control button size of a window

win pointer to a window object

return control button size

void

lv_win_set_sb_mode

(lv_obj_t *win, lv_sb_mode_t sb_mode);

Set the scroll bar mode of a window

win pointer to a window object

sb_mode the new scroll bar mode from 'lv_sb_mode_t'

void

lv_win_set_layout

(lv_obj_t *win, lv_layout_t layout);

Set the layout of the window

win pointer to a window object

layout the layout from 'lv_layout_t'

void

lv_win_set_style

(lv_obj_t *win, lv_win_style_t type, lv_style_t *style);

Set a style of a window

win pointer to a window object

type which style should be set

style pointer to a style

const

char

* lv_win_get_title(lv_obj_t * win);

Get the title of a window

win pointer to a window object

return title string of the window

lv_coord_t

lv_win_get_btn_size

(lv_obj_t * win);

Get the control button size of a window

win pointer to a window object

return control button size

lv_layout_t

lv_win_get_layout

(lv_obj_t *win);

Get the layout of a window

win pointer to a window object

return the layout of the window (from 'lv_layout_t')

lv_sb_mode_t

lv_win_get_sb_mode

(lv_obj_t *win);

Get the scroll bar mode of a window

win pointer to a window object

return the scroll bar mode of the window (from 'lv_sb_mode_t')

lv_coord_t

lv_win_get_width

(lv_obj_t * win);

Get width of the content area (page scrollable) of the window

win pointer to a window object

return the width of the content area

lv_obj_t *

lv_win_get_from_btn

(lv_obj_t * ctrl_btn);

Get the pointer of a widow from one of its control button.
It is useful in the action of the control buttons where only button is known.

ctrl_btn pointer to a control button of a window

return pointer to the window of 'ctrl_btn'

lv_style_t *

lv_win_get_style

(lv_obj_t *win, lv_win_style_t type);

Get a style of a window

win pointer to a button object

type which style window be get

return style pointer to a style

void

lv_win_focus

(lv_obj_t * win, lv_obj_t * obj, uint16_t anim_time);

Focus on an object. It ensures that the object will be visible in the window.

win pointer to a window object

obj pointer to an object to focus (must be in the window)

anim_time scroll animation time in milliseconds (0: no animation)

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