BigW Consortium Gitlab

Commit ad2a9a4c by Gabor

Merge branch 'new_objs' into beta

parents ce50c08e 0ef1fa06
......@@ -100,6 +100,12 @@
/*Window (dependencies: lv_cont, lv_btn, lv_label, lv_img, lv_page)*/
#define USE_LV_WIN 1
/*Tab (dependencies: lv_page, lv_btnm)*/
#define USE_LV_TABVIEW 1
#if USE_LV_TABVIEW != 0
#define LV_TABVIEW_ANIM_TIME 300 /*Time of slide animation [ms] (0: no animation)*/
#endif
/*************************
* Data visualizer object
*************************/
......@@ -143,9 +149,15 @@
/*Button matrix (dependencies: -)*/
#define USE_LV_BTNM 1
/*Keyboard (dependencies: lv_btnm)*/
#define USE_LV_KB 1
/*Check box (dependencies: lv_btn, lv_label)*/
#define USE_LV_CB 1
/*Switch (dependencies: lv_slider)*/
#define USE_LV_SW 1
/*List (dependencies: lv_page, lv_btn, lv_label, lv_img)*/
#define USE_LV_LIST 1
#if USE_LV_LIST != 0
......
......@@ -70,11 +70,15 @@ lv_obj_t * lv_btnm_create(lv_obj_t * par, lv_obj_t * copy)
dm_assert(ext);
ext->btn_cnt = 0;
ext->btn_pr = LV_BTNM_PR_NONE;
ext->btn_tgl = LV_BTNM_PR_NONE;
ext->btn_areas = NULL;
ext->cb = NULL;
ext->map_p = NULL;
ext->style_btn_rel = lv_style_get(LV_STYLE_BTN_REL, NULL);
ext->style_btn_pr = lv_style_get(LV_STYLE_BTN_PR, NULL);
ext->style_btn_trel = lv_style_get(LV_STYLE_BTN_TREL, NULL);
ext->style_btn_tpr = lv_style_get(LV_STYLE_BTN_TPR, NULL);
ext->tgl = 0;
if(ancestor_design_f == NULL) ancestor_design_f = lv_obj_get_design_f(new_btnm);
......@@ -84,7 +88,7 @@ lv_obj_t * lv_btnm_create(lv_obj_t * par, lv_obj_t * copy)
/*Init the new button matrix object*/
if(copy == NULL) {
lv_obj_set_size(new_btnm, LV_HOR_RES, LV_VER_RES / 2);
lv_obj_set_style(new_btnm, lv_style_get(LV_STYLE_PLAIN, NULL));
lv_obj_set_style(new_btnm, lv_style_get(LV_STYLE_PRETTY, NULL));
lv_btnm_set_map(new_btnm, lv_btnm_def_map);
}
/*Copy an existing object*/
......@@ -162,7 +166,7 @@ bool lv_btnm_signal(lv_obj_t * btnm, lv_signal_t sign, void * param)
}
if(sign == LV_SIGNAL_RELEASED && ext->btn_pr != LV_BTNM_PR_NONE) {
/*Invalidate to old area*/;
/*Invalidate to old pressed area*/;
lv_obj_get_cords(btnm, &btnm_area);
area_cpy(&btn_area, &ext->btn_areas[ext->btn_pr]);
btn_area.x1 += btnm_area.x1;
......@@ -171,6 +175,18 @@ bool lv_btnm_signal(lv_obj_t * btnm, lv_signal_t sign, void * param)
btn_area.y2 += btnm_area.y1;
lv_inv_area(&btn_area);
if(ext->tgl != 0) {
/*Invalidate to old toggled area*/;
area_cpy(&btn_area, &ext->btn_areas[ext->btn_tgl]);
btn_area.x1 += btnm_area.x1;
btn_area.y1 += btnm_area.y1;
btn_area.x2 += btnm_area.x1;
btn_area.y2 += btnm_area.y1;
lv_inv_area(&btn_area);
ext->btn_tgl = ext->btn_pr;
}
ext->btn_pr = LV_BTNM_PR_NONE;
}
} else if(sign == LV_SIGNAL_PRESS_LOST || sign == LV_SIGNAL_DEFOCUS) {
......@@ -314,7 +330,28 @@ void lv_btnm_set_action(lv_obj_t * btnm, lv_btnm_callback_t cb)
}
/**
* Set the styles of the buttons of the button matrox
* Enable or disable button toggling
* @param btnm pointer to button matrix object
* @param en true: enable toggling; false: disable toggling
* @param id index of the currently toggled button (ignored if 'en' == false)
*/
void lv_btnm_set_tgl(lv_obj_t * btnm, bool en, uint16_t id)
{
lv_btnm_ext_t * ext = lv_obj_get_ext(btnm);
ext->tgl = en == false ? 0 : 1;
if(ext->tgl != 0) {
if(id > ext->btn_cnt) id = LV_BTNM_PR_NONE;
ext->btn_tgl = id;
} else {
ext->btn_tgl = LV_BTNM_PR_NONE;
}
lv_obj_inv(btnm);
}
/**
* Set the styles of the buttons of the button matrix
* @param btnm pointer to a button matrix object
* @param state style in this state (LV_BTN_STATE_PR or LV_BTN_STATE_REL)
* @param style pointer to style
......@@ -373,6 +410,12 @@ lv_style_t * lv_btnm_get_style_btn(lv_obj_t * btnm, lv_btn_state_t state)
case LV_BTN_STATE_REL:
style = ext->style_btn_rel;
break;
case LV_BTN_STATE_TPR:
style = ext->style_btn_tpr;
break;
case LV_BTN_STATE_TREL:
style = ext->style_btn_trel;
break;
default:
style = NULL;
}
......@@ -420,7 +463,7 @@ static bool lv_btnm_design(lv_obj_t * btnm, const area_t * mask, lv_design_mode_
/*Search the next valid text in the map*/
while(strcmp(ext->map_p[txt_i], "\n") == 0) txt_i ++;
if(ext->map_p[txt_i][1] == '\177') continue;
if(ext->map_p[txt_i][1] == '\177' || ext->map_p[txt_i][0] == '\177') continue;
lv_obj_get_cords(btnm, &area_btnm);
......@@ -434,7 +477,10 @@ static bool lv_btnm_design(lv_obj_t * btnm, const area_t * mask, lv_design_mode_
btn_h = area_get_height(&area_tmp);
/*Load the style*/
btn_style = lv_btnm_get_style_btn(btnm, ext->btn_pr == btn_i ? LV_BTN_STATE_PR : LV_BTN_STATE_REL);
if(btn_i != ext->btn_pr && btn_i != ext->btn_tgl) btn_style = lv_btnm_get_style_btn(btnm, LV_BTN_STATE_REL);
else if(btn_i == ext->btn_pr && btn_i != ext->btn_tgl) btn_style = lv_btnm_get_style_btn(btnm, LV_BTN_STATE_PR);
else if(btn_i != ext->btn_pr && btn_i == ext->btn_tgl) btn_style = lv_btnm_get_style_btn(btnm, LV_BTN_STATE_TREL);
else if(btn_i == ext->btn_pr && btn_i == ext->btn_tgl) btn_style = lv_btnm_get_style_btn(btnm, LV_BTN_STATE_TPR);
lv_draw_rect(&area_tmp, mask, btn_style);
......
......@@ -43,9 +43,13 @@ typedef struct
area_t * btn_areas; /*Array of areas for the buttons (Handled by the library)*/
uint16_t btn_cnt; /*Number of button in 'map_p'(Handled by the library)*/
uint16_t btn_pr; /*Index of the currently pressed button or LV_BTNM_PR_NONE (Handled by the library)*/
uint16_t btn_tgl; /*Index of the currently toggled button or LV_BTNM_PR_NONE (Handled by the library)*/
lv_btnm_callback_t cb; /*A function to call when a button is releases*/
lv_style_t * style_btn_rel; /*Style of the released buttons*/
lv_style_t * style_btn_pr; /*Style of the pressed buttons*/
lv_style_t * style_btn_trel; /*Style of the released buttons*/
lv_style_t * style_btn_tpr; /*Style of the pressed buttons*/
uint8_t tgl :1; /*Enable toggling*/
}lv_btnm_ext_t;
/**********************
......@@ -89,6 +93,14 @@ void lv_btnm_set_map(lv_obj_t * btnm, const char ** map);
void lv_btnm_set_action(lv_obj_t * btnm, lv_btnm_callback_t cb);
/**
* Enable or disable button toggling
* @param btnm pointer to button matrix object
* @param en true: enable toggling; false: disable toggling
* @param id index of the currently toggled button (ignored if 'en' == false)
*/
void lv_btnm_set_tgl(lv_obj_t * btnm, bool en, uint16_t id);
/**
* Set the styles of the buttons of the button matrox
* @param btnm pointer to a button matrix object
* @param state style in this state (LV_BTN_STATE_PR or LV_BTN_STATE_REL)
......
/**
* @file lv_kb.c
*
*/
/*********************
* INCLUDES
*********************/
#include "lv_conf.h"
#if USE_LV_KB != 0
#include "lv_kb.h"
#include "lv_ta.h"
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
#if 0 /*Use Button matrix design*/
static bool lv_kb_design(lv_obj_t * kb, const area_t * mask, lv_design_mode_t mode);
#endif
static lv_action_res_t lv_app_kb_action(lv_obj_t * kb, uint16_t i);
/**********************
* STATIC VARIABLES
**********************/
static const char * kb_map_lc[] = {
"\0051#", "\004q", "\004w", "\004e", "\004r", "\004t", "\004y", "\004u", "\004i", "\004o", "\004p", "\007Del", "\n",
"\006ABC", "\003a", "\003s", "\003d", "\003f", "\003g", "\003h", "\003j", "\003k", "\003l", "\010Enter", "\n",
"_", "-", "z", "x", "c", "v", "b", "n", "m", ".", ",", ":", "\n",
"\003Hide", "\003Left", "\006 ", "\003Right", "\003Ok", ""
};
static const char * kb_map_uc[] = {
"\0051#", "\004Q", "\004W", "\004E", "\004R", "\004T", "\004Y", "\004U", "\004I", "\004O", "\004P", "\007Del", "\n",
"\006abc", "\003A", "\003S", "\003D", "\003F", "\003G", "\003H", "\003J", "\003K", "\003L", "\010Enter", "\n",
"_", "-", "Z", "X", "C", "V", "B", "N", "M", ".", ",", ":", "\n",
"\003Hide", "\003Left", "\006 ", "\003Right", "\003Ok", ""
};
static const char * kb_map_spec[] = {
"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "\002Del", "\n",
"\002abc", "+", "-", "/", "*", "=", "%", "!", "?", "#", "<", ">", "\n",
"\\", "@", "$", "(", ")", "{", "}", "[", "]", ";", "\"", "'", "\n",
"\003Hide", "\003Left", "\006 ", "\003Right", "\003Ok", ""
};
static const char * kb_map_num[] = {
"1", "2", "3", "\002Hide","\n",
"4", "5", "6", "\002Ok", "\n",
"7", "8", "9", "\002Del", "\n",
"+/-", "0", ".", "Left", "Right", ""
};
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
/*-----------------
* Create function
*-----------------*/
/**
* Create a keyboard objects
* @param par pointer to an object, it will be the parent of the new keyboard
* @param copy pointer to a keyboard object, if not NULL then the new object will be copied from it
* @return pointer to the created keyboard
*/
lv_obj_t * lv_kb_create(lv_obj_t * par, lv_obj_t * copy)
{
/*Create the ancestor of keyboard*/
/*TODO modify it to the ancestor create function */
lv_obj_t * new_kb = lv_btnm_create(par, copy);
dm_assert(new_kb);
/*Allocate the keyboard type specific extended data*/
lv_kb_ext_t * ext = lv_obj_alloc_ext(new_kb, sizeof(lv_kb_ext_t));
dm_assert(ext);
/*Initialize the allocated 'ext' */
ext->ta = NULL;
ext->mode = LV_KB_MODE_TXT;
ext->cur_mng = 0;
ext->close_action = NULL;
ext->ok_action = NULL;
/*The signal and design functions are not copied so set them here*/
lv_obj_set_signal_f(new_kb, lv_kb_signal);
/*Init the new keyboard keyboard*/
if(copy == NULL) {
lv_obj_set_size(new_kb, LV_HOR_RES, LV_VER_RES / 2);
lv_obj_align(new_kb, NULL, LV_ALIGN_IN_BOTTOM_MID, 0, 0);
lv_btnm_set_action(new_kb, lv_app_kb_action);
lv_btnm_set_map(new_kb, kb_map_lc);
}
/*Copy an existing keyboard*/
else {
lv_kb_ext_t * copy_ext = lv_obj_get_ext(copy);ext->ta = NULL;
ext->ta = copy_ext->ta;
ext->mode = copy_ext->mode;
ext->cur_mng = copy_ext->cur_mng;
ext->close_action = copy_ext->close_action;
ext->ok_action = copy_ext->ok_action;
/*Refresh the style with new signal function*/
lv_obj_refr_style(new_kb);
}
return new_kb;
}
/**
* Signal function of the keyboard
* @param kb pointer to a keyboard object
* @param sign a signal type from lv_signal_t enum
* @param param pointer to a signal specific variable
* @return true: the object is still valid (not deleted), false: the object become invalid
*/
bool lv_kb_signal(lv_obj_t * kb, lv_signal_t sign, void * param)
{
bool valid;
/* Include the ancient signal function */
valid = lv_btnm_signal(kb, sign, param);
/* The object can be deleted so check its validity and then
* make the object specific signal handling */
if(valid != false) {
if(sign == LV_SIGNAL_CLEANUP) {
/*Nothing to cleanup. (No dynamically allocated memory in 'ext')*/
}
}
return valid;
}
/*=====================
* Setter functions
*====================*/
/**
* Assign a Text Area to the Keyboard. The pressed characters will be put there.
* @param kb pointer to a Keyboard object
* @param ta pointer to a Text Area object to write there
*/
void lv_kb_set_ta(lv_obj_t * kb, lv_obj_t * ta)
{
lv_kb_ext_t * ext = lv_obj_get_ext(kb);
if(ext->ta != NULL && ext->cur_mng != 0) lv_ta_set_cursor_show(ext->ta, false);
ext->ta = ta;
if(ext->cur_mng != 0) lv_ta_set_cursor_show(ext->ta, true);
}
/**
* Set a new a mode (text or number map)
* @param kb pointer to a Keyboard object
* @param mode the mode from 'lv_kb_mode_t'
*/
void lv_kb_set_mode(lv_obj_t * kb, lv_kb_mode_t mode)
{
lv_kb_ext_t * ext = lv_obj_get_ext(kb);
ext->mode = mode;
if(mode == LV_KB_MODE_TXT) lv_btnm_set_map(kb, kb_map_lc);
else if(mode == LV_KB_MODE_NUM) lv_btnm_set_map(kb, kb_map_num);
}
/**
* Automatically hide or show the cursor of Text Area
* @param kb pointer to a Keyboard object
* @param en true: show cursor on the current text area, false: hide cursor
*/
void lv_kb_set_cur_mng(lv_obj_t * kb, bool en)
{
lv_kb_ext_t * ext = lv_obj_get_ext(kb);
ext->cur_mng = en == false? 0 : 1;
if(ext->ta != NULL) lv_ta_set_cursor_show(ext->ta, true);
}
/**
* Set call back to call when the "Ok" button is pressed
* @param kb pointer to Keyboard object
* @param action a callback with 'lv_action_t' type
*/
void lv_kb_set_ok_action(lv_obj_t * kb, lv_action_t action)
{
lv_kb_ext_t * ext = lv_obj_get_ext(kb);
ext->ok_action = action;
}
/**
* Set call back to call when the "Hide" button is pressed
* @param kb pointer to Keyboard object
* @param action a callback with 'lv_action_t' type
*/
void lv_kb_set_close_action(lv_obj_t * kb, lv_action_t action)
{
lv_kb_ext_t * ext = lv_obj_get_ext(kb);
ext->close_action = action;
}
/*=====================
* Getter functions
*====================*/
/**
* Assign a Text Area to the Keyboard. The pressed characters will be put there.
* @param kb pointer to a Keyboard object
* @return pointer to the assigned Text Area object
*/
lv_obj_t * lv_kb_get_ta(lv_obj_t * kb)
{
lv_kb_ext_t * ext = lv_obj_get_ext(kb);
return ext->ta;
}
/**
* Set a new a mode (text or number map)
* @param kb pointer to a Keyboard object
* @return the current mode from 'lv_kb_mode_t'
*/
lv_kb_mode_t lv_kb_get_mode(lv_obj_t * kb)
{
lv_kb_ext_t * ext = lv_obj_get_ext(kb);
return ext->mode;
}
/**
* Get the current cursor manage mode.
* @param kb pointer to a Keyboard object
* @return true: show cursor on the current text area, false: hide cursor
*/
bool lv_kb_get_cur_mng(lv_obj_t * kb, bool en)
{
lv_kb_ext_t * ext = lv_obj_get_ext(kb);
return ext->cur_mng == 0 ? false : true;
}
/**
* Get the callback to call when the "Ok" button is pressed
* @param kb pointer to Keyboard object
* @return the ok callback
*/
lv_action_t lv_kb_get_ok_action(lv_obj_t * kb, lv_action_t action)
{
lv_kb_ext_t * ext = lv_obj_get_ext(kb);
return ext->ok_action;
}
/**
* Get the callback to call when the "Hide" button is pressed
* @param kb pointer to Keyboard object
* @return the close callback
*/
lv_action_t lv_kb_get_close_action(lv_obj_t * kb, lv_action_t action)
{
lv_kb_ext_t * ext = lv_obj_get_ext(kb);
return ext->close_action;
}
/**********************
* STATIC FUNCTIONS
**********************/
#if 0 /*Use Button matrix design*/
/**
* Handle the drawing related tasks of the keyboards
* @param kb pointer to an object
* @param mask 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 true/false, depends on 'mode'
*/
static bool lv_kb_design(lv_obj_t * kb, const area_t * mask, lv_design_mode_t mode)
{
/*Return false if the object is not covers the mask_p area*/
if(mode == LV_DESIGN_COVER_CHK) {
return false;
}
/*Draw the object*/
else if(mode == LV_DESIGN_DRAW_MAIN) {
}
/*Post draw when the children are drawn*/
else if(mode == LV_DESIGN_DRAW_POST) {
}
return true;
}
#endif
/**
* Called when a button of 'kb_btnm' is released
* @param btnm pointer to 'kb_btnm'
* @param i the index of the released button from the current btnm map
* @return LV_ACTION_RES_INV if the btnm is deleted else LV_ACTION_RES_OK
*/
static lv_action_res_t lv_app_kb_action(lv_obj_t * kb, uint16_t i)
{
lv_kb_ext_t * ext = lv_obj_get_ext(kb);
if(ext->ta == NULL) return LV_ACTION_RES_OK;
const char ** map = lv_btnm_get_map(kb);
const char * txt = map[i];
/*Ignore the unit size number of the text*/
if(txt[0] <= '\011') txt++; /*Ignore length specifier*/
if(txt[0] == '\177') return LV_ACTION_RES_OK; /*Don't care hidden buttons*/
/*Do the corresponding action according to the text of the button*/
if(strcmp(txt, "abc") == 0) {
lv_btnm_set_map(kb, kb_map_lc);
} else if(strcmp(txt, "ABC") == 0) {
lv_btnm_set_map(kb, kb_map_uc);
} else if(strcmp(txt, "1#") == 0) {
lv_btnm_set_map(kb, kb_map_spec);
} else if(strcmp(txt, "Enter") == 0) {
lv_ta_add_char(ext->ta, '\n');
} else if(strcmp(txt, "Left") == 0) {
lv_ta_cursor_left(ext->ta);
} else if(strcmp(txt, "Right") == 0) {
lv_ta_cursor_right(ext->ta);
} else if(strcmp(txt, "Del") == 0) {
lv_ta_del(ext->ta);
} else if(strcmp(txt, "+/-") == 0) {
uint16_t cur = lv_ta_get_cursor_pos(ext->ta);
const char * ta_txt = lv_ta_get_txt(ext->ta);
if(ta_txt[0] == '-') {
lv_ta_set_cursor_pos(ext->ta, 1);
lv_ta_del(ext->ta);
lv_ta_add_char(ext->ta, '+');
lv_ta_set_cursor_pos(ext->ta, cur);
} else if(ta_txt[0] == '+') {
lv_ta_set_cursor_pos(ext->ta, 1);
lv_ta_del(ext->ta);
lv_ta_add_char(ext->ta, '-');
lv_ta_set_cursor_pos(ext->ta, cur);
} else {
lv_ta_set_cursor_pos(ext->ta, 0);
lv_ta_add_char(ext->ta, '-');
lv_ta_set_cursor_pos(ext->ta, cur + 1);
}
} else if(strcmp(txt, "Hide") == 0) {
//lv_app_kb_close(false);
return LV_ACTION_RES_INV;
} else if(strcmp(txt, "Ok") == 0) {
//lv_app_kb_close(true);
return LV_ACTION_RES_INV;
} else {
lv_ta_add_text(ext->ta, txt);
}
return LV_ACTION_RES_OK;
}
#endif
/**
* @file lv_kb.h
*
*/
#ifndef LV_KB_H
#define LV_KB_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#include "lv_conf.h"
#if USE_LV_KB != 0
#include "../lv_obj/lv_obj.h"
#include "lv_btnm.h"
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
typedef enum {
LV_KB_MODE_TXT,
LV_KB_MODE_NUM,
}lv_kb_mode_t;
/*Data of keyboard*/
typedef struct {
lv_btnm_ext_t btnm; /*Ext. of ancestor*/
/*New data for this type */
lv_obj_t * ta;
lv_kb_mode_t mode;
uint8_t cur_mng :1;
lv_action_t ok_action;
lv_action_t close_action;
}lv_kb_ext_t;
/**********************
* GLOBAL PROTOTYPES
**********************/
/**
* Create a keyboard objects
* @param par pointer to an object, it will be the parent of the new keyboard
* @param copy pointer to a keyboard object, if not NULL then the new object will be copied from it
* @return pointer to the created keyboard
*/
lv_obj_t * lv_kb_create(lv_obj_t * par, lv_obj_t * copy);
/**
* Signal function of the keyboard
* @param kb pointer to a keyboard object
* @param sign a signal type from lv_signal_t enum
* @param param pointer to a signal specific variable
* @return true: the object is still valid (not deleted), false: the object become invalid
*/
bool lv_kb_signal(lv_obj_t * kb, lv_signal_t sign, void * param);
/**
* Assign a Text Area to the Keyboard. The pressed characters will be put there.
* @param kb pointer to a Keyboard object
* @param ta pointer to a Text Area object to write there
*/
void lv_kb_set_ta(lv_obj_t * kb, lv_obj_t * ta);
/**
* Set a new a mode (text or number map)
* @param kb pointer to a Keyboard object
* @param mode the mode from 'lv_kb_mode_t'
*/
void lv_kb_set_mode(lv_obj_t * kb, lv_kb_mode_t mode);
/**
* Automatically hide or show the cursor of Text Area
* @param kb pointer to a Keyboard object
* @param en true: show cursor on the current text area, false: hide cursor
*/
void lv_kb_set_cur_mng(lv_obj_t * kb, bool en);
/**
* Set call back to call when the "Ok" button is pressed
* @param kb pointer to Keyboard object
* @param action a callback with 'lv_action_t' type
*/
void lv_kb_set_ok_action(lv_obj_t * kb, lv_action_t action);
/**
* Set call back to call when the "Hide" button is pressed
* @param kb pointer to Keyboard object
* @param action a callback with 'lv_action_t' type
*/
void lv_kb_set_close_action(lv_obj_t * kb, lv_action_t action);
/**
* Assign a Text Area to the Keyboard. The pressed characters will be put there.
* @param kb pointer to a Keyboard object
* @return pointer to the assigned Text Area object
*/
lv_obj_t * lv_kb_get_ta(lv_obj_t * kb);
/**
* Set a new a mode (text or number map)
* @param kb pointer to a Keyboard object
* @return the current mode from 'lv_kb_mode_t'
*/
lv_kb_mode_t lv_kb_get_mode(lv_obj_t * kb);
/**
* Get the current cursor manage mode.
* @param kb pointer to a Keyboard object
* @return true: show cursor on the current text area, false: hide cursor
*/
bool lv_kb_get_cur_mng(lv_obj_t * kb, bool en);
/**
* Get the callback to call when the "Ok" button is pressed
* @param kb pointer to Keyboard object
* @return the ok callback
*/
lv_action_t lv_kb_get_ok_action(lv_obj_t * kb, lv_action_t action);
/**
* Get the callback to call when the "Hide" button is pressed
* @param kb pointer to Keyboard object
* @return the close callback
*/
lv_action_t lv_kb_get_close_action(lv_obj_t * kb, lv_action_t action);
/**********************
* MACROS
**********************/
#endif /*USE_LV_KB*/
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /*LV_KB_H*/
......@@ -47,7 +47,7 @@ static bool lv_templ_design(lv_obj_t * templ, const area_t * mask, lv_design_mod
*-----------------*/
/**
* Create a template objects
* Create a template object
* @param par pointer to an object, it will be the parent of the new template
* @param copy pointer to a template object, if not NULL then the new object will be copied from it
* @return pointer to the created template
......@@ -111,12 +111,21 @@ bool lv_templ_signal(lv_obj_t * templ, lv_signal_t sign, void * param)
return valid;
}
/*======================
* Add/remove functions
*=====================*/
/*
* New object specific "add" or "remove" functions come here
*/
/*=====================
* Setter functions
*====================*/
/*
* New object specific "set" function comes here
* New object specific "set" functions come here
*/
......@@ -125,9 +134,16 @@ bool lv_templ_signal(lv_obj_t * templ, lv_signal_t sign, void * param)
*====================*/
/*
* New object specific "get" function comes here
* New object specific "get" functions come here
*/
/*=====================
* Other functions
*====================*/
/*
* New object specific "other" functions come here
*/
/**********************
* STATIC FUNCTIONS
......
......@@ -33,9 +33,8 @@ extern "C" {
* TYPEDEFS
**********************/
/*Data of template*/
typedef struct
{
/*Ext. of ancestor*/
typedef struct {
lv_ANCESTOR_ext_t ANCESTOR; /*Ext. of ancestor*/
/*New data for this type */
}lv_templ_ext_t;
......
......@@ -65,6 +65,7 @@ lv_obj_t * lv_slider_create(lv_obj_t * par, lv_obj_t * copy)
ext->cb = NULL;
ext->tmp_value = ext->bar.min_value;
ext->style_knob = lv_style_get(LV_STYLE_PRETTY, NULL);
ext->knob_in = 0;
/* Save the bar design function.
* It will be used in the sllider design function*/
......@@ -84,6 +85,7 @@ lv_obj_t * lv_slider_create(lv_obj_t * par, lv_obj_t * copy)
lv_slider_ext_t * copy_ext = lv_obj_get_ext(copy);
ext->style_knob = copy_ext->style_knob;
ext->cb = copy_ext->cb;
ext->knob_in = copy_ext->knob_in;
/*Refresh the style with new signal function*/
lv_obj_refr_style(new_slider);
}
......@@ -120,11 +122,13 @@ bool lv_slider_signal(lv_obj_t * slider, lv_signal_t sign, void * param)
else if(sign == LV_SIGNAL_PRESSING) {
lv_dispi_get_point(param, &p);
if(w > h) {
cord_t knob_w = h;
p.x -= slider->cords.x1 + h / 2; /*Modify the point to shift with half knob (important on the start and end)*/
tmp = (int32_t) ((int32_t) p.x * (ext->bar.max_value - ext->bar.min_value + 1)) / (w - h);
tmp = (int32_t) ((int32_t) p.x * (ext->bar.max_value - ext->bar.min_value + 1)) / (w - knob_w);
} else {
cord_t knob_h = w;
p.y -= slider->cords.y1 + w / 2; /*Modify the point to shift with half knob (important on the start and end)*/
tmp = (int32_t) ((int32_t) p.y * (ext->bar.max_value - ext->bar.min_value + 1)) / (h - w);
tmp = (int32_t) ((int32_t) p.y * (ext->bar.max_value - ext->bar.min_value + 1)) / (h - knob_h);
tmp = ext->bar.max_value - tmp; /*Invert he value: small value means higher y*/
}
......@@ -146,8 +150,18 @@ bool lv_slider_signal(lv_obj_t * slider, lv_signal_t sign, void * param)
slider->signal_f(slider, LV_SIGNAL_REFR_EXT_SIZE, NULL);
}
} else if(sign == LV_SIGNAL_REFR_EXT_SIZE) {
cord_t x = MATH_MIN(w, h);
if(slider->ext_size < x) slider->ext_size = x;
if(ext->knob_in == 0) {
cord_t x = MATH_MIN(w, h); /*The smaller size is the knob diameter*/
if(slider->ext_size < x) slider->ext_size = x;
} else {
lv_style_t * style = lv_obj_get_style(slider);
cord_t pad = MATH_MIN(style->hpad, style->vpad);
if(pad < 0) {
pad = -pad;
if(slider->ext_size < pad) slider->ext_size = pad;
}
}
} else if(sign == LV_SIGNAL_CONTROLL) {
lv_slider_ext_t * ext = lv_obj_get_ext(slider);
char c = *((char*)param);
......@@ -194,6 +208,17 @@ void lv_slider_set_style_knob(lv_obj_t * slider, lv_style_t * style)
lv_obj_inv(slider);
}
/**
* Set the 'knob in' attribute of a slider
* @param slider pointer to slider object
* @param in true: the knob is drawn always in the slider;
* false: the knob can be out on the edges
*/
void lv_slider_set_knob_in(lv_obj_t * slider, bool in)
{
lv_slider_ext_t * ext = lv_obj_get_ext(slider);
ext->knob_in = in == false ? 0 : 1;
}
/*=====================
* Getter functions
......@@ -220,6 +245,18 @@ lv_style_t * lv_slider_get_style_knob(lv_obj_t * slider)
return ext->style_knob;
}
/**
* Get the 'knob in' attribute of a slider
* @param slider pointer to slider object
* @return true: the knob is drawn always in the slider;
* false: the knob can be out on the edges
*/
bool lv_slider_get_knob_in(lv_obj_t * slider)
{
lv_slider_ext_t * ext = lv_obj_get_ext(slider);
return ext->knob_in == 0 ? false : true;
}
/**********************
* STATIC FUNCTIONS
**********************/
......@@ -243,6 +280,8 @@ static bool lv_slider_design(lv_obj_t * slider, const area_t * mask, lv_design_m
}
/*Draw the object*/
else if(mode == LV_DESIGN_DRAW_MAIN) {
lv_slider_ext_t * ext = lv_obj_get_ext(slider);
lv_style_t * style_slider = lv_obj_get_style(slider);
lv_style_t * style_knob = lv_slider_get_style_knob(slider);
lv_style_t * style_indic = lv_bar_get_style_indic(slider);
......@@ -251,8 +290,8 @@ static bool lv_slider_design(lv_obj_t * slider, const area_t * mask, lv_design_m
area_t area_bar;
area_cpy(&area_bar, &slider->cords);
/*Be sure at least vpad/hpad width bar will remain*/
cord_t vpad_bar = style_indic->vpad;
cord_t hpad_bar = style_indic->hpad;
cord_t vpad_bar = style_slider->vpad;
cord_t hpad_bar = style_slider->hpad;
if(vpad_bar * 2 + LV_SLIDER_SIZE_MIN > area_get_height(&area_bar)) {
vpad_bar = (area_get_height(&area_bar) - LV_SLIDER_SIZE_MIN) >> 1;
}
......@@ -295,27 +334,39 @@ static bool lv_slider_design(lv_obj_t * slider, const area_t * mask, lv_design_m
if(slider_w >= slider_h) {
area_indic.x2 = (int32_t) ((int32_t)area_get_width(&area_indic) * act_value) / (max_value - min_value);
area_indic.x2 += area_indic.x1;
} else {
area_indic.y1 = (int32_t) ((int32_t)area_get_height(&area_indic) * act_value) / (max_value - min_value);
area_indic.y1 = area_indic.y2 - area_indic.y1;
}
/*Draw the indicator*/
lv_draw_rect(&area_indic, mask, style_indic);
if(act_value != min_value) lv_draw_rect(&area_indic, mask, style_indic);
area_t knob_area;
area_cpy(&knob_area, &slider->cords);
if(slider_w >= slider_h) {
knob_area.x1 = area_indic.x2 - slider_h / 2;
knob_area.x2 = knob_area.x1 + slider_h;
if(ext->knob_in == 0) {
knob_area.x1 = area_indic.x2 - slider_h / 2;
knob_area.x2 = knob_area.x1 + slider_h;
} else {
knob_area.x1 = (int32_t) ((int32_t)(slider_w - slider_h) * act_value) / (max_value - min_value);
knob_area.x1 += slider->cords.x1;
knob_area.x2 = knob_area.x1 + slider_h;
}
knob_area.y1 = slider->cords.y1;
knob_area.y2 = slider->cords.y2;
} else {
knob_area.y1 = area_indic.y1 - slider_w / 2;
knob_area.y2 = knob_area.y1 + slider_w;
if(ext->knob_in == 0) {
knob_area.y1 = area_indic.y1 - slider_w / 2;
knob_area.y2 = knob_area.y1 + slider_w;
} else {
knob_area.y2 = (int32_t) ((int32_t)(slider_h - slider_w) * act_value) / (max_value - min_value);
knob_area.y2 = slider->cords.y2 - knob_area.y2;
knob_area.y1 = knob_area.y2 - slider_w;
}
knob_area.x1 = slider->cords.x1;
knob_area.x2 = slider->cords.x2;
......
......@@ -34,6 +34,7 @@ typedef struct
lv_action_t cb; /*Function to call when a new value is set*/
lv_style_t * style_knob; /*Style of the knob*/
int16_t tmp_value; /*Store a temporal value during press until release (Handled by the library)*/
uint8_t knob_in :1; /*1: Draw the knob inside the bar*/
}lv_slider_ext_t;
/*Built-in styles of slider*/
......@@ -78,6 +79,14 @@ void lv_slider_set_action(lv_obj_t * slider, lv_action_t cb);
void lv_slider_set_style_knob(lv_obj_t * slider, lv_style_t * style);
/**
* Set the 'knob in' attribute of a slider
* @param slider pointer to slider object
* @param in true: the knob is drawn always in the slider;
* false: the knob can be out on the edges
*/
void lv_slider_set_knob_in(lv_obj_t * slider, bool in);
/**
* Get the slider callback function
* @param slider pointer to slider object
* @return the callback function
......@@ -91,6 +100,14 @@ lv_action_t lv_slider_get_action(lv_obj_t * slider);
*/
lv_style_t * lv_slider_get_style_knob(lv_obj_t * slider);
/**
* Get the 'knob in' attribute of a slider
* @param slider pointer to slider object
* @return true: the knob is drawn always in the slider;
* false: the knob can be out on the edges
*/
bool lv_slider_get_knob_in(lv_obj_t * slider);
/**********************
* MACROS
**********************/
......
/**
* @file lv_sw.c
*
*/
/*********************
* INCLUDES
*********************/
#include "lv_conf.h"
#if USE_LV_SW != 0
#include "lv_sw.h"
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
#if 0 /*Slider design is used*/
static bool lv_sw_design(lv_obj_t * sw, const area_t * mask, lv_design_mode_t mode);
#endif
/**********************
* STATIC VARIABLES
**********************/
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
/*-----------------
* Create function
*-----------------*/
/**
* Create a switch objects
* @param par pointer to an object, it will be the parent of the new switch
* @param copy pointer to a switch object, if not NULL then the new object will be copied from it
* @return pointer to the created switch
*/
lv_obj_t * lv_sw_create(lv_obj_t * par, lv_obj_t * copy)
{
/*Create the ancestor of switch*/
lv_obj_t * new_sw = lv_slider_create(par, copy);
dm_assert(new_sw);
/*Allocate the switch type specific extended data*/
lv_sw_ext_t * ext = lv_obj_alloc_ext(new_sw, sizeof(lv_sw_ext_t));
dm_assert(ext);
/*Initialize the allocated 'ext' */
ext->changed = 0;
/*The signal and design functions are not copied so set them here*/
lv_obj_set_signal_f(new_sw, lv_sw_signal);
/*Init the new switch switch*/
if(copy == NULL) {
lv_bar_set_range(new_sw, 0, 1);
lv_obj_set_size(new_sw, LV_DPI, LV_DPI / 2);
lv_slider_set_knob_in(new_sw, true);
}
/*Copy an existing switch*/
else {
/*Nothing to copy*/
/*Refresh the style with new signal function*/
lv_obj_refr_style(new_sw);
}
return new_sw;
}
/**
* Signal function of the switch
* @param sw pointer to a switch object
* @param sign a signal type from lv_signal_t enum
* @param param pointer to a signal specific variable
* @return true: the object is still valid (not deleted), false: the object become invalid
*/
bool lv_sw_signal(lv_obj_t * sw, lv_signal_t sign, void * param)
{
bool valid;
lv_sw_ext_t * ext = lv_obj_get_ext(sw);
int16_t old_val = lv_bar_get_value(sw);
lv_action_t slider_cb = ext->slider.cb;
ext->slider.cb = NULL; /*Do not let the slider to call the callback. The Switch will do it*/
/* Include the ancient signal function */
valid = lv_slider_signal(sw, sign, param);
/* The object can be deleted so check its validity and then
* make the object specific signal handling */
if(valid != false) {
if(sign == LV_SIGNAL_CLEANUP) {
/*Nothing to cleanup. (No dynamically allocated memory in 'ext')*/
}
else if(sign == LV_SIGNAL_PRESSING) {
int16_t act_val = lv_bar_get_value(sw);
if(act_val != old_val) ext->changed = 1;
}
else if(sign == LV_SIGNAL_PRESS_LOST) {
ext->changed = 0;
}
else if(sign == LV_SIGNAL_RELEASED) {
if(ext->changed == 0) {
int16_t v = lv_bar_get_value(sw);
if(v == 0) lv_bar_set_value(sw, 1);
else lv_bar_set_value(sw, 0);
}
if(slider_cb != NULL) slider_cb(sw, param);
ext->changed = 0;
}
}
/*Restore the callback*/
ext->slider.cb = slider_cb;
return valid;
}
/*=====================
* Setter functions
*====================*/
/*
* New object specific "set" function comes here
*/
/*=====================
* Getter functions
*====================*/
/*
* New object specific "get" function comes here
*/
/**********************
* STATIC FUNCTIONS
**********************/
#if 0 /*Slider design is used*/
/**
* Handle the drawing related tasks of the switchs
* @param sw pointer to an object
* @param mask 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 true/false, depends on 'mode'
*/
static bool lv_sw_design(lv_obj_t * sw, const area_t * mask, lv_design_mode_t mode)
{
/*Return false if the object is not covers the mask_p area*/
if(mode == LV_DESIGN_COVER_CHK) {
return false;
}
/*Draw the object*/
else if(mode == LV_DESIGN_DRAW_MAIN) {
}
/*Post draw when the children are drawn*/
else if(mode == LV_DESIGN_DRAW_POST) {
}
return true;
}
#endif
#endif
/**
* @file lv_sw.h
*
*/
#ifndef LV_SW_H
#define LV_SW_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#include "lv_conf.h"
#if USE_LV_SW != 0
/*Testing of dependencies*/
#if USE_LV_SW == 0
#error "lv_sw: lv_slider is required. Enable it in lv_conf.h (USE_LV_SLIDER 1)"
#endif
#include "../lv_obj/lv_obj.h"
#include "lv_slider.h"
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/*Data of switch*/
typedef struct
{
lv_slider_ext_t slider; /*Ext. of ancestor*/
/*New data for this type */
uint8_t changed :1; /*Indicates the switch explicitly changed by drag*/
}lv_sw_ext_t;
/**********************
* GLOBAL PROTOTYPES
**********************/
/**
* Create a switch objects
* @param par pointer to an object, it will be the parent of the new switch
* @param copy pointer to a switch object, if not NULL then the new object will be copied from it
* @return pointer to the created switch
*/
lv_obj_t * lv_sw_create(lv_obj_t * par, lv_obj_t * copy);
/**
* Signal function of the switch
* @param sw pointer to a switch object
* @param sign a signal type from lv_signal_t enum
* @param param pointer to a signal specific variable
* @return true: the object is still valid (not deleted), false: the object become invalid
*/
bool lv_sw_signal(lv_obj_t * sw, lv_signal_t sign, void * param);
/**********************
* MACROS
**********************/
#endif /*USE_LV_SW*/
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /*LV_SW_H*/
......@@ -522,6 +522,8 @@ void lv_ta_set_cursor_show(lv_obj_t * ta, bool show)
{
lv_ta_ext_t * ext = lv_obj_get_ext(ta);
ext->cursor_show = show == false ? 0 : 1;
ext->cursor_state = 0;
lv_obj_inv(ta);
}
/**
......
/**
* @file lv_tab.c
*
*/
/*********************
* INCLUDES
*********************/
#include "lv_conf.h"
#if USE_LV_TABVIEW != 0
#include <lvgl/lv_objx/lv_tabview.h>
#include "lv_btnm.h"
#include "misc/gfx/anim.h"
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
#if 0 /*Unused*/
static bool lv_tab_design(lv_obj_t * tab, const area_t * mask, lv_design_mode_t mode);
#endif
static bool tabpage_signal(lv_obj_t * tab_page, lv_signal_t sign, void * param);
static bool tabscrl_signal(lv_obj_t * tab_scrl, lv_signal_t sign, void * param);
static void tabpage_pressed_hadler(lv_obj_t * tabview, lv_obj_t * tabpage, lv_dispi_t * dispi);
static void tabpage_pressing_hadler(lv_obj_t * tabview, lv_obj_t * tabpage, lv_dispi_t * dispi);
static void tabpage_press_lost_hadler(lv_obj_t * tabview, lv_obj_t * tabpage, lv_dispi_t * dispi);
static lv_action_res_t tab_btnm_action(lv_obj_t * tab_btnm, uint16_t id);
/**********************
* STATIC VARIABLES
**********************/
static lv_signal_f_t page_scrl_signal;
static const char * tab_def[] = {""};
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
/*-----------------
* Create function
*-----------------*/
/**
* Create a Tab view object
* @param par pointer to an object, it will be the parent of the new tab
* @param copy pointer to a tab object, if not NULL then the new object will be copied from it
* @return pointer to the created tab
*/
lv_obj_t * lv_tabview_create(lv_obj_t * par, lv_obj_t * copy)
{
/*Create the ancestor of tab*/
lv_obj_t * new_tabview = lv_obj_create(par, copy);
dm_assert(new_tabview);
/*Allocate the tab type specific extended data*/
lv_tabview_ext_t * ext = lv_obj_alloc_ext(new_tabview, sizeof(lv_tabview_ext_t));
dm_assert(ext);
/*Initialize the allocated 'ext' */
ext->drag_h = 0;
ext->draging = 0;
ext->tab_act = 0;
ext->point_last.x = 0;
ext->point_last.y = 0;
ext->content = NULL;
ext->indic = NULL;
ext->tabs = NULL;
ext->tab_name_ptr = dm_alloc(sizeof(char*));
ext->tab_name_ptr[0] = "";
/*The signal and design functions are not copied so set them here*/
lv_obj_set_signal_f(new_tabview, lv_tabview_signal);
/*Init the new tab tab*/
if(copy == NULL) {
lv_obj_set_size(new_tabview, LV_HOR_RES, LV_VER_RES);
lv_obj_set_style(new_tabview, lv_style_get(LV_STYLE_PRETTY, NULL));
ext->tabs = lv_btnm_create(new_tabview, NULL);
lv_btnm_set_map(ext->tabs, tab_def);
lv_obj_set_height(ext->tabs, 3 * LV_DPI / 4);
lv_btnm_set_action(ext->tabs, tab_btnm_action);
lv_btnm_set_tgl(ext->tabs, true, 0);
ext->indic = lv_obj_create(ext->tabs, NULL);
lv_style_t * style_indic = lv_obj_get_style(ext->indic);
lv_obj_set_size(ext->indic, LV_DPI, style_indic->line_width);
lv_obj_align(ext->indic, ext->tabs, LV_ALIGN_IN_BOTTOM_LEFT, 0, 0);
lv_obj_set_click(ext->indic, false);
ext->content = lv_cont_create(new_tabview, NULL);
lv_cont_set_fit(ext->content, true, false);
lv_cont_set_layout(ext->content, LV_CONT_LAYOUT_ROW_T);
lv_obj_set_height(ext->content, LV_VER_RES);
lv_obj_set_style(ext->content, lv_style_get(LV_STYLE_TRANSP_TIGHT, NULL));
lv_obj_align(ext->content, ext->tabs, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 0);
}
/*Copy an existing tab*/
else {
lv_tabview_ext_t * copy_ext = lv_obj_get_ext(copy);
ext->point_last.x = 0;
ext->point_last.y = 0;
ext->tabs = lv_btnm_create(new_tabview, copy_ext->tabs);
ext->indic = lv_obj_create(ext->tabs, copy_ext->indic);
ext->content = lv_cont_create(new_tabview, copy_ext->content);
ext->tab_name_ptr = dm_alloc(sizeof(char*));
ext->tab_name_ptr[0] = "";
lv_btnm_set_map(ext->tabs, ext->tab_name_ptr);
uint16_t i;
for (i = 0; i < copy_ext->tab_cnt; i++) {
lv_tabview_add_tab(new_tabview, copy_ext->tab_name_ptr[i]);
}
/*Refresh the style with new signal function*/
lv_obj_refr_style(new_tabview);
}
return new_tabview;
}
/**
* Signal function of the Tab view
* @param tabview pointer to a Tab view object
* @param sign a signal type from lv_signal_t enum
* @param param pointer to a signal specific variable
* @return true: the object is still valid (not deleted), false: the object become invalid
*/
bool lv_tabview_signal(lv_obj_t * tabview, lv_signal_t sign, void * param)
{
bool valid;
/* Include the ancient signal function */
valid = lv_obj_signal(tabview, sign, param);
/* The object can be deleted so check its validity and then
* make the object specific signal handling */
if(valid != false) {
if(sign == LV_SIGNAL_CLEANUP) {
/*Nothing to cleanup. (No dynamically allocated memory in 'ext')*/
} else if(sign == LV_SIGNAL_CORD_CHG) {
lv_tabview_ext_t * ext = lv_obj_get_ext(tabview);
if(ext->content != NULL &&
(lv_obj_get_width(tabview) != area_get_width(param) ||
lv_obj_get_height(tabview) != area_get_height(param)))
{
lv_tabview_realign(tabview);
}
}
}
return valid;
}
/*======================
* Add/remove functions
*=====================*/
/**
* Add a new tab with the given name
* @param tabview pointer to Tab view object where to ass the new tab
* @param name the text on the tab button
* @return pointer to page object (lv_page) which is the containter of the contet
*/
lv_obj_t * lv_tabview_add_tab(lv_obj_t * tabview, const char * name)
{
lv_tabview_ext_t * ext = lv_obj_get_ext(tabview);
/*Create the container page*/
lv_obj_t * h = lv_page_create(ext->content, NULL);
lv_obj_set_size(h, lv_obj_get_width(tabview), lv_obj_get_height(tabview));
lv_obj_set_style(h, lv_style_get(LV_STYLE_PRETTY_COLOR, NULL));
lv_obj_set_signal_f(h, tabpage_signal);
lv_page_set_sb_mode(h, LV_PAGE_SB_MODE_AUTO);
if(page_scrl_signal == NULL) page_scrl_signal = lv_obj_get_signal_f(lv_page_get_scrl(h));
lv_obj_set_signal_f(lv_page_get_scrl(h), tabscrl_signal);
/*Extend the button matrix map with the new name*/
ext->tab_cnt++;
ext->tab_name_ptr = dm_realloc(ext->tab_name_ptr, sizeof(char *) * (ext->tab_cnt + 1));
ext->tab_name_ptr[ext->tab_cnt - 1] = name;
ext->tab_name_ptr[ext->tab_cnt] = "";
lv_btnm_set_map(ext->tabs, ext->tab_name_ptr);
/*Modify the indicator size*/
lv_style_t * style_tabs = lv_obj_get_style(ext->tabs);
cord_t indic_width = (lv_obj_get_width(tabview) - style_tabs->opad * (ext->tab_cnt - 1) - 2 * style_tabs->hpad) / ext->tab_cnt;
lv_obj_set_width(ext->indic, indic_width);
lv_obj_set_x(ext->indic, indic_width * ext->tab_act + style_tabs->opad * ext->tab_act + style_tabs->hpad);
return h;
}
/*=====================
* Setter functions
*====================*/
/**
* Set a new tab
* @param tabview pointer to Tab view object
* @param id index of a tab to load
* @param anim_en true: set with sliding animation; false: set immediately
*/
void lv_tabview_set_act(lv_obj_t * tabview, uint16_t id, bool anim_en)
{
lv_tabview_ext_t * ext = lv_obj_get_ext(tabview);
lv_style_t * style = lv_obj_get_style(ext->content);
ext->tab_act = id >= ext->tab_cnt ? ext->tab_cnt - 1 : id;
#if LV_TABVIEW_ANIM_TIME == 0
anim_en = false;
#endif
cord_t cont_x = -(lv_obj_get_width(tabview) * id + style->opad * id + style->hpad);
if(anim_en == false) {
lv_obj_set_x(ext->content, cont_x);
} else {
anim_t a;
a.var = ext->content;
a.start = lv_obj_get_x(ext->content);
a.end = cont_x;
a.fp = (anim_fp_t)lv_obj_set_x;
a.path = anim_get_path(ANIM_PATH_LIN);
a.end_cb = NULL;
a.act_time = 0;
a.time = LV_TABVIEW_ANIM_TIME;
a.playback = 0;
a.playback_pause = 0;
a.repeat = 0;
a.repeat_pause = 0;
anim_create(&a);
}
/*Move the indicator*/
cord_t indic_width = lv_obj_get_width(ext->indic);
lv_style_t * tabs_style = lv_obj_get_style(ext->tabs);
cord_t indic_x = indic_width * id + tabs_style->opad * id + tabs_style->hpad;
if(anim_en == false) {
lv_obj_set_x(ext->indic, indic_x);
} else {
anim_t a;
a.var = ext->indic;
a.start = lv_obj_get_x(ext->indic);
a.end = indic_x;
a.fp = (anim_fp_t)lv_obj_set_x;
a.path = anim_get_path(ANIM_PATH_LIN);
a.end_cb = NULL;
a.act_time = 0;
a.time = LV_TABVIEW_ANIM_TIME;
a.playback = 0;
a.playback_pause = 0;
a.repeat = 0;
a.repeat_pause = 0;
anim_create(&a);
}
lv_btnm_set_tgl(ext->tabs, true, ext->tab_act);
}
/*=====================
* Getter functions
*====================*/
/**
* Get the index of the currently active tab
* @param tabview pointer to Tab view object
* @return the active tab index
*/
uint16_t lv_tabview_get_tab_act(lv_obj_t * tabview)
{
lv_tabview_ext_t * ext = lv_obj_get_ext(tabview);
return ext->tab_act;
}
/**
* Get the number of tabs
* @param tabview pointer to Tab view object
* @return tab count
*/
uint16_t lv_tabview_get_tab_cnt(lv_obj_t * tabview)
{
lv_tabview_ext_t * ext = lv_obj_get_ext(tabview);
return ext->tab_cnt;
}
/**
* Get the page (content area) of a tab
* @param tabview pointer to Tab view object
* @param id index of the tab (>= 0)
* @return pointer to page (lv_page) object
*/
lv_obj_t * lv_tabview_get_tab_page(lv_obj_t * tabview, uint16_t id)
{
lv_tabview_ext_t * ext = lv_obj_get_ext(tabview);
uint16_t i = 0;
lv_obj_t * page = lv_obj_get_child(ext->content, NULL);
while(page != NULL && i != id) {
i++;
page = lv_obj_get_child(ext->content, page);
}
if(i == id) return page;
return NULL;
}
/**
* Get the tab button matrix (lv_btnm) of a Tab view
* @param tabview pointer to Tab view object
* @return pointer to button matrix (lv_btnm) object which is the tab buttons
*/
lv_obj_t * lv_tabview_get_tabs(lv_obj_t * tabview)
{
lv_tabview_ext_t * ext = lv_obj_get_ext(tabview);
return ext->tabs;
}
/**
* Get the indicator rectangle (lv_obj) of a Tab view
* @param tabview pointer to Tab view object
* @return pointer to Base object (lv_obj) which is the indicator rectangle on the tab buttons
*/
lv_obj_t * lv_tabview_get_indic(lv_obj_t * tabview)
{
lv_tabview_ext_t * ext = lv_obj_get_ext(tabview);
return ext->indic;
}
/*=====================
* Other functions
*====================*/
/**
* Realign and resize the elements of Tab view
* @param tabview pointer to a Tab view object
*/
void lv_tabview_realign(lv_obj_t * tabview)
{
lv_tabview_ext_t * ext = lv_obj_get_ext(tabview);
lv_obj_set_width(ext->tabs, lv_obj_get_width(tabview));
lv_obj_set_height(ext->content, lv_obj_get_height(tabview) - lv_obj_get_height(ext->tabs));
lv_obj_align(ext->content, ext->tabs, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 0);
lv_obj_t * pages = lv_obj_get_child(ext->content, NULL);
while(pages != NULL) {
lv_obj_set_size(pages, lv_obj_get_width(tabview), lv_obj_get_height(tabview) - lv_obj_get_height(ext->tabs));
pages = lv_obj_get_child(ext->content, pages);
}
if(ext->tab_cnt != 0) {
lv_style_t * style_tabs = lv_obj_get_style(ext->tabs);
cord_t indic_width = (lv_obj_get_width(tabview) - style_tabs->opad * (ext->tab_cnt - 1) -
2 * style_tabs->hpad) / ext->tab_cnt;
lv_obj_set_width(ext->indic, indic_width);
}
lv_obj_align(ext->indic, ext->tabs, LV_ALIGN_IN_BOTTOM_LEFT, 0, 0);
lv_tabview_set_act(tabview, ext->tab_act, false);
}
/**********************
* STATIC FUNCTIONS
**********************/
#if 0 /*Unused*/
/**
* Handle the drawing related tasks of the tabs
* @param tab pointer to an object
* @param mask 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 true/false, depends on 'mode'
*/
static bool lv_tab_design(lv_obj_t * tab, const area_t * mask, lv_design_mode_t mode)
{
/*Return false if the object is not covers the mask_p area*/
if(mode == LV_DESIGN_COVER_CHK) {
return false;
}
/*Draw the object*/
else if(mode == LV_DESIGN_DRAW_MAIN) {
}
/*Post draw when the children are drawn*/
else if(mode == LV_DESIGN_DRAW_POST) {
}
return true;
}
#endif
/**
* Signal function of a tab's page
* @param tab pointer to a tab page object
* @param sign a signal type from lv_signal_t enum
* @param param pointer to a signal specific variable
* @return true: the object is still valid (not deleted), false: the object become invalid
*/
static bool tabpage_signal(lv_obj_t * tab_page, lv_signal_t sign, void * param)
{
bool valid;
/* Include the ancient signal function */
valid = lv_page_signal(tab_page, sign, param);
/* The object can be deleted so check its validity and then
* make the object specific signal handling */
if(valid != false) {
lv_obj_t * cont = lv_obj_get_parent(tab_page);
lv_obj_t * tab = lv_obj_get_parent(cont);
if(sign == LV_SIGNAL_PRESSED) {
tabpage_pressed_hadler(tab, tab_page, param);
}
else if(sign == LV_SIGNAL_PRESSING) {
tabpage_pressing_hadler(tab, tab_page, param);
}
else if(sign == LV_SIGNAL_RELEASED || sign == LV_SIGNAL_PRESS_LOST) {
tabpage_press_lost_hadler(tab, tab_page, param);
}
}
return valid;
}
/**
* Signal function of the tab page's scrollable object
* @param tab_scrl pointer to a tab page's scrollable object
* @param sign a signal type from lv_signal_t enum
* @param param pointer to a signal specific variable
* @return true: the object is still valid (not deleted), false: the object become invalid
*/
static bool tabscrl_signal(lv_obj_t * tab_scrl, lv_signal_t sign, void * param)
{
bool valid;
/* Include the ancient signal function */
valid = page_scrl_signal(tab_scrl, sign, param);
/* The object can be deleted so check its validity and then
* make the object specific signal handling */
if(valid != false) {
lv_obj_t * tab_page = lv_obj_get_parent(tab_scrl);
lv_obj_t * cont = lv_obj_get_parent(tab_page);
lv_obj_t * tab = lv_obj_get_parent(cont);
if(sign == LV_SIGNAL_PRESSED) {
tabpage_pressed_hadler(tab, tab_page, param);
}
else if(sign == LV_SIGNAL_PRESSING) {
tabpage_pressing_hadler(tab, tab_page, param);
}
else if(sign == LV_SIGNAL_RELEASED || sign == LV_SIGNAL_PRESS_LOST) {
tabpage_press_lost_hadler(tab, tab_page, param);
}
}
return valid;
}
/**
* Called when a tab's page or scrollable object is pressed
* @param tabview pointer to the tab view object
* @param tabpage pointer to the page of a tab
* @param dispi pointer to the caller dispi
*/
static void tabpage_pressed_hadler(lv_obj_t * tabview, lv_obj_t * tabpage, lv_dispi_t * dispi)
{
lv_tabview_ext_t * ext = lv_obj_get_ext(tabview);
lv_dispi_get_point(dispi, &ext->point_last);
}
/**
* Called when a tab's page or scrollable object is being pressed
* @param tabview pointer to the tab view object
* @param tabpage pointer to the page of a tab
* @param dispi pointer to the caller dispi
*/
static void tabpage_pressing_hadler(lv_obj_t * tabview, lv_obj_t * tabpage, lv_dispi_t * dispi)
{
lv_tabview_ext_t * ext = lv_obj_get_ext(tabview);
point_t point_act;
lv_dispi_get_point(dispi, &point_act);
cord_t x_diff = point_act.x - ext->point_last.x;
cord_t y_diff = point_act.y - ext->point_last.y;
if(ext->draging == 0) {
if(x_diff >= LV_DISPI_DRAG_LIMIT || x_diff<= -LV_DISPI_DRAG_LIMIT) {
ext->drag_h = 1;
ext->draging = 1;
lv_obj_set_drag(lv_page_get_scrl(tabpage), false);
} else if(y_diff >= LV_DISPI_DRAG_LIMIT || y_diff <= -LV_DISPI_DRAG_LIMIT) {
ext->drag_h = 0;
ext->draging = 1;
}
}
if(ext->drag_h != 0) {
lv_obj_set_x(ext->content, lv_obj_get_x(ext->content) + point_act.x - ext->point_last.x);
ext->point_last.x = point_act.x;
ext->point_last.y = point_act.y;
/*Move the indicator*/
cord_t indic_width = lv_obj_get_width(ext->indic);
lv_style_t * tabs_style = lv_obj_get_style(ext->tabs);
lv_style_t * indic_style = lv_obj_get_style(ext->indic);
cord_t p = ((tabpage->cords.x1 - tabview->cords.x1) * (indic_width + tabs_style->opad)) / lv_obj_get_width(tabview);
lv_obj_set_x(ext->indic, indic_width * ext->tab_act + tabs_style->opad * ext->tab_act + indic_style->hpad - p);
}
}
/**
* Called when a tab's page or scrollable object is released or the press id lost
* @param tabview pointer to the tab view object
* @param tabpage pointer to the page of a tab
* @param dispi pointer to the caller dispi
*/
static void tabpage_press_lost_hadler(lv_obj_t * tabview, lv_obj_t * tabpage, lv_dispi_t * dispi)
{
lv_tabview_ext_t * ext = lv_obj_get_ext(tabview);
ext->drag_h = 0;
ext->draging = 0;
lv_obj_set_drag(lv_page_get_scrl(tabpage), true);
point_t point_act;
lv_dispi_get_point(dispi, &point_act);
cord_t x_diff = point_act.x - ext->point_last.x;
cord_t x_predict = 0;
while(x_diff != 0) {
x_predict += x_diff;
x_diff = x_diff * (100 - LV_DISPI_DRAG_THROW) / 100;
}
cord_t page_x1 = tabpage->cords.x1 + x_predict;
cord_t page_x2 = tabpage->cords.x2 + x_predict;
if(page_x1 > (tabview->cords.x2 - tabview->cords.x1) / 2) {
if(ext->tab_act != 0) ext->tab_act--;
} else if(page_x2 < (tabview->cords.x2 - tabview->cords.x1) / 2) {
if(ext->tab_act < ext->tab_cnt - 1) ext->tab_act++;
}
lv_tabview_set_act(tabview, ext->tab_act, true);
}
/**
* Called when a tab button is released
* @param tab_btnm pointer to the tab's button matrix object
* @param id the id of the tab (>= 0)
* @return LV_ACTION_RES_OK because the button matrix in not deleted in the function
*/
static lv_action_res_t tab_btnm_action(lv_obj_t * tab_btnm, uint16_t id)
{
lv_obj_t * tab = lv_obj_get_parent(tab_btnm);
lv_tabview_ext_t * ext = lv_obj_get_ext(tab);
ext->tab_act = id;
lv_tabview_set_act(tab, id, true);
return LV_ACTION_RES_OK;
}
#endif
/**
* @file lv_tabview.h
*
*/
#ifndef LV_TABVIEW_H
#define LV_TABVIEW_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#include "lv_conf.h"
#if USE_LV_TABVIEW != 0
/*Testing of dependencies*/
#if USE_LV_BTNM == 0
#error "lv_tabview: lv_btnm is required. Enable it in lv_conf.h (USE_LV_BTNM 1) "
#endif
#if USE_LV_PAGE == 0
#error "lv_tabview: lv_page is required. Enable it in lv_conf.h (USE_LV_PAGE 1) "
#endif
#include "../lv_obj/lv_obj.h"
#include "../lv_objx/lv_win.h"
#include "../lv_objx/lv_page.h"
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/*Data of tab*/
typedef struct
{
/*Ext. of ancestor*/
/*New data for this type */
lv_obj_t * tabs;
lv_obj_t * indic;
lv_obj_t * content; /*A rectangle to show the current tab*/
const char ** tab_name_ptr;
point_t point_last;
uint16_t tab_act;
uint16_t tab_cnt;
uint8_t draging :1;
uint8_t drag_h :1;
}lv_tabview_ext_t;
/**********************
* GLOBAL PROTOTYPES
**********************/
/**
* Create a Tab view objects
* @param par pointer to an object, it will be the parent of the new tab
* @param copy pointer to a tab object, if not NULL then the new object will be copied from it
* @return pointer to the created tab
*/
lv_obj_t * lv_tabview_create(lv_obj_t * par, lv_obj_t * copy);
/**
* Signal function of the Tab view
* @param tab pointer to a tab object
* @param sign a signal type from lv_signal_t enum
* @param param pointer to a signal specific variable
* @return true: the object is still valid (not deleted), false: the object become invalid
*/
bool lv_tabview_signal(lv_obj_t * tab, lv_signal_t sign, void * param);
/**
* Realign and resize the elements of Tab view
* @param tabview pointer to a Tab view object
*/
void lv_tabview_realign(lv_obj_t * tabview);
/**
* Set a new tab
* @param tabview pointer to Tab view object
* @param id index of a tab to load
* @param anim_en true: set with sliding animation; false: set immediately
*/
void lv_tabview_set_act(lv_obj_t * tabview, uint16_t id, bool anim_en);
/**
* Get the index of the currently active tab
* @param tabview pointer to Tab view object
* @return the active tab index
*/
uint16_t lv_tabview_get_tab_act(lv_obj_t * tabview);
/**
* Get the number of tabs
* @param tabview pointer to Tab view object
* @return tab count
*/
uint16_t lv_tabview_get_tab_cnt(lv_obj_t * tabview);
/**
* Get the page (content area) of a tab
* @param tabview pointer to Tab view object
* @param id index of the tab (>= 0)
* @return pointer to page (lv_page) object
*/
lv_obj_t * lv_tabview_get_tab_page(lv_obj_t * tabview, uint16_t id);
/**
* Get the tab button matrix (lv_btnm) of a Tab view
* @param tabview pointer to Tab view object
* @return pointer to button matrix (lv_btnm) object which is the tab buttons
*/
lv_obj_t * lv_tabview_get_tabs(lv_obj_t * tabview);
/**
* Get the indicator rectangle (lv_obj) of a Tab view
* @param tabview pointer to Tab view object
* @return pointer to Base object (lv_obj) which is the indicator rectangle on the tab buttons
*/
lv_obj_t * lv_tabview_get_indic(lv_obj_t * tabview);
/**
* Add a new tab with the given name
* @param tabview pointer to Tab view object where to ass the new tab
* @param name the text on the tab button
* @return pointer to page object (lv_page) which is the containter of the contet
*/
lv_obj_t * lv_tabview_add_tab(lv_obj_t * tabview, const char * name);
/**********************
* MACROS
**********************/
#endif /*USE_LV_TABVIEW*/
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /*LV_TAB_H*/
......@@ -31,12 +31,16 @@ extern "C" {
#include "lv_objx/lv_slider.h"
#include "lv_objx/lv_led.h"
#include "lv_objx/lv_btnm.h"
#include "lv_objx/lv_kb.h"
#include "lv_objx/lv_ddlist.h"
#include "lv_objx/lv_ta.h"
#include "lv_objx/lv_win.h"
#include "lv_objx/lv_tabview.h"
#include "lv_objx/lv_mbox.h"
#include "lv_objx/lv_gauge.h"
#include "lv_objx/lv_lmeter.h"
#include "lv_objx/lv_sw.h"
#include "lv_objx/lv_kb.h"
#include "lv_app/lv_app.h"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment