1
0
mirror of https://github.com/lvgl/lvgl.git synced 2025-01-21 06:53:01 +08:00
lvgl/src/lv_widgets/lv_win.c

673 lines
20 KiB
C
Raw Normal View History

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
*********************/
#include "lv_win.h"
#if LV_USE_WIN != 0
2016-10-07 17:33:35 +02:00
#include "../lv_misc/lv_debug.h"
#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
*********************/
#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;
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
* @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
*/
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*/
lv_obj_t * new_win = lv_obj_create(par, copy);
2019-09-24 23:14:17 +02:00
LV_ASSERT_MEM(new_win);
if(new_win == NULL) return NULL;
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*/
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);
if(ext == NULL) {
lv_obj_del(new_win);
return NULL;
}
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) {
/* 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 */
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));
2020-02-26 19:48:27 +01:00
}
else {
w = lv_disp_get_hor_res(NULL);
h = lv_disp_get_ver_res(NULL);
}
lv_obj_set_size(new_win, w, h);
2020-04-30 11:26:35 +02:00
ext->btn_w = LV_DPX(65);
ext->page = lv_page_create(new_win, NULL);
2020-02-14 22:04:00 +01:00
lv_obj_add_protect(ext->page, LV_PROTECT_PARENT);
lv_page_set_scrollbar_mode(ext->page, LV_SCROLLBAR_MODE_AUTO);
lv_obj_clean_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*/
2020-02-14 22:04:00 +01:00
lv_obj_add_protect(ext->header, LV_PROTECT_PARENT);
2018-06-19 09:49:58 +02:00
lv_obj_set_parent(ext->header, new_win);
2020-02-26 19:48:27 +01:00
if(ancestor_header_design == NULL) ancestor_header_design = lv_obj_get_design_cb(ext->header);
2020-04-17 08:58:34 +02:00
lv_obj_set_height(ext->header, LV_DPX(65));
2020-02-13 06:56:14 +01:00
2020-02-12 08:54:03 +01:00
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);
2020-04-30 11:26:35 +02:00
ext->btn_w = copy_ext->btn_w;
2016-10-07 17:33:35 +02:00
2020-02-25 15:32:35 +01:00
/*Copy the buttons*/
2018-06-19 09:49:58 +02:00
lv_obj_t * child;
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) {
2020-02-25 15:32:35 +01:00
lv_obj_t * btn = lv_btn_create(ext->header, child);
lv_img_create(btn, lv_obj_get_child(child, NULL));
2018-06-19 09:49:58 +02:00
child = lv_obj_get_child_back(copy_ext->header, child);
}
2016-10-07 17:33:35 +02: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
/*Refresh the style with new signal function*/
2020-03-10 10:41:39 +01:00
lv_obj_refresh_style(new_win, LV_STYLE_PROP_ALL);
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;
}
/**
* Delete all children of the scrl object, without deleting scrl child.
* @param win pointer to an object
*/
void lv_win_clean(lv_obj_t * win)
{
LV_ASSERT_OBJ(win, LV_OBJX_NAME);
lv_obj_t * scrl = lv_page_get_scrllable(win);
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
* @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
*/
lv_obj_t * lv_win_add_btn(lv_obj_t * win, const void * img_src)
2016-10-07 17:33:35 +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);
2017-11-15 21:06:44 +01:00
lv_obj_t * img = lv_img_create(btn, NULL);
lv_obj_set_click(img, false);
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
*====================*/
/**
* 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
*/
void lv_win_close_event_cb(lv_obj_t * btn, lv_event_t event)
{
LV_ASSERT_OBJ(btn, "lv_btn");
if(event == LV_EVENT_RELEASED) {
lv_obj_t * win = lv_win_get_from_btn(btn);
lv_obj_del(win);
}
}
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)
{
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);
2020-03-10 08:34:07 +01:00
LV_ASSERT_MEM(ext->title_txt);
if(ext->title_txt == NULL) return;
2020-02-11 09:40:31 +01:00
strcpy(ext->title_txt, title);
lv_obj_invalidate(ext->header);
2016-10-07 17:33:35 +02:00
}
/**
2020-02-11 09:40:31 +01:00
* Set the height of the header
* @param win pointer to a window object
2020-02-11 09:40:31 +01:00
* @param height height of the header
*/
2020-02-11 09:40:31 +01:00
void lv_win_set_header_height(lv_obj_t * win, lv_coord_t height)
{
LV_ASSERT_OBJ(win, LV_OBJX_NAME);
lv_win_ext_t * ext = lv_obj_get_ext_attr(win);
2020-02-11 09:40:31 +01:00
lv_obj_set_height(ext->header, height);
lv_win_realign(win);
}
2020-03-10 18:30:04 +01:00
/**
* Set the width of the control buttons on the header
* @param win pointer to a window object
* @param width width of the control button. 0: to make them square automatically.
*/
void lv_win_set_btn_width(lv_obj_t * win, lv_coord_t width)
{
LV_ASSERT_OBJ(win, LV_OBJX_NAME);
lv_win_ext_t * ext = lv_obj_get_ext_attr(win);
ext->btn_w = width;
lv_win_realign(win);
}
2019-09-18 06:29:54 +02:00
/**
* Set the size of the content area.
2020-03-10 18:30:04 +01:00
* It's the effective area where object can be placed.
2019-09-18 06:29:54 +02:00
* @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)
{
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);
lv_obj_set_size(win, w, h);
2019-09-18 06:29:54 +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)
{
LV_ASSERT_OBJ(win, LV_OBJX_NAME);
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'
*/
void lv_win_set_scrollbar_mode(lv_obj_t * win, lv_scrollbar_mode_t sb_mode)
{
LV_ASSERT_OBJ(win, LV_OBJX_NAME);
lv_win_ext_t * ext = lv_obj_get_ext_attr(win);
lv_page_set_scrollbar_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)
{
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);
}
/**
* 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
* @param en whether dragging is enabled
*/
2019-04-04 07:15:40 +02:00
void lv_win_set_drag(lv_obj_t * win, bool en)
{
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);
lv_obj_t * win_header = ext->header;
lv_obj_set_drag_parent(win_header, en);
lv_obj_set_drag(win, en);
}
2017-11-15 21:06:44 +01:00
2016-10-07 17:33:35 +02:00
/*=====================
* Getter functions
*====================*/
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
*/
const char * lv_win_get_title(const lv_obj_t * win)
2016-12-15 10:31:30 +01: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
}
/**
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
*/
lv_obj_t * lv_win_get_content(const lv_obj_t * win)
{
LV_ASSERT_OBJ(win, LV_OBJX_NAME);
lv_win_ext_t * ext = lv_obj_get_ext_attr(win);
return ext->page;
}
/**
2020-02-11 09:40:31 +01:00
* Get the header height
* @param win pointer to a window object
2020-02-11 09:40:31 +01:00
* @return header height
*/
2020-02-11 09:40:31 +01:00
lv_coord_t lv_win_get_header_height(const lv_obj_t * win)
{
LV_ASSERT_OBJ(win, LV_OBJX_NAME);
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);
}
2020-03-10 18:30:04 +01:00
/**
* Get the width of the control buttons on the header
* @param win pointer to a window object
* @return width of the control button. 0: square.
*/
lv_coord_t lv_win_get_btn_width(lv_obj_t * win)
{
LV_ASSERT_OBJ(win, LV_OBJX_NAME);
lv_win_ext_t * ext = lv_obj_get_ext_attr(win);
return ext->btn_w;
}
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'
*/
lv_obj_t * lv_win_get_from_btn(const lv_obj_t * ctrl_btn)
2016-12-15 10:31:30 +01: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
/**
* 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)
{
LV_ASSERT_OBJ(win, LV_OBJX_NAME);
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')
*/
lv_scrollbar_mode_t lv_win_get_sb_mode(lv_obj_t * win)
{
LV_ASSERT_OBJ(win, LV_OBJX_NAME);
lv_win_ext_t * ext = lv_obj_get_ext_attr(win);
return lv_page_get_scrollbar_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)
{
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));
}
/**
* 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)
{
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_scrllable(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);
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
}
/*=====================
* 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
*/
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)
{
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);
}
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_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,
2020-05-18 16:57:23 +02:00
label_dsc.flag);
2020-02-12 08:54:03 +01:00
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);
2020-02-26 19:48:27 +01:00
}
else if(mode == LV_DESIGN_DRAW_POST) {
2020-02-12 08:54:03 +01:00
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);
2020-02-26 19:48:27 +01:00
}
else if(sign == LV_SIGNAL_GET_STATE_DSC) {
2020-02-11 09:40:31 +01:00
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_SCROLLABLE) info->result = lv_obj_get_state(lv_page_get_scrllable(ext->page),
2020-05-01 11:17:43 +02:00
LV_CONT_PART_MAIN);
2020-04-21 11:36:05 +02:00
else if(info->part == LV_WIN_PART_SCROLLBAR) info->result = lv_obj_get_state(ext->page, LV_PAGE_PART_SCROLLBAR);
else if(info->part == LV_WIN_PART_HEADER) info->result = lv_obj_get_state(ext->header, LV_OBJ_PART_MAIN);
2020-02-11 09:40:31 +01:00
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;
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);
2020-02-26 19:48:27 +01:00
}
else {
2017-11-15 21:06:44 +01:00
child = lv_obj_get_child(win, child);
}
}
}
2020-02-26 19:48:27 +01:00
}
else if(sign == LV_SIGNAL_STYLE_CHG) {
2017-11-15 21:06:44 +01:00
lv_win_realign(win);
2020-02-26 19:48:27 +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);
}
2020-02-26 19:48:27 +01: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;
2020-02-26 19:48:27 +01:00
}
else if(sign == LV_SIGNAL_CONTROL) {
2018-10-05 17:22:49 +02:00
/*Forward all the control signals to the page*/
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) {
2020-02-26 19:48:27 +01:00
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;
2020-04-21 11:36:05 +02:00
case LV_WIN_PART_SCROLLBAR:
style_dsc_p = lv_obj_get_style_list(ext->page, LV_PAGE_PART_SCROLLBAR);
2020-02-26 19:48:27 +01:00
break;
2020-04-21 11:36:05 +02:00
case LV_WIN_PART_CONTENT_SCROLLABLE:
style_dsc_p = lv_obj_get_style_list(ext->page, LV_PAGE_PART_SCROLLABLE);
2020-02-26 19:48:27 +01:00
break;
default:
style_dsc_p = NULL;
2020-02-11 09:40:31 +01:00
}
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-03-10 18:30:04 +01:00
lv_coord_t btn_h = lv_obj_get_height_fit(ext->header);
lv_coord_t btn_w = ext->btn_w != 0 ? ext->btn_w : btn_h;
2020-02-11 09:40:31 +01:00
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-03-10 18:30:04 +01:00
lv_obj_set_size(btn, btn_h, btn_w);
2020-02-11 09:40:31 +01:00
if(btn_prev == NULL) {
lv_obj_align(btn, ext->header, LV_ALIGN_IN_RIGHT_MID, -header_right, 0);
2020-02-26 19:48:27 +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
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