1
0
mirror of https://github.com/lvgl/lvgl.git synced 2025-01-21 06:53:01 +08:00
lvgl/src/lv_core/lv_group.h

290 lines
8.4 KiB
C
Raw Normal View History

2017-07-19 15:19:10 +02:00
/**
* @file lv_group.h
*
*/
#ifndef LV_GROUP_H
#define LV_GROUP_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#ifdef LV_CONF_INCLUDE_SIMPLE
#include "lv_conf.h"
#else
2019-03-17 08:33:03 +01:00
#include "../../../lv_conf.h"
#endif
2017-07-19 15:19:10 +02:00
#include "lv_obj.h"
/*********************
* DEFINES
*********************/
/*Predefined keys to control the focused object via lv_group_send(group, c)*/
2019-05-13 05:50:27 +02:00
/*For compatibility in signal function define the keys regardless to `LV_USE_GROUP`*/
2019-05-15 06:46:27 +02:00
enum {
2019-05-13 05:50:27 +02:00
LV_KEY_UP = 17, /*0x11*/
LV_KEY_DOWN = 18, /*0x12*/
LV_KEY_RIGHT = 19, /*0x13*/
LV_KEY_LEFT = 20, /*0x14*/
LV_KEY_ESC = 27, /*0x1B*/
LV_KEY_DEL = 127, /*0x7F*/
LV_KEY_BACKSPACE = 8, /*0x08*/
LV_KEY_ENTER = 10, /*0x0A, '\n'*/
LV_KEY_NEXT = 9, /*0x09, '\t'*/
LV_KEY_PREV=11, /*0x0B, '*/
LV_KEY_HOME = 2, /*0x02, STX*/
LV_KEY_END = 3, /*0x03, ETX*/
2019-05-15 06:46:27 +02:00
};
typedef uint8_t lv_key_t;
2019-04-04 07:15:40 +02:00
#if LV_USE_GROUP != 0
2017-07-19 15:19:10 +02:00
/**********************
* TYPEDEFS
**********************/
struct _lv_group_t;
typedef void (*lv_group_style_mod_cb_t)(struct _lv_group_t *, lv_style_t *);
typedef void (*lv_group_focus_cb_t)(struct _lv_group_t *);
2017-11-19 19:28:45 +01:00
typedef struct _lv_group_t
2017-07-19 15:19:10 +02:00
{
2019-04-04 07:15:40 +02:00
lv_ll_t obj_ll; /*Linked list to store the objects in the group */
lv_obj_t ** obj_focus; /*The object in focus*/
2019-04-22 08:45:07 +02:00
lv_group_style_mod_cb_t style_mod_cb; /*A function to modifies the style of the focused object*/
lv_group_style_mod_cb_t style_mod_edit_cb; /*A function which modifies the style of the edited object*/
2019-04-04 07:15:40 +02:00
lv_group_focus_cb_t focus_cb; /*A function to call when a new object is focused (optional)*/
lv_style_t style_tmp; /*Stores the modified style of the focused object */
#if LV_USE_USER_DATA
2019-04-04 07:15:40 +02:00
lv_group_user_data_t user_data;
2019-03-03 11:20:49 +01:00
#endif
2019-04-04 07:15:40 +02:00
uint8_t frozen : 1; /*1: can't focus to new object*/
uint8_t editing : 1; /*1: Edit mode, 0: Navigate mode*/
uint8_t click_focus : 1; /*1: If an object in a group is clicked by an indev then it will be
focused */
uint8_t refocus_policy : 1; /*1: Focus prev if focused on deletion. 0: Focus next if focused on
deletion.*/
uint8_t wrap : 1; /*1: Focus next/prev can wrap at end of list. 0: Focus next/prev stops at end
of list.*/
2018-06-19 09:49:58 +02:00
} lv_group_t;
2017-07-19 15:19:10 +02:00
2019-04-04 07:15:40 +02:00
enum { LV_GROUP_REFOCUS_POLICY_NEXT = 0, LV_GROUP_REFOCUS_POLICY_PREV = 1 };
typedef uint8_t lv_group_refocus_policy_t;
2018-10-28 15:27:41 -07:00
2017-07-19 15:19:10 +02:00
/**********************
* GLOBAL PROTOTYPES
**********************/
2017-11-19 20:45:40 +01:00
/**
2019-04-04 07:15:40 +02:00
* Init. the group module
* @remarks Internal function, do not call directly.
*/
void lv_group_init(void);
2017-11-19 20:45:40 +01:00
/**
* Create a new object group
* @return pointer to the new object group
*/
2017-07-19 15:19:10 +02:00
lv_group_t * lv_group_create(void);
2017-11-19 20:45:40 +01:00
/**
* Delete a group object
* @param group pointer to a group
*/
void lv_group_del(lv_group_t * group);
2017-11-19 20:45:40 +01:00
/**
* Add an object to a group
* @param group pointer to a group
* @param obj pointer to an object to add
*/
void lv_group_add_obj(lv_group_t * group, lv_obj_t * obj);
2017-11-19 20:45:40 +01:00
/**
* Remove an object from its group
* @param obj pointer to an object to remove
*/
void lv_group_remove_obj(lv_obj_t * obj);
/**
* Remove all objects from a group
* @param group pointer to a group
*/
void lv_group_remove_all_objs(lv_group_t * group);
2017-11-19 20:45:40 +01:00
/**
* Focus on an object (defocus the current)
* @param obj pointer to an object to focus on
*/
void lv_group_focus_obj(lv_obj_t * obj);
2017-11-19 20:45:40 +01:00
/**
* Focus the next object in a group (defocus the current)
* @param group pointer to a group
*/
void lv_group_focus_next(lv_group_t * group);
2017-11-19 20:45:40 +01:00
/**
* Focus the previous object in a group (defocus the current)
* @param group pointer to a group
*/
void lv_group_focus_prev(lv_group_t * group);
2017-11-19 20:45:40 +01:00
/**
* Do not let to change the focus from the current object
* @param group pointer to a group
* @param en true: freeze, false: release freezing (normal mode)
*/
2017-07-27 12:07:16 +02:00
void lv_group_focus_freeze(lv_group_t * group, bool en);
2017-11-19 20:45:40 +01:00
/**
* Send a control character to the focuses object of a group
* @param group pointer to a group
2019-04-08 14:36:20 +02:00
* @param c a character (use LV_KEY_.. to navigate)
* @return result of focused object in group.
2017-11-19 20:45:40 +01:00
*/
lv_res_t lv_group_send_data(lv_group_t * group, uint32_t c);
2017-11-19 20:45:40 +01:00
/**
* Set a function for a group which will modify the object's style if it is in focus
* @param group pointer to a group
* @param style_mod_cb the style modifier function pointer
*/
void lv_group_set_style_mod_cb(lv_group_t * group, lv_group_style_mod_cb_t style_mod_cb);
/**
* Set a function for a group which will modify the object's style if it is in focus in edit mode
* @param group pointer to a group
* @param style_mod_edit_cb the style modifier function pointer
*/
void lv_group_set_style_mod_edit_cb(lv_group_t * group, lv_group_style_mod_cb_t style_mod_edit_cb);
/**
* Set a function for a group which will be called when a new object is focused
* @param group pointer to a group
* @param focus_cb the call back function or NULL if unused
2017-11-19 20:45:40 +01:00
*/
void lv_group_set_focus_cb(lv_group_t * group, lv_group_focus_cb_t focus_cb);
2017-11-19 20:45:40 +01:00
2018-10-28 15:27:41 -07:00
/**
2019-04-04 07:15:40 +02:00
* Set whether the next or previous item in a group is focused if the currently focussed obj is
* deleted.
2018-10-28 15:27:41 -07:00
* @param group pointer to a group
* @param new refocus policy enum
*/
void lv_group_set_refocus_policy(lv_group_t * group, lv_group_refocus_policy_t policy);
/**
* Manually set the current mode (edit or navigate).
* @param group pointer to group
* @param edit: true: edit mode; false: navigate mode
*/
void lv_group_set_editing(lv_group_t * group, bool edit);
2018-07-12 23:38:27 +02:00
/**
* Set the `click_focus` attribute. If enabled then the object will be focused then it is clicked.
* @param group pointer to group
* @param en: true: enable `click_focus`
*/
void lv_group_set_click_focus(lv_group_t * group, bool en);
/**
* Set whether focus next/prev will allow wrapping from first->last or last->first object.
* @param group pointer to group
* @param en: true: wrapping enabled; false: wrapping disabled
*/
void lv_group_set_wrap(lv_group_t * group, bool en);
2017-11-19 20:45:40 +01:00
/**
* Modify a style with the set 'style_mod' function. The input style remains unchanged.
* @param group pointer to group
* @param style pointer to a style to modify
* @return a copy of the input style but modified with the 'style_mod' function
*/
lv_style_t * lv_group_mod_style(lv_group_t * group, const lv_style_t * style);
2017-11-19 20:45:40 +01:00
/**
* Get the focused object or NULL if there isn't one
* @param group pointer to a group
* @return pointer to the focused object
*/
lv_obj_t * lv_group_get_focused(const lv_group_t * group);
2017-07-19 15:19:10 +02:00
#if LV_USE_USER_DATA
2019-03-06 23:14:19 +01:00
/**
* Get a pointer to the group's user data
* @param group pointer to an group
* @return pointer to the user data
*/
lv_group_user_data_t * lv_group_get_user_data(lv_group_t * group);
2019-03-06 23:14:19 +01:00
#endif
/**
* Get a the style modifier function of a group
* @param group pointer to a group
* @return pointer to the style modifier function
*/
lv_group_style_mod_cb_t lv_group_get_style_mod_cb(const lv_group_t * group);
/**
* Get a the style modifier function of a group in edit mode
* @param group pointer to a group
* @return pointer to the style modifier function
*/
lv_group_style_mod_cb_t lv_group_get_style_mod_edit_cb(const lv_group_t * group);
/**
* Get the focus callback function of a group
* @param group pointer to a group
* @return the call back function or NULL if not set
*/
lv_group_focus_cb_t lv_group_get_focus_cb(const lv_group_t * group);
/**
* Get the current mode (edit or navigate).
* @param group pointer to group
* @return true: edit mode; false: navigate mode
*/
bool lv_group_get_editing(const lv_group_t * group);
2018-07-12 23:38:27 +02:00
/**
* Get the `click_focus` attribute.
* @param group pointer to group
* @return true: `click_focus` is enabled; false: disabled
*/
bool lv_group_get_click_focus(const lv_group_t * group);
2018-07-12 23:38:27 +02:00
/**
* Get whether focus next/prev will allow wrapping from first->last or last->first object.
* @param group pointer to group
* @param en: true: wrapping enabled; false: wrapping disabled
*/
bool lv_group_get_wrap(lv_group_t * group);
2018-07-12 23:38:27 +02:00
/**
2019-04-04 07:15:40 +02:00
* Notify the group that current theme changed and style modification callbacks need to be
* refreshed.
* @param group pointer to group. If NULL then all groups are notified.
*/
void lv_group_report_style_mod(lv_group_t * group);
2017-07-19 15:19:10 +02:00
/**********************
* MACROS
**********************/
#endif /*LV_USE_GROUP != 0*/
2017-07-19 15:19:10 +02:00
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /*LV_GROUP_H*/