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

181 lines
4.8 KiB
C
Raw Normal View History

2017-08-23 09:24:23 +02:00
/**
* @file lv_kb.h
2018-06-19 09:49:58 +02:00
*
2017-08-23 09:24:23 +02:00
*/
#ifndef LV_KEYBOARD_H
#define LV_KEYBOARD_H
2017-08-23 09:24:23 +02:00
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#include "../lv_conf_internal.h"
#if LV_USE_KEYBOARD != 0
2017-08-23 09:24:23 +02:00
/*Testing of dependencies*/
#if LV_USE_BTNMATRIX == 0
#error "lv_kb: lv_btnm is required. Enable it in lv_conf.h (LV_USE_BTNMATRIX 1) "
#endif
#if LV_USE_TEXTAREA == 0
#error "lv_kb: lv_ta is required. Enable it in lv_conf.h (LV_USE_TEXTAREA 1) "
#endif
2017-11-30 11:35:33 +01:00
#include "../lv_core/lv_obj.h"
2020-02-14 12:44:15 +01:00
#include "lv_btnmatrix.h"
2017-08-23 09:24:23 +02:00
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
2019-06-27 18:07:26 -04:00
/** Current keyboard mode. */
2018-09-18 13:59:40 +02:00
enum {
LV_KEYBOARD_MODE_TEXT_LOWER,
LV_KEYBOARD_MODE_TEXT_UPPER,
LV_KEYBOARD_MODE_SPECIAL,
LV_KEYBOARD_MODE_NUM,
2018-09-18 13:59:40 +02:00
};
typedef uint8_t lv_keyboard_mode_t;
2019-11-16 13:06:30 -08:00
2017-08-23 09:24:23 +02:00
/*Data of keyboard*/
2019-04-04 07:15:40 +02:00
typedef struct
{
lv_btnmatrix_ext_t btnm; /*Ext. of ancestor*/
2017-08-23 09:24:23 +02:00
/*New data for this type */
2019-06-06 06:05:40 +02:00
lv_obj_t * ta; /*Pointer to the assigned text area*/
lv_keyboard_mode_t mode; /*Key map type*/
2019-06-06 06:05:40 +02:00
uint8_t cursor_mng : 1; /*1: automatically show/hide cursor when a text area is assigned or left*/
} lv_keyboard_ext_t;
2017-08-23 09:24:23 +02:00
2018-09-18 13:59:40 +02:00
enum {
LV_KEYBOARD_PART_BG,
LV_KEYBOARD_PART_BTN,
2018-09-18 13:59:40 +02:00
};
typedef uint8_t lv_keyboard_style_t;
2018-09-18 13:59:40 +02:00
2017-08-23 09:24:23 +02:00
/**********************
* 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_keyboard_create(lv_obj_t * par, const lv_obj_t * copy);
2017-08-23 09:24:23 +02:00
2017-11-10 15:01:40 +01:00
/*=====================
* Setter functions
*====================*/
2017-08-23 09:24:23 +02:00
2017-08-23 14:15:33 +02:00
/**
* 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_keyboard_set_ta(lv_obj_t * kb, lv_obj_t * ta);
2017-08-23 14:15:33 +02:00
/**
* Set a new a mode (text or number map)
* @param kb pointer to a Keyboard object
* @param mode the mode from 'lv_keyboard_mode_t'
2017-08-23 14:15:33 +02:00
*/
void lv_keyboard_set_mode(lv_obj_t * kb, lv_keyboard_mode_t mode);
2017-08-23 14:15:33 +02:00
/**
2017-11-10 15:01:40 +01:00
* Automatically hide or show the cursor of the current Text Area
2017-08-23 14:15:33 +02:00
* @param kb pointer to a Keyboard object
* @param en true: show cursor on the current text area, false: hide cursor
*/
void lv_keyboard_set_cursor_manage(lv_obj_t * kb, bool en);
2017-08-23 14:15:33 +02:00
2017-12-19 22:00:32 +01:00
/**
* Set a new map for the keyboard
* @param kb pointer to a Keyboard object
* @param mode keyboard map to alter 'lv_keyboard_mode_t'
2017-12-19 22:00:32 +01:00
* @param map pointer to a string array to describe the map.
* See 'lv_btnmatrix_set_map()' for more info.
2017-12-19 22:00:32 +01:00
*/
void lv_keyboard_set_map(lv_obj_t * kb, lv_keyboard_mode_t mode, const char * map[]);
2017-08-23 14:15:33 +02:00
/**
* Set the button control map (hidden, disabled etc.) for the keyboard. The
* control map array will be copied and so may be deallocated after this
* function returns.
* @param kb pointer to a keyboard object
* @param mode keyboard ctrl map to alter 'lv_keyboard_mode_t'
* @param ctrl_map pointer to an array of `lv_btn_ctrl_t` control bytes.
* See: `lv_btnmatrix_set_ctrl_map` for more details.
*/
void lv_keyboard_set_ctrl_map(lv_obj_t * kb, lv_keyboard_mode_t mode, const lv_btnmatrix_ctrl_t ctrl_map[]);
2017-11-10 15:01:40 +01:00
/*=====================
* Getter functions
*====================*/
2017-08-23 14:15:33 +02:00
/**
* 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_keyboard_get_ta(const lv_obj_t * kb);
2017-11-10 15:01:40 +01:00
2017-08-23 14:15:33 +02:00
/**
* Set a new a mode (text or number map)
* @param kb pointer to a Keyboard object
* @return the current mode from 'lv_keyboard_mode_t'
2017-08-23 14:15:33 +02:00
*/
lv_keyboard_mode_t lv_keyboard_get_mode(const lv_obj_t * kb);
2017-08-23 14:15:33 +02:00
/**
* 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_keyboard_get_cursor_manage(const lv_obj_t * kb);
2017-08-23 14:15:33 +02:00
/**
* Get the current map of a keyboard
* @param kb pointer to a keyboard object
* @return the current map
*/
static inline const char ** lv_keyboard_get_map_array(const lv_obj_t * kb)
2019-04-10 06:25:44 +02:00
{
return lv_btnmatrix_get_map_array(kb);
2019-04-10 06:25:44 +02:00
}
/*=====================
* Other functions
*====================*/
/**
* Default keyboard event to add characters to the Text area and change the map.
2019-04-04 07:15:40 +02:00
* If a custom `event_cb` is added to the keyboard this function be called from it to handle the
* button clicks
* @param kb pointer to a keyboard
* @param event the triggering event
*/
void lv_keyboard_def_event_cb(lv_obj_t * kb, lv_event_t event);
2017-08-23 09:24:23 +02:00
/**********************
* MACROS
**********************/
#endif /*LV_USE_KEYBOARD*/
2017-08-23 09:24:23 +02:00
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /*LV_KEYBOARD_H*/