/*1* Copyright (c) 2019-2020 CTCaer2*3* This program is free software; you can redistribute it and/or modify it4* under the terms and conditions of the GNU General Public License,5* version 2, as published by the Free Software Foundation.6*7* This program is distributed in the hope it will be useful, but WITHOUT8* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or9* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for10* more details.11*12* You should have received a copy of the GNU General Public License13* along with this program. If not, see <http://www.gnu.org/licenses/>.14*/1516/**17* @file lv_kb.h18*19*/2021#ifndef LV_KB_H22#define LV_KB_H2324#ifdef __cplusplus25extern "C" {26#endif2728/*********************29* INCLUDES30*********************/31#ifdef LV_CONF_INCLUDE_SIMPLE32#include "lv_conf.h"33#else34#include "../../lv_conf.h"35#endif3637#if USE_LV_KB != 03839/*Testing of dependencies*/40#if USE_LV_BTNM == 041#error "lv_kb: lv_btnm is required. Enable it in lv_conf.h (USE_LV_BTNM 1) "42#endif4344#if USE_LV_TA == 045#error "lv_kb: lv_ta is required. Enable it in lv_conf.h (USE_LV_TA 1) "46#endif4748#include "../lv_core/lv_obj.h"49#include "lv_btnm.h"5051/*********************52* DEFINES53*********************/5455/**********************56* TYPEDEFS57**********************/5859enum {60LV_KB_MODE_TEXT,61LV_KB_MODE_NUM,62LV_KB_MODE_HEX63};64typedef uint8_t lv_kb_mode_t;6566/*Data of keyboard*/67typedef struct {68lv_btnm_ext_t btnm; /*Ext. of ancestor*/69/*New data for this type */70lv_obj_t *ta; /*Pointer to the assigned text area*/71lv_kb_mode_t mode; /*Key map type*/72uint8_t cursor_mng :1; /*1: automatically show/hide cursor when a text area is assigned or left*/73lv_action_t ok_action; /*Called when the "Ok" button is clicked*/74lv_action_t hide_action; /*Called when the "Hide" button is clicked*/75} lv_kb_ext_t;7677enum {78LV_KB_STYLE_BG,79LV_KB_STYLE_BTN_REL,80LV_KB_STYLE_BTN_PR,81LV_KB_STYLE_BTN_TGL_REL,82LV_KB_STYLE_BTN_TGL_PR,83LV_KB_STYLE_BTN_INA,84};85typedef uint8_t lv_kb_style_t;868788/**********************89* GLOBAL PROTOTYPES90**********************/9192/**93* Create a keyboard objects94* @param par pointer to an object, it will be the parent of the new keyboard95* @param copy pointer to a keyboard object, if not NULL then the new object will be copied from it96* @return pointer to the created keyboard97*/98lv_obj_t * lv_kb_create(lv_obj_t * par, const lv_obj_t * copy);99100/*=====================101* Setter functions102*====================*/103104/**105* Assign a Text Area to the Keyboard. The pressed characters will be put there.106* @param kb pointer to a Keyboard object107* @param ta pointer to a Text Area object to write there108*/109void lv_kb_set_ta(lv_obj_t * kb, lv_obj_t * ta);110111/**112* Set a new a mode (text or number map)113* @param kb pointer to a Keyboard object114* @param mode the mode from 'lv_kb_mode_t'115*/116void lv_kb_set_mode(lv_obj_t * kb, lv_kb_mode_t mode);117118/**119* Automatically hide or show the cursor of the current Text Area120* @param kb pointer to a Keyboard object121* @param en true: show cursor on the current text area, false: hide cursor122*/123void lv_kb_set_cursor_manage(lv_obj_t * kb, bool en);124125/**126* Set call back to call when the "Ok" button is pressed127* @param kb pointer to Keyboard object128* @param action a callback with 'lv_action_t' type129*/130void lv_kb_set_ok_action(lv_obj_t * kb, lv_action_t action);131132/**133* Set call back to call when the "Hide" button is pressed134* @param kb pointer to Keyboard object135* @param action a callback with 'lv_action_t' type136*/137void lv_kb_set_hide_action(lv_obj_t * kb, lv_action_t action);138139/**140* Set a new map for the keyboard141* @param kb pointer to a Keyboard object142* @param map pointer to a string array to describe the map.143* See 'lv_btnm_set_map()' for more info.144*/145static inline void lv_kb_set_map(lv_obj_t *kb, const char ** map)146{147lv_btnm_set_map(kb, map);148}149150/**151* Set a style of a keyboard152* @param kb pointer to a keyboard object153* @param type which style should be set154* @param style pointer to a style155*/156void lv_kb_set_style(lv_obj_t *kb, lv_kb_style_t type, lv_style_t *style);157158/*=====================159* Getter functions160*====================*/161162/**163* Assign a Text Area to the Keyboard. The pressed characters will be put there.164* @param kb pointer to a Keyboard object165* @return pointer to the assigned Text Area object166*/167lv_obj_t * lv_kb_get_ta(const lv_obj_t * kb);168169/**170* Set a new a mode (text or number map)171* @param kb pointer to a Keyboard object172* @return the current mode from 'lv_kb_mode_t'173*/174lv_kb_mode_t lv_kb_get_mode(const lv_obj_t * kb);175176/**177* Get the current cursor manage mode.178* @param kb pointer to a Keyboard object179* @return true: show cursor on the current text area, false: hide cursor180*/181bool lv_kb_get_cursor_manage(const lv_obj_t * kb);182183/**184* Get the callback to call when the "Ok" button is pressed185* @param kb pointer to Keyboard object186* @return the ok callback187*/188lv_action_t lv_kb_get_ok_action(const lv_obj_t * kb);189190/**191* Get the callback to call when the "Hide" button is pressed192* @param kb pointer to Keyboard object193* @return the close callback194*/195lv_action_t lv_kb_get_hide_action(const lv_obj_t * kb);196197/**198* Get a style of a keyboard199* @param kb pointer to a keyboard object200* @param type which style should be get201* @return style pointer to a style202*/203lv_style_t * lv_kb_get_style(const lv_obj_t *kb, lv_kb_style_t type);204205/**********************206* MACROS207**********************/208209#endif /*USE_LV_KB*/210211#ifdef __cplusplus212} /* extern "C" */213#endif214215#endif /*LV_KB_H*/216217218