2016-10-07 17:33:35 +02:00
|
|
|
/**
|
|
|
|
* @file lv_win.c
|
2018-06-19 09:49:58 +02:00
|
|
|
*
|
2016-10-07 17:33:35 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*********************
|
|
|
|
* INCLUDES
|
|
|
|
*********************/
|
2018-07-07 11:53:22 +02:00
|
|
|
#include "lv_win.h"
|
2019-03-07 00:05:16 +01:00
|
|
|
#if LV_USE_WIN != 0
|
2016-10-07 17:33:35 +02:00
|
|
|
|
2019-09-24 16:30:38 +02:00
|
|
|
#include "../lv_core/lv_debug.h"
|
2017-11-16 15:32:33 +01:00
|
|
|
#include "../lv_themes/lv_theme.h"
|
2019-02-20 23:58:13 +01:00
|
|
|
#include "../lv_core/lv_disp.h"
|
2016-10-07 17:33:35 +02:00
|
|
|
|
|
|
|
/*********************
|
|
|
|
* DEFINES
|
|
|
|
*********************/
|
2019-09-26 10:51:54 +02:00
|
|
|
#define LV_OBJX_NAME "lv_win"
|
2020-02-11 09:40:31 +01:00
|
|
|
#define DEF_TITLE "Window"
|
2016-10-07 17:33:35 +02:00
|
|
|
|
|
|
|
/**********************
|
|
|
|
* TYPEDEFS
|
|
|
|
**********************/
|
|
|
|
|
|
|
|
/**********************
|
|
|
|
* STATIC PROTOTYPES
|
|
|
|
**********************/
|
2017-11-15 21:06:44 +01:00
|
|
|
static lv_res_t lv_win_signal(lv_obj_t * win, lv_signal_t sign, void * param);
|
2020-02-12 08:54:03 +01:00
|
|
|
static lv_design_res_t lv_win_header_design(lv_obj_t * header, const lv_area_t * clip_area, lv_design_mode_t mode);
|
2020-02-11 09:40:31 +01:00
|
|
|
static lv_style_list_t * lv_win_get_style(lv_obj_t * win, uint8_t part);
|
2016-10-07 17:33:35 +02:00
|
|
|
static void lv_win_realign(lv_obj_t * win);
|
|
|
|
|
|
|
|
/**********************
|
|
|
|
* STATIC VARIABLES
|
|
|
|
**********************/
|
2020-02-12 08:54:03 +01:00
|
|
|
static lv_design_cb_t ancestor_header_design;
|
2019-02-26 09:25:46 +01:00
|
|
|
static lv_signal_cb_t ancestor_signal;
|
2016-10-07 17:33:35 +02:00
|
|
|
|
|
|
|
/**********************
|
|
|
|
* MACROS
|
|
|
|
**********************/
|
|
|
|
|
|
|
|
/**********************
|
|
|
|
* GLOBAL FUNCTIONS
|
|
|
|
**********************/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a window objects
|
|
|
|
* @param par pointer to an object, it will be the parent of the new window
|
2017-01-14 23:54:16 +01:00
|
|
|
* @param copy pointer to a window object, if not NULL then the new object will be copied from it
|
2016-10-07 17:33:35 +02:00
|
|
|
* @return pointer to the created window
|
|
|
|
*/
|
2018-07-30 06:52:29 +02:00
|
|
|
lv_obj_t * lv_win_create(lv_obj_t * par, const lv_obj_t * copy)
|
2016-10-07 17:33:35 +02:00
|
|
|
{
|
2018-10-05 17:22:49 +02:00
|
|
|
LV_LOG_TRACE("window create started");
|
2018-07-25 17:57:08 +02:00
|
|
|
|
2016-10-07 17:33:35 +02:00
|
|
|
/*Create the ancestor object*/
|
2017-04-13 10:20:35 +02:00
|
|
|
lv_obj_t * new_win = lv_obj_create(par, copy);
|
2019-09-24 23:14:17 +02:00
|
|
|
LV_ASSERT_MEM(new_win);
|
2018-07-25 13:33:53 +02:00
|
|
|
if(new_win == NULL) return NULL;
|
|
|
|
|
2019-04-10 06:40:49 +02:00
|
|
|
if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_cb(new_win);
|
2018-06-19 09:49:58 +02:00
|
|
|
|
2016-10-07 17:33:35 +02:00
|
|
|
/*Allocate the object type specific extended data*/
|
2017-10-20 10:17:02 +02:00
|
|
|
lv_win_ext_t * ext = lv_obj_allocate_ext_attr(new_win, sizeof(lv_win_ext_t));
|
2019-09-24 23:14:17 +02:00
|
|
|
LV_ASSERT_MEM(ext);
|
2019-12-03 18:16:14 +01:00
|
|
|
if(ext == NULL) {
|
|
|
|
lv_obj_del(new_win);
|
|
|
|
return NULL;
|
|
|
|
}
|
2018-07-25 13:33:53 +02:00
|
|
|
|
2019-04-04 07:15:40 +02:00
|
|
|
ext->page = NULL;
|
|
|
|
ext->header = NULL;
|
2020-02-11 09:40:31 +01:00
|
|
|
ext->title_txt = lv_mem_alloc(strlen(DEF_TITLE) + 1);
|
|
|
|
strcpy(ext->title_txt, DEF_TITLE);
|
2016-10-07 17:33:35 +02:00
|
|
|
|
|
|
|
/*Init the new window object*/
|
|
|
|
if(copy == NULL) {
|
2019-04-09 15:24:20 +02:00
|
|
|
/* Set a size which fits into the parent.
|
2019-04-10 06:21:54 +02:00
|
|
|
* Don't use `par` directly because if the window is created on a page it is moved to the
|
|
|
|
* scrollable so the parent has changed */
|
2020-01-30 05:48:49 +01:00
|
|
|
lv_coord_t w;
|
|
|
|
lv_coord_t h;
|
|
|
|
if(par) {
|
|
|
|
w = lv_obj_get_width_fit(lv_obj_get_parent(new_win));
|
|
|
|
h = lv_obj_get_height_fit(lv_obj_get_parent(new_win));
|
|
|
|
} else {
|
|
|
|
w = lv_disp_get_hor_res(NULL);
|
|
|
|
h = lv_disp_get_ver_res(NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
lv_obj_set_size(new_win, w, h);
|
2019-04-09 15:24:20 +02:00
|
|
|
|
2017-04-13 10:20:35 +02:00
|
|
|
ext->page = lv_page_create(new_win, NULL);
|
|
|
|
lv_obj_set_protect(ext->page, LV_PROTECT_PARENT);
|
2017-11-18 00:18:19 +01:00
|
|
|
lv_page_set_sb_mode(ext->page, LV_SB_MODE_AUTO);
|
2020-02-11 09:40:31 +01:00
|
|
|
lv_style_list_reset(lv_obj_get_style_list(ext->page, LV_PAGE_PART_BG));
|
2016-12-17 10:50:28 +01:00
|
|
|
|
2018-06-19 09:49:58 +02:00
|
|
|
/*Create a holder for the header*/
|
|
|
|
ext->header = lv_obj_create(new_win, NULL);
|
2020-02-12 08:54:03 +01:00
|
|
|
/*Move back to window background because it's automatically moved to the content page*/
|
2018-06-19 09:49:58 +02:00
|
|
|
lv_obj_set_protect(ext->header, LV_PROTECT_PARENT);
|
|
|
|
lv_obj_set_parent(ext->header, new_win);
|
2020-02-12 08:54:03 +01:00
|
|
|
if(ancestor_header_design == NULL) ancestor_header_design= lv_obj_get_design_cb(ext->header);
|
|
|
|
lv_obj_set_design_cb(ext->header, lv_win_header_design);
|
2019-09-27 03:28:44 +02:00
|
|
|
lv_obj_set_signal_cb(new_win, lv_win_signal);
|
|
|
|
|
2020-02-11 09:40:31 +01:00
|
|
|
lv_theme_apply(new_win, LV_THEME_WIN);
|
2016-10-07 17:33:35 +02:00
|
|
|
}
|
|
|
|
/*Copy an existing object*/
|
|
|
|
else {
|
2018-06-19 09:49:58 +02:00
|
|
|
lv_win_ext_t * copy_ext = lv_obj_get_ext_attr(copy);
|
|
|
|
/*Create the objects*/
|
2019-04-04 07:15:40 +02:00
|
|
|
ext->header = lv_obj_create(new_win, copy_ext->header);
|
2020-02-11 09:40:31 +01:00
|
|
|
ext->title_txt = lv_mem_alloc(strlen(copy_ext->title_txt) + 1);
|
|
|
|
strcpy(ext->title_txt, copy_ext->title_txt);
|
2019-04-04 07:15:40 +02:00
|
|
|
ext->page = lv_page_create(new_win, copy_ext->page);
|
2016-10-07 17:33:35 +02:00
|
|
|
|
2018-06-19 09:49:58 +02:00
|
|
|
/*Copy the control buttons*/
|
|
|
|
lv_obj_t * child;
|
|
|
|
lv_obj_t * cbtn;
|
|
|
|
child = lv_obj_get_child_back(copy_ext->header, NULL);
|
2017-11-15 21:06:44 +01:00
|
|
|
child = lv_obj_get_child_back(copy_ext->header, child); /*Sip the title*/
|
2018-06-19 09:49:58 +02:00
|
|
|
while(child != NULL) {
|
|
|
|
cbtn = lv_btn_create(ext->header, child);
|
|
|
|
lv_img_create(cbtn, lv_obj_get_child(child, NULL));
|
|
|
|
child = lv_obj_get_child_back(copy_ext->header, child);
|
|
|
|
}
|
2016-10-07 17:33:35 +02:00
|
|
|
|
2019-02-26 09:25:46 +01:00
|
|
|
lv_obj_set_signal_cb(new_win, lv_win_signal);
|
2016-10-07 17:33:35 +02:00
|
|
|
}
|
2018-06-19 09:49:58 +02:00
|
|
|
|
2019-02-26 16:07:40 +01:00
|
|
|
/*Refresh the style with new signal function*/
|
|
|
|
lv_obj_refresh_style(new_win);
|
|
|
|
|
2017-01-02 14:10:32 +01:00
|
|
|
lv_win_realign(new_win);
|
|
|
|
|
2018-10-05 17:22:49 +02:00
|
|
|
LV_LOG_INFO("window created");
|
2018-07-25 17:57:08 +02:00
|
|
|
|
2016-10-07 17:33:35 +02:00
|
|
|
return new_win;
|
|
|
|
}
|
|
|
|
|
2018-03-16 11:53:27 -04:00
|
|
|
/**
|
|
|
|
* Delete all children of the scrl object, without deleting scrl child.
|
2019-09-26 12:54:40 +02:00
|
|
|
* @param win pointer to an object
|
2018-03-16 11:53:27 -04:00
|
|
|
*/
|
2019-09-26 12:54:40 +02:00
|
|
|
void lv_win_clean(lv_obj_t * win)
|
2018-03-16 11:53:27 -04:00
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(win, LV_OBJX_NAME);
|
|
|
|
|
|
|
|
lv_obj_t * scrl = lv_page_get_scrl(win);
|
2018-03-16 11:53:27 -04:00
|
|
|
lv_obj_clean(scrl);
|
|
|
|
}
|
2016-10-07 17:33:35 +02:00
|
|
|
|
2017-11-15 21:06:44 +01:00
|
|
|
/*======================
|
|
|
|
* Add/remove functions
|
|
|
|
*=====================*/
|
2016-10-07 17:33:35 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Add control button to the header of the window
|
|
|
|
* @param win pointer to a window object
|
2018-02-23 13:56:04 +01:00
|
|
|
* @param img_src an image source ('lv_img_t' variable, path to file or a symbol)
|
2016-10-07 17:33:35 +02:00
|
|
|
* @return pointer to the created button object
|
|
|
|
*/
|
2019-06-21 15:26:28 +02:00
|
|
|
lv_obj_t * lv_win_add_btn(lv_obj_t * win, const void * img_src)
|
2016-10-07 17:33:35 +02:00
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(win, LV_OBJX_NAME);
|
|
|
|
LV_ASSERT_NULL(img_src);
|
|
|
|
|
2017-11-15 21:06:44 +01:00
|
|
|
lv_win_ext_t * ext = lv_obj_get_ext_attr(win);
|
2016-10-07 17:33:35 +02:00
|
|
|
|
2018-06-19 09:49:58 +02:00
|
|
|
lv_obj_t * btn = lv_btn_create(ext->header, NULL);
|
2020-02-11 09:40:31 +01:00
|
|
|
lv_theme_apply(btn, LV_THEME_WIN_BTN);
|
|
|
|
lv_coord_t btn_size = lv_obj_get_height_fit(ext->header);
|
|
|
|
lv_obj_set_size(btn, btn_size, btn_size);
|
2016-12-17 21:22:16 +01:00
|
|
|
|
2017-11-15 21:06:44 +01:00
|
|
|
lv_obj_t * img = lv_img_create(btn, NULL);
|
|
|
|
lv_obj_set_click(img, false);
|
2018-02-23 13:56:04 +01:00
|
|
|
lv_img_set_src(img, img_src);
|
2016-10-07 17:33:35 +02:00
|
|
|
|
2017-11-15 21:06:44 +01:00
|
|
|
lv_win_realign(win);
|
2016-10-07 17:33:35 +02:00
|
|
|
|
2017-11-15 21:06:44 +01:00
|
|
|
return btn;
|
2016-10-07 17:33:35 +02:00
|
|
|
}
|
|
|
|
|
2017-11-15 21:06:44 +01:00
|
|
|
/*=====================
|
|
|
|
* Setter functions
|
|
|
|
*====================*/
|
|
|
|
|
2016-12-16 07:41:34 +01:00
|
|
|
/**
|
2019-03-07 00:05:16 +01:00
|
|
|
* Can be assigned to a window control button to close the window
|
|
|
|
* @param btn pointer to the control button on teh widows header
|
|
|
|
* @param evet the event type
|
2016-12-16 07:41:34 +01:00
|
|
|
*/
|
2019-06-21 15:26:28 +02:00
|
|
|
void lv_win_close_event_cb(lv_obj_t * btn, lv_event_t event)
|
2016-12-16 07:41:34 +01:00
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(btn, "lv_btn");
|
|
|
|
|
2019-03-07 00:05:16 +01:00
|
|
|
if(event == LV_EVENT_RELEASED) {
|
|
|
|
lv_obj_t * win = lv_win_get_from_btn(btn);
|
2016-12-16 07:41:34 +01:00
|
|
|
|
2019-03-07 00:05:16 +01:00
|
|
|
lv_obj_del(win);
|
|
|
|
}
|
2016-12-16 07:41:34 +01:00
|
|
|
}
|
|
|
|
|
2016-10-07 17:33:35 +02:00
|
|
|
/**
|
|
|
|
* Set the title of a window
|
|
|
|
* @param win pointer to a window object
|
|
|
|
* @param title string of the new title
|
|
|
|
*/
|
|
|
|
void lv_win_set_title(lv_obj_t * win, const char * title)
|
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(win, LV_OBJX_NAME);
|
|
|
|
LV_ASSERT_STR(title);
|
|
|
|
|
2018-06-19 09:49:58 +02:00
|
|
|
lv_win_ext_t * ext = lv_obj_get_ext_attr(win);
|
2016-10-07 17:33:35 +02:00
|
|
|
|
2020-02-11 09:40:31 +01:00
|
|
|
ext->title_txt = lv_mem_realloc(ext->title_txt, strlen(title) + 1);
|
|
|
|
strcpy(ext->title_txt, title);
|
|
|
|
lv_obj_invalidate(ext->header);
|
2016-10-07 17:33:35 +02:00
|
|
|
}
|
|
|
|
|
2017-04-13 13:34:57 +02:00
|
|
|
/**
|
2020-02-11 09:40:31 +01:00
|
|
|
* Set the height of the header
|
2017-04-13 13:34:57 +02:00
|
|
|
* @param win pointer to a window object
|
2020-02-11 09:40:31 +01:00
|
|
|
* @param height height of the header
|
2017-04-13 13:34:57 +02:00
|
|
|
*/
|
2020-02-11 09:40:31 +01:00
|
|
|
void lv_win_set_header_height(lv_obj_t * win, lv_coord_t height)
|
2017-04-13 13:34:57 +02:00
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(win, LV_OBJX_NAME);
|
|
|
|
|
2017-10-20 10:17:02 +02:00
|
|
|
lv_win_ext_t * ext = lv_obj_get_ext_attr(win);
|
2017-04-13 13:34:57 +02:00
|
|
|
|
2020-02-11 09:40:31 +01:00
|
|
|
lv_obj_set_height(ext->header, height);
|
2017-04-13 13:34:57 +02:00
|
|
|
lv_win_realign(win);
|
|
|
|
}
|
|
|
|
|
2019-09-18 06:29:54 +02:00
|
|
|
/**
|
|
|
|
* Set the size of the content area.
|
|
|
|
* @param win pointer to a window object
|
|
|
|
* @param w width
|
|
|
|
* @param h height (the window will be higher with the height of the header)
|
|
|
|
*/
|
|
|
|
void lv_win_set_content_size(lv_obj_t * win, lv_coord_t w, lv_coord_t h)
|
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(win, LV_OBJX_NAME);
|
|
|
|
|
2019-09-18 06:29:54 +02:00
|
|
|
lv_win_ext_t * ext = lv_obj_get_ext_attr(win);
|
|
|
|
h += lv_obj_get_height(ext->header);
|
2019-10-03 06:11:40 +02:00
|
|
|
|
|
|
|
lv_obj_set_size(win, w, h);
|
2019-09-18 06:29:54 +02:00
|
|
|
}
|
|
|
|
|
2018-09-10 21:30:25 +02:00
|
|
|
/**
|
|
|
|
* Set the layout of the window
|
|
|
|
* @param win pointer to a window object
|
|
|
|
* @param layout the layout from 'lv_layout_t'
|
|
|
|
*/
|
2018-10-05 17:22:49 +02:00
|
|
|
void lv_win_set_layout(lv_obj_t * win, lv_layout_t layout)
|
2018-09-10 21:30:25 +02:00
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(win, LV_OBJX_NAME);
|
|
|
|
|
2018-09-10 21:30:25 +02:00
|
|
|
lv_win_ext_t * ext = lv_obj_get_ext_attr(win);
|
|
|
|
lv_page_set_scrl_layout(ext->page, layout);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the scroll bar mode of a window
|
|
|
|
* @param win pointer to a window object
|
|
|
|
* @param sb_mode the new scroll bar mode from 'lv_sb_mode_t'
|
|
|
|
*/
|
2018-10-05 17:22:49 +02:00
|
|
|
void lv_win_set_sb_mode(lv_obj_t * win, lv_sb_mode_t sb_mode)
|
2018-09-10 21:30:25 +02:00
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(win, LV_OBJX_NAME);
|
|
|
|
|
2018-09-10 21:30:25 +02:00
|
|
|
lv_win_ext_t * ext = lv_obj_get_ext_attr(win);
|
|
|
|
lv_page_set_sb_mode(ext->page, sb_mode);
|
|
|
|
}
|
2019-06-19 00:35:35 +02:00
|
|
|
/**
|
|
|
|
* Set focus animation duration on `lv_win_focus()`
|
|
|
|
* @param win pointer to a window object
|
|
|
|
* @param anim_time duration of animation [ms]
|
|
|
|
*/
|
|
|
|
void lv_win_set_anim_time(lv_obj_t * win, uint16_t anim_time)
|
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(win, LV_OBJX_NAME);
|
|
|
|
|
2019-06-19 00:35:35 +02:00
|
|
|
lv_page_set_anim_time(lv_win_get_content(win), anim_time);
|
|
|
|
}
|
2018-09-10 21:30:25 +02:00
|
|
|
|
2018-11-25 21:31:54 -05:00
|
|
|
/**
|
|
|
|
* Set drag status of a window. If set to 'true' window can be dragged like on a PC.
|
|
|
|
* @param win pointer to a window object
|
2018-12-22 19:45:55 +01:00
|
|
|
* @param en whether dragging is enabled
|
2018-11-25 21:31:54 -05:00
|
|
|
*/
|
2019-04-04 07:15:40 +02:00
|
|
|
void lv_win_set_drag(lv_obj_t * win, bool en)
|
2018-11-25 21:31:54 -05:00
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(win, LV_OBJX_NAME);
|
|
|
|
|
2019-04-04 07:15:40 +02:00
|
|
|
lv_win_ext_t * ext = lv_obj_get_ext_attr(win);
|
2018-11-25 21:31:54 -05:00
|
|
|
lv_obj_t * win_header = ext->header;
|
2018-12-22 19:45:55 +01:00
|
|
|
lv_obj_set_drag_parent(win_header, en);
|
|
|
|
lv_obj_set_drag(win, en);
|
2018-11-25 21:31:54 -05:00
|
|
|
}
|
2017-11-15 21:06:44 +01:00
|
|
|
|
2016-10-07 17:33:35 +02:00
|
|
|
/*=====================
|
|
|
|
* Getter functions
|
|
|
|
*====================*/
|
2017-04-13 10:20:35 +02:00
|
|
|
|
2016-12-15 10:31:30 +01:00
|
|
|
/**
|
|
|
|
* Get the title of a window
|
|
|
|
* @param win pointer to a window object
|
|
|
|
* @return title string of the window
|
|
|
|
*/
|
2018-07-30 06:52:29 +02:00
|
|
|
const char * lv_win_get_title(const lv_obj_t * win)
|
2016-12-15 10:31:30 +01:00
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(win, LV_OBJX_NAME);
|
|
|
|
|
2018-06-19 09:49:58 +02:00
|
|
|
lv_win_ext_t * ext = lv_obj_get_ext_attr(win);
|
2020-02-11 09:40:31 +01:00
|
|
|
return ext->title_txt;
|
2016-12-15 10:31:30 +01:00
|
|
|
}
|
|
|
|
|
2017-04-13 13:34:57 +02:00
|
|
|
/**
|
2019-04-04 07:15:40 +02:00
|
|
|
* Get the content holder object of window (`lv_page`) to allow additional customization
|
|
|
|
* @param win pointer to a window object
|
|
|
|
* @return the Page object where the window's content is
|
|
|
|
*/
|
2018-08-26 15:55:22 +02:00
|
|
|
lv_obj_t * lv_win_get_content(const lv_obj_t * win)
|
2017-11-18 00:18:19 +01:00
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(win, LV_OBJX_NAME);
|
|
|
|
|
2017-11-18 00:18:19 +01:00
|
|
|
lv_win_ext_t * ext = lv_obj_get_ext_attr(win);
|
2018-08-26 15:55:22 +02:00
|
|
|
return ext->page;
|
2017-11-18 00:18:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-02-11 09:40:31 +01:00
|
|
|
* Get the header height
|
2017-04-13 13:34:57 +02:00
|
|
|
* @param win pointer to a window object
|
2020-02-11 09:40:31 +01:00
|
|
|
* @return header height
|
2017-04-13 13:34:57 +02:00
|
|
|
*/
|
2020-02-11 09:40:31 +01:00
|
|
|
lv_coord_t lv_win_get_header_height(const lv_obj_t * win)
|
2017-04-13 13:34:57 +02:00
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(win, LV_OBJX_NAME);
|
|
|
|
|
2017-10-20 10:17:02 +02:00
|
|
|
lv_win_ext_t * ext = lv_obj_get_ext_attr(win);
|
2020-02-11 09:40:31 +01:00
|
|
|
return lv_obj_get_height(ext->header);
|
2017-04-13 13:34:57 +02:00
|
|
|
}
|
|
|
|
|
2016-12-15 10:31:30 +01:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
* @param ctrl_btn pointer to a control button of a window
|
|
|
|
* @return pointer to the window of 'ctrl_btn'
|
|
|
|
*/
|
2018-07-30 06:52:29 +02:00
|
|
|
lv_obj_t * lv_win_get_from_btn(const lv_obj_t * ctrl_btn)
|
2016-12-15 10:31:30 +01:00
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(ctrl_btn, "lv_btn");
|
|
|
|
|
2018-06-19 09:49:58 +02:00
|
|
|
lv_obj_t * header = lv_obj_get_parent(ctrl_btn);
|
2019-04-04 07:15:40 +02:00
|
|
|
lv_obj_t * win = lv_obj_get_parent(header);
|
2016-12-15 10:31:30 +01:00
|
|
|
|
2018-06-19 09:49:58 +02:00
|
|
|
return win;
|
2016-12-15 10:31:30 +01:00
|
|
|
}
|
2016-10-07 17:33:35 +02:00
|
|
|
|
2018-09-10 21:30:25 +02:00
|
|
|
/**
|
|
|
|
* Get the layout of a window
|
|
|
|
* @param win pointer to a window object
|
|
|
|
* @return the layout of the window (from 'lv_layout_t')
|
|
|
|
*/
|
2018-10-05 17:22:49 +02:00
|
|
|
lv_layout_t lv_win_get_layout(lv_obj_t * win)
|
2018-09-10 21:30:25 +02:00
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(win, LV_OBJX_NAME);
|
|
|
|
|
2018-09-10 21:30:25 +02:00
|
|
|
lv_win_ext_t * ext = lv_obj_get_ext_attr(win);
|
|
|
|
return lv_page_get_scrl_layout(ext->page);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the scroll bar mode of a window
|
|
|
|
* @param win pointer to a window object
|
|
|
|
* @return the scroll bar mode of the window (from 'lv_sb_mode_t')
|
|
|
|
*/
|
2018-10-05 17:22:49 +02:00
|
|
|
lv_sb_mode_t lv_win_get_sb_mode(lv_obj_t * win)
|
2018-09-10 21:30:25 +02:00
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(win, LV_OBJX_NAME);
|
|
|
|
|
2018-09-10 21:30:25 +02:00
|
|
|
lv_win_ext_t * ext = lv_obj_get_ext_attr(win);
|
|
|
|
return lv_page_get_sb_mode(ext->page);
|
|
|
|
}
|
|
|
|
|
2019-06-19 00:35:35 +02:00
|
|
|
/**
|
|
|
|
* Get focus animation duration
|
|
|
|
* @param win pointer to a window object
|
|
|
|
* @return duration of animation [ms]
|
|
|
|
*/
|
|
|
|
uint16_t lv_win_get_anim_time(const lv_obj_t * win)
|
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(win, LV_OBJX_NAME);
|
|
|
|
|
2019-06-19 00:35:35 +02:00
|
|
|
return lv_page_get_anim_time(lv_win_get_content(win));
|
|
|
|
}
|
|
|
|
|
2018-09-10 21:30:25 +02:00
|
|
|
/**
|
|
|
|
* Get width of the content area (page scrollable) of the window
|
|
|
|
* @param win pointer to a window object
|
|
|
|
* @return the width of the content_bg area
|
|
|
|
*/
|
|
|
|
lv_coord_t lv_win_get_width(lv_obj_t * win)
|
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(win, LV_OBJX_NAME);
|
|
|
|
|
2019-04-11 19:59:55 +08:00
|
|
|
lv_win_ext_t * ext = lv_obj_get_ext_attr(win);
|
|
|
|
lv_obj_t * scrl = lv_page_get_scrl(ext->page);
|
2020-02-11 09:40:31 +01:00
|
|
|
lv_coord_t left = lv_obj_get_style_pad_left(win, LV_WIN_PART_BG);
|
|
|
|
lv_coord_t right = lv_obj_get_style_pad_left(win, LV_WIN_PART_BG);
|
2018-09-10 21:30:25 +02:00
|
|
|
|
2020-02-11 09:40:31 +01:00
|
|
|
return lv_obj_get_width_fit(scrl) - left - right;
|
2017-11-15 21:06:44 +01:00
|
|
|
}
|
|
|
|
|
2017-11-18 00:18:19 +01:00
|
|
|
/*=====================
|
|
|
|
* Other functions
|
|
|
|
*====================*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Focus on an object. It ensures that the object will be visible in the window.
|
|
|
|
* @param win pointer to a window object
|
|
|
|
* @param obj pointer to an object to focus (must be in the window)
|
2019-06-19 00:35:35 +02:00
|
|
|
* @param anim_en LV_ANIM_ON focus with an animation; LV_ANIM_OFF focus without animation
|
2017-11-18 00:18:19 +01:00
|
|
|
*/
|
2019-06-19 00:35:35 +02:00
|
|
|
void lv_win_focus(lv_obj_t * win, lv_obj_t * obj, lv_anim_enable_t anim_en)
|
2017-11-18 00:18:19 +01:00
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(win, LV_OBJX_NAME);
|
|
|
|
LV_ASSERT_OBJ(obj, "");
|
|
|
|
|
|
|
|
|
2018-06-19 09:49:58 +02:00
|
|
|
lv_win_ext_t * ext = lv_obj_get_ext_attr(win);
|
2019-06-19 00:35:35 +02:00
|
|
|
lv_page_focus(ext->page, obj, anim_en);
|
2017-11-18 00:18:19 +01:00
|
|
|
}
|
|
|
|
|
2016-10-07 17:33:35 +02:00
|
|
|
/**********************
|
|
|
|
* STATIC FUNCTIONS
|
|
|
|
**********************/
|
2020-02-12 08:54:03 +01:00
|
|
|
/**
|
|
|
|
* Handle the drawing related tasks of the window header
|
|
|
|
* @param header pointer to an object
|
|
|
|
* @param clip_area the object will be drawn only in this area
|
|
|
|
* @param mode LV_DESIGN_COVER_CHK: only check if the object fully covers the 'mask_p' area
|
|
|
|
* (return 'true' if yes)
|
|
|
|
* LV_DESIGN_DRAW: draw the object (always return 'true')
|
|
|
|
* LV_DESIGN_DRAW_POST: drawing after every children are drawn
|
|
|
|
* @param return an element of `lv_design_res_t`
|
|
|
|
*/
|
|
|
|
static lv_design_res_t lv_win_header_design(lv_obj_t * header, const lv_area_t * clip_area, lv_design_mode_t mode)
|
|
|
|
{
|
|
|
|
/*Return false if the object is not covers the mask_p area*/
|
|
|
|
if(mode == LV_DESIGN_COVER_CHK) {
|
|
|
|
return ancestor_header_design(header, clip_area, mode);
|
|
|
|
}
|
|
|
|
/*Draw the object*/
|
|
|
|
else if(mode == LV_DESIGN_DRAW_MAIN) {
|
|
|
|
ancestor_header_design(header, clip_area, mode);
|
|
|
|
|
|
|
|
lv_obj_t * win = lv_obj_get_parent(header);
|
|
|
|
lv_win_ext_t * ext = lv_obj_get_ext_attr(win);
|
|
|
|
|
|
|
|
lv_style_int_t left = lv_obj_get_style_pad_left(header, LV_OBJ_PART_MAIN);
|
|
|
|
lv_style_int_t top = lv_obj_get_style_pad_top(header, LV_OBJ_PART_MAIN);
|
|
|
|
|
|
|
|
lv_draw_label_dsc_t label_dsc;
|
|
|
|
lv_draw_label_dsc_init(&label_dsc);
|
|
|
|
lv_obj_init_draw_label_dsc(header, LV_OBJ_PART_MAIN, &label_dsc);
|
2016-10-07 17:33:35 +02:00
|
|
|
|
2020-02-12 08:54:03 +01:00
|
|
|
lv_area_t txt_area;
|
|
|
|
lv_point_t txt_size;
|
|
|
|
|
|
|
|
|
|
|
|
lv_txt_get_size(&txt_size, ext->title_txt, label_dsc.font, label_dsc.letter_space, label_dsc.line_space, LV_COORD_MAX, label_dsc.flag);
|
|
|
|
|
|
|
|
txt_area.x1 = header->coords.x1 + left;
|
|
|
|
txt_area.y1 = header->coords.y1 + (lv_obj_get_height(header) - txt_size.y) / 2;
|
|
|
|
txt_area.x2 = txt_area.x1 + txt_size.x;
|
|
|
|
txt_area.y2 = txt_area.y1 + txt_size.y;
|
|
|
|
|
|
|
|
lv_draw_label(&txt_area, clip_area, &label_dsc, ext->title_txt, NULL);
|
|
|
|
} else if(mode == LV_DESIGN_DRAW_POST) {
|
|
|
|
ancestor_header_design(header, clip_area, mode);
|
|
|
|
}
|
|
|
|
|
|
|
|
return LV_DESIGN_RES_OK;
|
|
|
|
}
|
2016-10-07 17:33:35 +02:00
|
|
|
/**
|
2017-11-15 21:06:44 +01:00
|
|
|
* Signal function of the window
|
|
|
|
* @param win pointer to a window object
|
|
|
|
* @param sign a signal type from lv_signal_t enum
|
|
|
|
* @param param pointer to a signal specific variable
|
|
|
|
* @return LV_RES_OK: the object is not deleted in the function; LV_RES_INV: the object is deleted
|
2016-10-07 17:33:35 +02:00
|
|
|
*/
|
2017-11-15 21:06:44 +01:00
|
|
|
static lv_res_t lv_win_signal(lv_obj_t * win, lv_signal_t sign, void * param)
|
2016-10-07 17:33:35 +02:00
|
|
|
{
|
2017-11-15 21:06:44 +01:00
|
|
|
lv_res_t res;
|
2016-10-07 17:33:35 +02:00
|
|
|
|
2020-02-11 09:40:31 +01:00
|
|
|
if(sign == LV_SIGNAL_GET_STYLE) {
|
|
|
|
lv_get_style_info_t * info = param;
|
|
|
|
info->result = lv_win_get_style(win, info->part);
|
|
|
|
if(info->result != NULL) return LV_RES_OK;
|
|
|
|
else return ancestor_signal(win, sign, param);
|
|
|
|
return LV_RES_OK;
|
|
|
|
} else if(sign == LV_SIGNAL_GET_STATE_DSC) {
|
|
|
|
lv_win_ext_t * ext = lv_obj_get_ext_attr(win);
|
|
|
|
lv_get_state_info_t * info = param;
|
|
|
|
if(info->part == LV_WIN_PART_CONTENT_SCRL) info->result = lv_obj_get_state_dsc(lv_page_get_scrl(ext->page), LV_CONT_PART_MAIN);
|
|
|
|
else if(info->part == LV_WIN_PART_SCRLBAR) info->result = lv_obj_get_state_dsc(ext->page, LV_PAGE_PART_SCRLBAR);
|
|
|
|
else if(info->part == LV_WIN_PART_HEADER) info->result = lv_obj_get_state_dsc(ext->header, LV_OBJ_PART_MAIN);
|
|
|
|
return LV_RES_OK;
|
|
|
|
}
|
|
|
|
|
2017-11-15 21:06:44 +01:00
|
|
|
/* Include the ancient signal function */
|
|
|
|
res = ancestor_signal(win, sign, param);
|
|
|
|
if(res != LV_RES_OK) return res;
|
2019-09-26 12:54:40 +02:00
|
|
|
if(sign == LV_SIGNAL_GET_TYPE) return lv_obj_handle_get_type_signal(param, LV_OBJX_NAME);
|
2016-10-07 17:33:35 +02:00
|
|
|
|
2017-11-15 21:06:44 +01:00
|
|
|
lv_win_ext_t * ext = lv_obj_get_ext_attr(win);
|
|
|
|
if(sign == LV_SIGNAL_CHILD_CHG) { /*Move children to the page*/
|
|
|
|
lv_obj_t * page = ext->page;
|
|
|
|
if(page != NULL) {
|
|
|
|
lv_obj_t * child;
|
|
|
|
child = lv_obj_get_child(win, NULL);
|
|
|
|
while(child != NULL) {
|
|
|
|
if(lv_obj_is_protected(child, LV_PROTECT_PARENT) == false) {
|
|
|
|
lv_obj_t * tmp = child;
|
2019-06-06 06:05:40 +02:00
|
|
|
child = lv_obj_get_child(win, child); /*Get the next child before move this*/
|
2017-11-15 21:06:44 +01:00
|
|
|
lv_obj_set_parent(tmp, page);
|
|
|
|
} else {
|
|
|
|
child = lv_obj_get_child(win, child);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-06-19 09:49:58 +02:00
|
|
|
} else if(sign == LV_SIGNAL_STYLE_CHG) {
|
2017-11-15 21:06:44 +01:00
|
|
|
lv_win_realign(win);
|
2020-02-11 09:40:31 +01:00
|
|
|
} else if(sign == LV_SIGNAL_COORD_CHG) {
|
2017-11-15 21:06:44 +01:00
|
|
|
/*If the size is changed refresh the window*/
|
2019-06-06 06:05:40 +02:00
|
|
|
if(lv_area_get_width(param) != lv_obj_get_width(win) || lv_area_get_height(param) != lv_obj_get_height(win)) {
|
2017-11-15 21:06:44 +01:00
|
|
|
lv_win_realign(win);
|
|
|
|
}
|
2018-06-19 09:49:58 +02:00
|
|
|
} else if(sign == LV_SIGNAL_CLEANUP) {
|
2019-04-04 07:15:40 +02:00
|
|
|
ext->header = NULL; /*These objects were children so they are already invalid*/
|
|
|
|
ext->page = NULL;
|
2020-02-11 09:40:31 +01:00
|
|
|
lv_mem_free(ext->title_txt);
|
|
|
|
ext->title_txt = NULL;
|
2019-03-19 07:15:00 +01:00
|
|
|
} else if(sign == LV_SIGNAL_CONTROL) {
|
2018-10-05 17:22:49 +02:00
|
|
|
/*Forward all the control signals to the page*/
|
2019-02-26 09:25:46 +01:00
|
|
|
ext->page->signal_cb(ext->page, sign, param);
|
2018-02-28 15:37:41 +01:00
|
|
|
}
|
2017-12-03 00:35:39 +01:00
|
|
|
|
2017-11-15 21:06:44 +01:00
|
|
|
return res;
|
2016-10-07 17:33:35 +02:00
|
|
|
}
|
2020-02-11 09:40:31 +01:00
|
|
|
/**
|
|
|
|
* Get the style descriptor of a part of the object
|
|
|
|
* @param win pointer the object
|
|
|
|
* @param part the part of the win. (LV_PAGE_WIN_...)
|
|
|
|
* @return pointer to the style descriptor of the specified part
|
|
|
|
*/
|
|
|
|
static lv_style_list_t * lv_win_get_style(lv_obj_t * win, uint8_t part)
|
|
|
|
{
|
|
|
|
LV_ASSERT_OBJ(win, LV_OBJX_NAME);
|
|
|
|
|
|
|
|
lv_win_ext_t * ext = lv_obj_get_ext_attr(win);
|
|
|
|
lv_style_list_t * style_dsc_p;
|
|
|
|
|
|
|
|
switch(part) {
|
|
|
|
case LV_WIN_PART_BG:
|
|
|
|
style_dsc_p = &win->style_list;
|
|
|
|
break;
|
|
|
|
case LV_WIN_PART_HEADER:
|
|
|
|
style_dsc_p = lv_obj_get_style_list(ext->header, LV_OBJ_PART_MAIN);
|
|
|
|
break;
|
|
|
|
case LV_WIN_PART_SCRLBAR:
|
|
|
|
style_dsc_p = lv_obj_get_style_list(ext->page, LV_PAGE_PART_SCRLBAR);
|
|
|
|
break;
|
|
|
|
case LV_WIN_PART_CONTENT_SCRL:
|
|
|
|
style_dsc_p = lv_obj_get_style_list(ext->page, LV_PAGE_PART_SCRL);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
style_dsc_p = NULL;
|
|
|
|
}
|
2016-10-07 17:33:35 +02:00
|
|
|
|
2020-02-11 09:40:31 +01:00
|
|
|
return style_dsc_p;
|
|
|
|
}
|
2016-10-07 17:33:35 +02:00
|
|
|
/**
|
|
|
|
* Realign the building elements of a window
|
2020-02-12 08:54:03 +01:00
|
|
|
* @param win pointer to a window object
|
2016-10-07 17:33:35 +02:00
|
|
|
*/
|
|
|
|
static void lv_win_realign(lv_obj_t * win)
|
|
|
|
{
|
2017-11-15 21:06:44 +01:00
|
|
|
lv_win_ext_t * ext = lv_obj_get_ext_attr(win);
|
2016-10-07 17:33:35 +02:00
|
|
|
|
2020-02-11 09:40:31 +01:00
|
|
|
if(ext->page == NULL || ext->header == NULL) return;
|
2017-11-15 21:06:44 +01:00
|
|
|
|
2020-02-12 08:54:03 +01:00
|
|
|
lv_obj_set_width(ext->header, lv_obj_get_width(win));
|
|
|
|
|
2018-06-19 09:49:58 +02:00
|
|
|
lv_obj_t * btn;
|
|
|
|
lv_obj_t * btn_prev = NULL;
|
2020-02-11 09:40:31 +01:00
|
|
|
lv_coord_t btn_size = lv_obj_get_height_fit(ext->header);
|
|
|
|
lv_style_int_t header_inner = lv_obj_get_style_pad_inner(win, LV_WIN_PART_HEADER);
|
|
|
|
lv_style_int_t header_right = lv_obj_get_style_pad_right(win, LV_WIN_PART_HEADER);
|
2017-11-15 21:06:44 +01:00
|
|
|
/*Refresh the size of all control buttons*/
|
|
|
|
btn = lv_obj_get_child_back(ext->header, NULL);
|
|
|
|
while(btn != NULL) {
|
2020-02-11 09:40:31 +01:00
|
|
|
lv_obj_set_size(btn, btn_size, btn_size);
|
|
|
|
if(btn_prev == NULL) {
|
|
|
|
lv_obj_align(btn, ext->header, LV_ALIGN_IN_RIGHT_MID, -header_right, 0);
|
2017-11-15 21:06:44 +01:00
|
|
|
} else {
|
2020-02-11 09:40:31 +01:00
|
|
|
lv_obj_align(btn, btn_prev, LV_ALIGN_OUT_LEFT_MID, - header_inner, 0);
|
2017-11-15 21:06:44 +01:00
|
|
|
}
|
|
|
|
btn_prev = btn;
|
2019-04-04 07:15:40 +02:00
|
|
|
btn = lv_obj_get_child_back(ext->header, btn);
|
2017-11-15 21:06:44 +01:00
|
|
|
}
|
2016-12-17 10:50:28 +01:00
|
|
|
|
2017-12-07 19:22:23 +01:00
|
|
|
lv_obj_set_pos(ext->header, 0, 0);
|
2016-10-07 17:33:35 +02:00
|
|
|
|
2019-06-06 06:05:40 +02:00
|
|
|
lv_obj_set_size(ext->page, lv_obj_get_width(win), lv_obj_get_height(win) - lv_obj_get_height(ext->header));
|
2018-06-19 09:49:58 +02:00
|
|
|
lv_obj_align(ext->page, ext->header, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 0);
|
2016-10-07 17:33:35 +02:00
|
|
|
}
|
2017-11-15 21:06:44 +01:00
|
|
|
|
2016-10-07 17:33:35 +02:00
|
|
|
#endif
|