2016-09-30 13:35:54 +02:00
|
|
|
/**
|
|
|
|
* @file lv_btnm.h
|
2018-06-19 09:49:58 +02:00
|
|
|
*
|
2016-09-30 13:35:54 +02:00
|
|
|
*/
|
|
|
|
|
2020-02-14 12:36:44 +01:00
|
|
|
#ifndef LV_BTNMATRIX_H
|
|
|
|
#define LV_BTNMATRIX_H
|
2016-09-30 13:35:54 +02:00
|
|
|
|
2017-07-09 15:32:49 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2016-09-30 13:35:54 +02:00
|
|
|
/*********************
|
|
|
|
* INCLUDES
|
|
|
|
*********************/
|
2019-12-26 02:49:30 +01:00
|
|
|
#include "../lv_conf_internal.h"
|
2018-07-07 11:53:22 +02:00
|
|
|
|
2020-02-14 12:36:44 +01:00
|
|
|
#if LV_USE_BTNMATRIX != 0
|
2016-09-30 13:35:54 +02:00
|
|
|
|
2017-11-30 11:35:33 +01:00
|
|
|
#include "../lv_core/lv_obj.h"
|
2016-09-30 13:35:54 +02:00
|
|
|
#include "lv_label.h"
|
|
|
|
#include "lv_btn.h"
|
|
|
|
|
|
|
|
/*********************
|
|
|
|
* DEFINES
|
|
|
|
*********************/
|
2020-02-14 12:36:44 +01:00
|
|
|
#define LV_BTNMATRIX_BTN_NONE 0xFFFF
|
|
|
|
LV_EXPORT_CONST_INT(LV_BTNMATRIX_BTN_NONE);
|
2019-10-03 23:20:50 +03:00
|
|
|
|
2016-09-30 13:35:54 +02:00
|
|
|
/**********************
|
|
|
|
* TYPEDEFS
|
|
|
|
**********************/
|
|
|
|
|
2019-12-31 06:10:50 +01:00
|
|
|
/** Type to store button control bits (disabled, hidden etc.)
|
|
|
|
* The first 3 bits are used to store the width */
|
2019-03-19 06:30:05 +01:00
|
|
|
enum {
|
2021-02-04 14:46:11 +01:00
|
|
|
_LV_BTNMATRIX_WIDTH = 0x0007, /**< Reserved to stire the size units */
|
2020-02-14 12:36:44 +01:00
|
|
|
LV_BTNMATRIX_CTRL_HIDDEN = 0x0008, /**< Button hidden */
|
|
|
|
LV_BTNMATRIX_CTRL_NO_REPEAT = 0x0010, /**< Do not repeat press this button. */
|
2020-03-04 16:29:21 +01:00
|
|
|
LV_BTNMATRIX_CTRL_DISABLED = 0x0020, /**< Disable this button. */
|
2020-02-14 12:36:44 +01:00
|
|
|
LV_BTNMATRIX_CTRL_CHECKABLE = 0x0040, /**< Button *can* be toggled. */
|
2020-09-16 11:26:06 +02:00
|
|
|
LV_BTNMATRIX_CTRL_CHECKED = 0x0080, /**< Button is currently toggled (e.g. checked). */
|
|
|
|
LV_BTNMATRIX_CTRL_CLICK_TRIG = 0x0100, /**< 1: Send LV_EVENT_VALUE_CHANGE on CLICK, 0: Send LV_EVENT_VALUE_CHANGE on PRESS*/
|
2021-02-04 14:46:11 +01:00
|
|
|
LV_BTNMATRIX_CTRL_CUSTOM_1 = 0x1000, /**< Custom free to use flag */
|
|
|
|
LV_BTNMATRIX_CTRL_CUSTOM_2 = 0x2000, /**< Custom free to use flag */
|
|
|
|
LV_BTNMATRIX_CTRL_CUSTOM_3 = 0x4000, /**< Custom free to use flag */
|
|
|
|
LV_BTNMATRIX_CTRL_CUSTOM_4 = 0x8000, /**< Custom free to use flag */
|
2019-03-19 06:30:05 +01:00
|
|
|
};
|
2021-02-04 14:46:11 +01:00
|
|
|
|
2020-02-14 12:36:44 +01:00
|
|
|
typedef uint16_t lv_btnmatrix_ctrl_t;
|
2019-02-12 16:55:30 +08:00
|
|
|
|
2021-01-21 15:18:20 +01:00
|
|
|
typedef bool (*lv_btnmatrix_btn_draw_cb_t)(lv_obj_t * btnm, uint32_t btn_id, const lv_area_t * draw_area, const lv_area_t * clip_area);
|
2021-01-05 13:01:07 +01:00
|
|
|
|
2017-01-14 23:54:16 +01:00
|
|
|
/*Data of button matrix*/
|
2020-02-26 19:48:27 +01:00
|
|
|
typedef struct {
|
2021-01-08 21:30:14 +01:00
|
|
|
lv_obj_t obj;
|
2019-06-27 07:16:15 +02:00
|
|
|
const char ** map_p; /*Pointer to the current map*/
|
|
|
|
lv_area_t * button_areas; /*Array of areas of buttons*/
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_btnmatrix_ctrl_t * ctrl_bits; /*Array of control bytes*/
|
2019-06-27 07:16:15 +02:00
|
|
|
uint16_t btn_cnt; /*Number of button in 'map_p'(Handled by the library)*/
|
2021-02-24 09:55:47 +01:00
|
|
|
uint16_t btn_id_sel; /*Index of the active button (being pressed/released etc) or LV_BTNMATRIX_BTN_NONE */
|
2019-04-04 07:15:40 +02:00
|
|
|
uint8_t recolor : 1; /*Enable button recoloring*/
|
2020-03-04 16:29:21 +01:00
|
|
|
uint8_t one_check : 1; /*Single button toggled at once*/
|
2021-01-08 21:30:14 +01:00
|
|
|
} lv_btnmatrix_t;
|
2017-01-14 23:54:16 +01:00
|
|
|
|
2021-01-05 13:01:07 +01:00
|
|
|
|
2021-02-07 22:39:54 +01:00
|
|
|
extern const lv_obj_class_t lv_btnmatrix_class;
|
2017-11-15 15:50:33 +01:00
|
|
|
|
2016-09-30 13:35:54 +02:00
|
|
|
/**********************
|
|
|
|
* GLOBAL PROTOTYPES
|
|
|
|
**********************/
|
2017-01-13 23:27:49 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a button matrix objects
|
2021-02-01 14:55:08 +01:00
|
|
|
* @param parent pointer to an object, it will be the parent of the new button matrix
|
|
|
|
* @param copy DEPRECATED, will be removed in v9.
|
|
|
|
* Pointer to an other button matrix to copy.
|
|
|
|
* @return pointer to the created button matrix
|
2017-01-13 23:27:49 +01:00
|
|
|
*/
|
2021-02-01 14:55:08 +01:00
|
|
|
lv_obj_t * lv_btnmatrix_create(lv_obj_t * parent, const lv_obj_t * copy);
|
2017-01-13 23:27:49 +01:00
|
|
|
|
2017-11-10 15:01:40 +01:00
|
|
|
/*=====================
|
|
|
|
* Setter functions
|
|
|
|
*====================*/
|
2016-09-30 13:35:54 +02:00
|
|
|
|
2017-01-13 23:27:49 +01:00
|
|
|
/**
|
2019-03-11 06:18:44 +01:00
|
|
|
* Set a new map. Buttons will be created/deleted according to the map. The
|
|
|
|
* button matrix keeps a reference to the map and so the string array must not
|
|
|
|
* be deallocated during the life of the matrix.
|
2021-02-01 14:55:08 +01:00
|
|
|
* @param obj pointer to a button matrix object
|
|
|
|
* @param map pointer a string array. The last string has to be: "". Use "\n" to make a line break.
|
2017-01-13 23:27:49 +01:00
|
|
|
*/
|
2021-02-01 14:55:08 +01:00
|
|
|
void lv_btnmatrix_set_map(lv_obj_t * obj, const char * map[]);
|
2017-01-13 23:27:49 +01:00
|
|
|
|
2019-02-19 14:56:45 +08:00
|
|
|
/**
|
2021-02-01 14:55:08 +01:00
|
|
|
* Set the button control map (hidden, disabled etc.) for a button matrix.
|
|
|
|
* The control map array will be copied and so may be deallocated after this
|
2019-02-19 14:56:45 +08:00
|
|
|
* function returns.
|
2021-02-01 14:55:08 +01:00
|
|
|
* @param obj pointer to a button matrix object
|
|
|
|
* @param ctrl_map pointer to an array of `lv_btn_ctrl_t` control bytes. The
|
|
|
|
* length of the array and position of the elements must match
|
|
|
|
* the number and order of the individual buttons (i.e. excludes
|
|
|
|
* newline entries).
|
|
|
|
* An element of the map should look like e.g.:
|
2020-02-14 12:36:44 +01:00
|
|
|
* `ctrl_map[0] = width | LV_BTNMATRIX_CTRL_NO_REPEAT | LV_BTNMATRIX_CTRL_TGL_ENABLE`
|
2019-02-19 14:56:45 +08:00
|
|
|
*/
|
2021-02-01 14:55:08 +01:00
|
|
|
void lv_btnmatrix_set_ctrl_map(lv_obj_t * obj, const lv_btnmatrix_ctrl_t ctrl_map[]);
|
2019-02-19 14:56:45 +08:00
|
|
|
|
2018-12-15 21:44:44 -05:00
|
|
|
/**
|
2021-02-01 14:55:08 +01:00
|
|
|
* Enable recoloring of button's texts. E.g. "a #ff0000 red# word"
|
|
|
|
* @param obj pointer to button matrix object
|
|
|
|
* @param en true: enable recoloring; false: disable
|
2018-12-15 21:44:44 -05:00
|
|
|
*/
|
2021-02-01 14:55:08 +01:00
|
|
|
void lv_btnmatrix_set_recolor(const lv_obj_t * obj, bool en);
|
2019-02-12 16:55:30 +08:00
|
|
|
/**
|
2019-06-17 16:05:30 +02:00
|
|
|
* Set the attributes of a button of the button matrix
|
2021-02-01 14:55:08 +01:00
|
|
|
* @param obj pointer to button matrix object
|
|
|
|
* @param btn_id 0 based index of the button to modify. (Not counting new lines)
|
|
|
|
* @param ctrl OR-ed attributs. E.g. `LV_BTNMATRIX_CTRL_NO_REPEAT | LV_BTNMATRIX_CTRL_CHECKABLE`
|
2019-06-17 16:05:30 +02:00
|
|
|
*/
|
2021-02-01 14:55:08 +01:00
|
|
|
void lv_btnmatrix_set_btn_ctrl(lv_obj_t * obj, uint16_t btn_id, lv_btnmatrix_ctrl_t ctrl);
|
2019-06-17 16:05:30 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Clear the attributes of a button of the button matrix
|
2021-02-01 14:55:08 +01:00
|
|
|
* @param obj pointer to button matrix object
|
|
|
|
* @param btn_id 0 based index of the button to modify. (Not counting new lines)
|
|
|
|
* @param ctrl OR-ed attributs. E.g. `LV_BTNMATRIX_CTRL_NO_REPEAT | LV_BTNMATRIX_CTRL_CHECKABLE`
|
2019-02-12 16:55:30 +08:00
|
|
|
*/
|
2021-02-01 14:55:08 +01:00
|
|
|
void lv_btnmatrix_clear_btn_ctrl(const lv_obj_t * obj, uint16_t btn_id, lv_btnmatrix_ctrl_t ctrl);
|
2019-02-12 16:55:30 +08:00
|
|
|
|
|
|
|
/**
|
2021-02-01 14:55:08 +01:00
|
|
|
* Set attributes of all buttons of a button matrix
|
|
|
|
* @param obj pointer to a button matrix object
|
|
|
|
* @param ctrl attribute(s) to set from `lv_btnmatrix_ctrl_t`. Values can be ORed.
|
2019-06-17 16:05:30 +02:00
|
|
|
*/
|
2021-02-01 14:55:08 +01:00
|
|
|
void lv_btnmatrix_set_btn_ctrl_all(lv_obj_t * obj, lv_btnmatrix_ctrl_t ctrl);
|
2019-06-17 16:05:30 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Clear the attributes of all buttons of a button matrix
|
2021-02-01 14:55:08 +01:00
|
|
|
* @param obj pointer to a button matrix object
|
|
|
|
* @param ctrl attribute(s) to set from `lv_btnmatrix_ctrl_t`. Values can be ORed.
|
|
|
|
* @param en true: set the attributes; false: clear the attributes
|
2019-02-12 16:55:30 +08:00
|
|
|
*/
|
2021-02-01 14:55:08 +01:00
|
|
|
void lv_btnmatrix_clear_btn_ctrl_all(lv_obj_t * obj, lv_btnmatrix_ctrl_t ctrl);
|
2019-02-12 16:55:30 +08:00
|
|
|
|
|
|
|
/**
|
2021-02-01 14:55:08 +01:00
|
|
|
* Set a single button's relative width.
|
2019-02-12 16:55:30 +08:00
|
|
|
* This method will cause the matrix be regenerated and is a relatively
|
|
|
|
* expensive operation. It is recommended that initial width be specified using
|
2020-02-14 12:36:44 +01:00
|
|
|
* `lv_btnmatrix_set_ctrl_map` and this method only be used for dynamic changes.
|
2021-02-01 14:55:08 +01:00
|
|
|
* @param obj pointer to button matrix object
|
|
|
|
* @param btn_id 0 based index of the button to modify.
|
|
|
|
* @param width relative width compared to the buttons in the same row. [1..7]
|
2019-02-12 16:55:30 +08:00
|
|
|
*/
|
2021-02-01 14:55:08 +01:00
|
|
|
void lv_btnmatrix_set_btn_width(lv_obj_t * obj, uint16_t btn_id, uint8_t width);
|
2019-02-12 16:55:30 +08:00
|
|
|
|
2019-03-20 18:33:33 -04:00
|
|
|
/**
|
2020-09-16 11:26:06 +02:00
|
|
|
* Make the button matrix like a selector widget (only one button may be checked at a time).
|
2021-02-01 14:55:08 +01:00
|
|
|
* `LV_BTNMATRIX_CTRL_CHECKABLE` must be enabled on the buttons to be selected useing
|
|
|
|
* `lv_btnmatrix_set_ctrl()` or `lv_btnmatrix_set_btn_ctrl_all()`.
|
|
|
|
* @param obj pointer to a button matrix object
|
|
|
|
* @param en: whether "one check" mode is enabled
|
2019-03-20 18:33:33 -04:00
|
|
|
*/
|
2021-02-01 14:55:08 +01:00
|
|
|
void lv_btnmatrix_set_one_checked(lv_obj_t * obj, bool en);
|
2020-07-07 09:36:59 +02:00
|
|
|
|
2017-11-10 15:01:40 +01:00
|
|
|
/*=====================
|
|
|
|
* Getter functions
|
|
|
|
*====================*/
|
|
|
|
|
2017-01-13 23:27:49 +01:00
|
|
|
/**
|
|
|
|
* Get the current map of a button matrix
|
2021-02-01 14:55:08 +01:00
|
|
|
* @param obj pointer to a button matrix object
|
|
|
|
* @return the current map
|
2017-01-13 23:27:49 +01:00
|
|
|
*/
|
2021-02-01 14:55:08 +01:00
|
|
|
const char ** lv_btnmatrix_get_map(const lv_obj_t * obj);
|
2017-01-13 23:27:49 +01:00
|
|
|
|
|
|
|
/**
|
2019-03-11 06:18:44 +01:00
|
|
|
* Check whether the button's text can use recolor or not
|
2021-02-01 14:55:08 +01:00
|
|
|
* @param obj pointer to button matrix object
|
|
|
|
* @return true: text recolor enable; false: disabled
|
2017-01-13 23:27:49 +01:00
|
|
|
*/
|
2021-02-01 14:55:08 +01:00
|
|
|
bool lv_btnmatrix_get_recolor(const lv_obj_t * obj);
|
2017-01-13 23:27:49 +01:00
|
|
|
|
2018-11-19 07:00:17 +01:00
|
|
|
/**
|
2021-02-24 05:10:48 +01:00
|
|
|
* Get the index of the lastly "activated" button by the user (pressed, released, focused etc)
|
2021-02-01 14:55:08 +01:00
|
|
|
* Useful in the the `event_cb` to get the text of the button, check if hidden etc.
|
|
|
|
* @param obj pointer to button matrix object
|
|
|
|
* @return index of the last released button (LV_BTNMATRIX_BTN_NONE: if unset)
|
2018-11-19 07:00:17 +01:00
|
|
|
*/
|
2021-02-24 09:55:47 +01:00
|
|
|
uint16_t lv_btnmatrix_get_selected_btn(const lv_obj_t * obj);
|
2017-11-15 15:50:33 +01:00
|
|
|
|
2017-11-10 15:01:40 +01:00
|
|
|
/**
|
2019-03-11 06:18:44 +01:00
|
|
|
* Get the button's text
|
2021-02-01 14:55:08 +01:00
|
|
|
* @param obj pointer to button matrix object
|
|
|
|
* @param btn_id the index a button not counting new line characters.
|
|
|
|
* @return text of btn_index` button
|
2019-03-11 06:18:44 +01:00
|
|
|
*/
|
2021-02-01 14:55:08 +01:00
|
|
|
const char * lv_btnmatrix_get_btn_text(const lv_obj_t * obj, uint16_t btn_id);
|
2019-03-11 06:18:44 +01:00
|
|
|
|
|
|
|
/**
|
2019-03-19 06:30:05 +01:00
|
|
|
* Get the whether a control value is enabled or disabled for button of a button matrix
|
2021-02-01 14:55:08 +01:00
|
|
|
* @param obj pointer to a button matrix object
|
|
|
|
* @param btn_id the index of a button not counting new line characters.
|
|
|
|
* @param ctrl control values to check (ORed value can be used)
|
|
|
|
* @return true: the control attribute is enabled false: disabled
|
2019-03-11 06:18:44 +01:00
|
|
|
*/
|
2021-02-01 14:55:08 +01:00
|
|
|
bool lv_btnmatrix_has_btn_ctrl(lv_obj_t * obj, uint16_t btn_id, lv_btnmatrix_ctrl_t ctrl);
|
2019-03-11 06:18:44 +01:00
|
|
|
|
2019-03-20 18:33:33 -04:00
|
|
|
/**
|
2021-02-01 14:55:08 +01:00
|
|
|
* Tell whether "one check" mode is enabled or not.
|
|
|
|
* @param obj Button matrix object
|
|
|
|
* @return true: "one check" mode is enabled; false: disabled
|
2019-03-20 18:33:33 -04:00
|
|
|
*/
|
2021-02-01 14:55:08 +01:00
|
|
|
bool lv_btnmatrix_get_one_checked(const lv_obj_t * obj);
|
2020-07-07 09:36:59 +02:00
|
|
|
|
|
|
|
|
2016-09-30 13:35:54 +02:00
|
|
|
/**********************
|
|
|
|
* MACROS
|
|
|
|
**********************/
|
|
|
|
|
2020-02-14 12:36:44 +01:00
|
|
|
#endif /*LV_USE_BTNMATRIX*/
|
2016-09-30 13:35:54 +02:00
|
|
|
|
2017-07-09 15:32:49 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
} /* extern "C" */
|
|
|
|
#endif
|
|
|
|
|
2020-02-14 12:36:44 +01:00
|
|
|
#endif /*LV_BTNMATRIX_H*/
|