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
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef LV_BTNM_H
|
|
|
|
#define LV_BTNM_H
|
|
|
|
|
2017-07-09 15:32:49 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2016-09-30 13:35:54 +02:00
|
|
|
/*********************
|
|
|
|
* INCLUDES
|
|
|
|
*********************/
|
2018-07-07 12:21:36 +02:00
|
|
|
#ifdef LV_CONF_INCLUDE_SIMPLE
|
2018-07-07 11:53:22 +02:00
|
|
|
#include "lv_conf.h"
|
|
|
|
#else
|
2017-11-26 23:57:39 +01:00
|
|
|
#include "../../lv_conf.h"
|
2018-07-07 11:53:22 +02:00
|
|
|
#endif
|
|
|
|
|
2019-03-07 00:05:16 +01:00
|
|
|
#if LV_USE_BTNM != 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
|
|
|
|
*********************/
|
|
|
|
|
2017-10-12 16:59:51 +02:00
|
|
|
/*Control byte*/
|
2019-03-11 06:18:44 +01:00
|
|
|
#define LV_BTNM_WIDTH_MASK 0x07
|
|
|
|
#define LV_BTNM_BTN_HIDDEN 0x08
|
|
|
|
#define LV_BTNM_BTN_NO_REPEAT 0x10
|
|
|
|
#define LV_BTNM_BTN_INACTIVE 0x20
|
|
|
|
#define LV_BTNM_BTN_TOGGLE 0x40
|
|
|
|
#define LV_BTNM_BTN_TOGGLE_STATE 0x80
|
2018-09-26 14:21:39 +02:00
|
|
|
|
2019-03-12 06:20:45 +01:00
|
|
|
#define LV_BTNM_BTN_NONE 0xFFFF
|
2016-09-30 13:35:54 +02:00
|
|
|
/**********************
|
|
|
|
* TYPEDEFS
|
|
|
|
**********************/
|
|
|
|
|
2019-02-12 16:55:30 +08:00
|
|
|
/* Type to store button control bits (disabled, hidden etc.) */
|
2019-02-27 06:17:37 +01:00
|
|
|
typedef uint8_t lv_btnm_ctrl_t;
|
2019-02-12 16:55:30 +08:00
|
|
|
|
2017-01-14 23:54:16 +01:00
|
|
|
/*Data of button matrix*/
|
|
|
|
typedef struct
|
|
|
|
{
|
2017-11-03 13:39:37 +01:00
|
|
|
/*No inherited ext.*/ /*Ext. of ancestor*/
|
2017-01-14 23:54:16 +01:00
|
|
|
/*New data for this type */
|
2018-03-07 11:37:38 +01:00
|
|
|
const char ** map_p; /*Pointer to the current map*/
|
|
|
|
lv_area_t *button_areas; /*Array of areas of buttons*/
|
2019-02-27 06:17:37 +01:00
|
|
|
lv_btnm_ctrl_t *ctrl_bits; /*Array of control bytes*/
|
2017-11-03 13:39:37 +01:00
|
|
|
lv_style_t *styles_btn[LV_BTN_STATE_NUM]; /*Styles of buttons in each state*/
|
2018-03-07 11:37:38 +01:00
|
|
|
uint16_t btn_cnt; /*Number of button in 'map_p'(Handled by the library)*/
|
2019-03-12 06:20:45 +01:00
|
|
|
uint16_t btn_id_pr; /*Index of the currently pressed button or LV_BTNM_BTN_NONE*/
|
|
|
|
uint16_t btn_id_act; /*Index of the active button (being pressed/released etc) or LV_BTNM_BTN_NONE */
|
2018-12-15 21:44:44 -05:00
|
|
|
uint8_t recolor :1; /*Enable button recoloring*/
|
2018-06-19 09:49:58 +02:00
|
|
|
} lv_btnm_ext_t;
|
2017-01-14 23:54:16 +01:00
|
|
|
|
2018-09-18 13:59:40 +02:00
|
|
|
enum {
|
2017-11-15 15:50:33 +01:00
|
|
|
LV_BTNM_STYLE_BG,
|
|
|
|
LV_BTNM_STYLE_BTN_REL,
|
|
|
|
LV_BTNM_STYLE_BTN_PR,
|
|
|
|
LV_BTNM_STYLE_BTN_TGL_REL,
|
|
|
|
LV_BTNM_STYLE_BTN_TGL_PR,
|
|
|
|
LV_BTNM_STYLE_BTN_INA,
|
2018-09-18 13:59:40 +02:00
|
|
|
};
|
|
|
|
typedef uint8_t lv_btnm_style_t;
|
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
|
|
|
|
* @param par pointer to an object, it will be the parent of the new button matrix
|
|
|
|
* @param copy pointer to a button matrix object, if not NULL then the new object will be copied from it
|
|
|
|
* @return pointer to the created button matrix
|
|
|
|
*/
|
2018-07-30 06:52:29 +02:00
|
|
|
lv_obj_t * lv_btnm_create(lv_obj_t * par, 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.
|
2017-01-13 23:27:49 +01:00
|
|
|
* @param btnm pointer to a button matrix object
|
2019-03-11 06:18:44 +01:00
|
|
|
* @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
|
|
|
*/
|
2019-02-19 15:06:23 +08:00
|
|
|
void lv_btnm_set_map(const lv_obj_t * btnm, const char ** map);
|
2017-01-13 23:27:49 +01:00
|
|
|
|
2019-02-19 14:56:45 +08: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
|
|
|
|
* function returns.
|
|
|
|
* @param btnm 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
|
2019-03-11 06:18:44 +01:00
|
|
|
* the number and order of the individual buttons (i.e. excludes
|
|
|
|
* newline entries).
|
2019-02-19 14:56:45 +08:00
|
|
|
* The control bits are:
|
|
|
|
* - bit 5 : 1 = inactive (disabled)
|
|
|
|
* - bit 4 : 1 = no repeat (on long press)
|
|
|
|
* - bit 3 : 1 = hidden
|
|
|
|
* - bit 2..0: Relative width compared to the buttons in the
|
|
|
|
* same row. [1..7]
|
|
|
|
*/
|
2019-02-27 06:17:37 +01:00
|
|
|
void lv_btnm_set_ctrl_map(const lv_obj_t * btnm, const lv_btnm_ctrl_t * ctrl_map);
|
2019-02-19 14:56:45 +08:00
|
|
|
|
2017-01-13 23:27:49 +01:00
|
|
|
/**
|
2019-03-11 06:18:44 +01:00
|
|
|
* Set the pressed button i.e. visually highlight it.
|
|
|
|
* Mainly used a when the btnm is in a group to show the selected button
|
2019-02-28 09:27:25 +01:00
|
|
|
* @param btnm pointer to button matrix object
|
2019-03-12 06:20:45 +01:00
|
|
|
* @param id index of the currently pressed button (`LV_BTNM_BTN_NONE` to unpress)
|
2019-02-28 09:27:25 +01:00
|
|
|
*/
|
|
|
|
void lv_btnm_set_pressed(const lv_obj_t * btnm, uint16_t id);
|
|
|
|
|
2017-11-10 15:01:40 +01:00
|
|
|
/**
|
2017-11-15 15:50:33 +01:00
|
|
|
* Set a style of a button matrix
|
2017-11-10 15:01:40 +01:00
|
|
|
* @param btnm pointer to a button matrix object
|
2017-11-15 15:50:33 +01:00
|
|
|
* @param type which style should be set
|
|
|
|
* @param style pointer to a style
|
2017-04-21 09:15:39 +02:00
|
|
|
*/
|
2019-03-11 06:18:44 +01:00
|
|
|
void lv_btnm_set_style(lv_obj_t * btnm, lv_btnm_style_t type, lv_style_t * style);
|
2017-11-10 15:01:40 +01:00
|
|
|
|
2018-12-15 21:44:44 -05:00
|
|
|
/**
|
2019-03-11 06:18:44 +01:00
|
|
|
* Enable recoloring of button's texts
|
2018-12-15 21:44:44 -05:00
|
|
|
* @param btnm pointer to button matrix object
|
2019-03-11 06:18:44 +01:00
|
|
|
* @param en true: enable recoloring; false: disable
|
2018-12-15 21:44:44 -05:00
|
|
|
*/
|
|
|
|
void lv_btnm_set_recolor(const lv_obj_t * btnm, bool en);
|
|
|
|
|
2019-02-12 16:55:30 +08:00
|
|
|
/**
|
|
|
|
* Show/hide a single button in the matrix
|
|
|
|
* @param btnm pointer to button matrix object
|
2019-02-20 03:32:37 +08:00
|
|
|
* @param btn_idx 0 based index of the button to modify.
|
2019-02-12 16:55:30 +08:00
|
|
|
* @param hidden true: hide the button
|
|
|
|
*/
|
|
|
|
void lv_btnm_set_btn_hidden(const lv_obj_t * btnm, uint16_t btn_idx, bool hidden);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Enable/disable a single button in the matrix
|
|
|
|
* @param btnm pointer to button matrix object
|
2019-03-11 06:18:44 +01:00
|
|
|
* @param btn_id 0 based index of the button to modify.
|
2019-03-12 06:20:45 +01:00
|
|
|
* @param ina true: make the button inactive
|
2019-02-12 16:55:30 +08:00
|
|
|
*/
|
2019-03-12 06:20:45 +01:00
|
|
|
void lv_btnm_set_btn_inactive(const lv_obj_t * btnm, uint16_t btn_id, bool ina);
|
2019-02-12 16:55:30 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Enable/disable long press for a single button in the matrix
|
|
|
|
* @param btnm pointer to button matrix object
|
2019-03-11 06:18:44 +01:00
|
|
|
* @param btn_id 0 based index of the button to modify.
|
2019-03-12 06:20:45 +01:00
|
|
|
* @param no_rep true: disable repeat
|
2019-02-12 16:55:30 +08:00
|
|
|
*/
|
2019-03-12 06:20:45 +01:00
|
|
|
void lv_btnm_set_btn_no_repeat(const lv_obj_t * btnm, uint16_t btn_id, bool no_rep);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Enable/disable toggling a single button in the matrix
|
|
|
|
* @param btnm pointer to button matrix object
|
|
|
|
* @param btn_id 0 based index of the button to modify.
|
|
|
|
* @param tgl true: toggle enable
|
|
|
|
*/
|
|
|
|
void lv_btnm_set_btn_toggle(const lv_obj_t * btnm, uint16_t btn_id, bool tgl);
|
2019-03-11 06:18:44 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Make the a single button button toggled or not toggled.
|
|
|
|
* @param btnm pointer to button matrix object
|
|
|
|
* @param btn_id index of button (not counting "\n")
|
2019-03-12 06:20:45 +01:00
|
|
|
* @param state true: toggled; false: not toggled
|
2019-03-11 06:18:44 +01:00
|
|
|
*/
|
|
|
|
void lv_btnm_set_btn_toggle_state(lv_obj_t * btnm, uint16_t btn_id, bool toggle);
|
2019-02-12 16:55:30 +08:00
|
|
|
|
2019-03-11 06:18:44 +01:00
|
|
|
/**
|
2019-02-12 16:55:30 +08:00
|
|
|
* Set hidden/disabled/repeat flags for a single button.
|
|
|
|
* @param btnm pointer to button matrix object
|
2019-03-12 06:20:45 +01:00
|
|
|
* @param btn_id 0 based index of the button to modify.
|
2019-02-12 16:55:30 +08:00
|
|
|
* @param hidden true: hide the button
|
2019-03-12 06:20:45 +01:00
|
|
|
* @param inactive true: disable the button
|
|
|
|
* @param no_repeat true: disable repeat
|
|
|
|
* @param toggle true: enable toggling
|
|
|
|
* @param toggled_state true: set toggled state
|
2019-02-12 16:55:30 +08:00
|
|
|
*/
|
2019-03-12 06:20:45 +01:00
|
|
|
void lv_btnm_set_btn_flags(const lv_obj_t * btnm, uint16_t btn_id, bool hidden, bool inactive, bool no_repeat, bool toggle, bool toggle_state);
|
2019-02-12 16:55:30 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set a single buttons relative width.
|
|
|
|
* This method will cause the matrix be regenerated and is a relatively
|
|
|
|
* expensive operation. It is recommended that initial width be specified using
|
2019-02-19 14:56:45 +08:00
|
|
|
* `lv_btnm_set_ctrl_map` and this method only be used for dynamic changes.
|
2019-02-12 16:55:30 +08:00
|
|
|
* @param btnm pointer to button matrix object
|
2019-03-11 06:18:44 +01:00
|
|
|
* @param btn_id 0 based index of the button to modify.
|
2019-02-12 16:55:30 +08:00
|
|
|
* @param width Relative width compared to the buttons in the same row. [1..7]
|
|
|
|
*/
|
2019-03-11 06:18:44 +01:00
|
|
|
void lv_btnm_set_btn_width(const lv_obj_t * btnm, uint16_t btn_id, uint8_t width);
|
2019-02-12 16:55:30 +08:00
|
|
|
|
2019-03-12 06:20:45 +01:00
|
|
|
/**
|
|
|
|
* Set the toggle state of all buttons
|
|
|
|
* @param btnm pointer to a button matrix object
|
|
|
|
* @param state true: toggled; false: not toggled
|
|
|
|
*/
|
|
|
|
void lv_btnm_set_btn_toggle_state_all(lv_obj_t * btnm, bool state);
|
2019-02-12 16:55:30 +08: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
|
|
|
|
* @param btnm pointer to a button matrix object
|
|
|
|
* @return the current map
|
|
|
|
*/
|
2018-07-30 06:52:29 +02:00
|
|
|
const char ** lv_btnm_get_map(const lv_obj_t * btnm);
|
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
|
|
|
|
* @param btnm pointer to button matrix object
|
|
|
|
* @return true: text recolor enable; false: disabled
|
2017-01-13 23:27:49 +01:00
|
|
|
*/
|
2019-03-11 06:18:44 +01:00
|
|
|
bool lv_btnm_get_recolor(const lv_obj_t * btnm);
|
2017-01-13 23:27:49 +01:00
|
|
|
|
2018-11-19 07:00:17 +01:00
|
|
|
/**
|
2019-03-11 06:18:44 +01:00
|
|
|
* Get the index of the lastly "activated" button by the user (pressed, released etc)
|
|
|
|
* Useful in the the `event_cb` to get the text of the button, check if hidden etc.
|
2018-11-19 07:00:17 +01:00
|
|
|
* @param btnm pointer to button matrix object
|
2019-03-12 06:20:45 +01:00
|
|
|
* @return index of the last released button (LV_BTNM_BTN_NONE: if unset)
|
2018-11-19 07:00:17 +01:00
|
|
|
*/
|
2019-03-11 06:18:44 +01:00
|
|
|
uint16_t lv_btnm_get_active_btn(const lv_obj_t * btnm);
|
2017-11-15 15:50:33 +01:00
|
|
|
|
2019-03-12 06:20:45 +01:00
|
|
|
/**
|
|
|
|
* Get the text of the lastly "activated" button by the user (pressed, released etc)
|
|
|
|
* Useful in the the `event_cb`
|
|
|
|
* @param btnm pointer to button matrix object
|
|
|
|
* @return text of the last released button (NULL: if unset)
|
|
|
|
*/
|
|
|
|
const char * lv_btnm_get_active_btn_text(const lv_obj_t * btnm);
|
|
|
|
|
2017-11-05 00:48:57 +01:00
|
|
|
/**
|
2019-03-11 06:18:44 +01:00
|
|
|
* Get the pressed button's index.
|
|
|
|
* The button be really pressed by the user or manually set to pressed with `lv_btnm_set_pressed`
|
2017-11-15 15:50:33 +01:00
|
|
|
* @param btnm pointer to button matrix object
|
2019-03-12 06:20:45 +01:00
|
|
|
* @return index of the pressed button (LV_BTNM_BTN_NONE: if unset)
|
2017-11-05 00:48:57 +01:00
|
|
|
*/
|
2019-03-11 06:18:44 +01:00
|
|
|
uint16_t lv_btnm_get_pressed_btn(const lv_obj_t * btnm);
|
2017-04-21 09:15:39 +02:00
|
|
|
|
2017-11-10 15:01:40 +01:00
|
|
|
/**
|
2019-03-11 06:18:44 +01:00
|
|
|
* Get the button's text
|
|
|
|
* @param btnm pointer to button matrix object
|
|
|
|
* @param btn_index the index a button not counting new line characters. (The return value of lv_btnm_get_pressed/released)
|
|
|
|
* @return text of btn_index` button
|
|
|
|
*/
|
2019-03-12 06:20:45 +01:00
|
|
|
const char * lv_btnm_get_btn_text(const lv_obj_t * btnm, uint16_t btn_id);
|
2019-03-11 06:18:44 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Check whether "no repeat" for a button is set or not.
|
|
|
|
* The `LV_EVENT_LONG_PRESS_REPEAT` will be sent anyway but it can be ignored by the user if this function returns `true`
|
2017-11-10 15:01:40 +01:00
|
|
|
* @param btnm pointer to a button matrix object
|
2019-03-11 06:18:44 +01:00
|
|
|
* @param btn_index the index a button not counting new line characters. (The return value of lv_btnm_get_pressed/released)
|
|
|
|
* @return true: long press repeat is disabled; false: long press repeat enabled
|
|
|
|
*/
|
2019-03-12 06:20:45 +01:00
|
|
|
bool lv_btnm_get_btn_no_repeate(lv_obj_t * btnm, uint16_t btn_id);
|
2019-03-11 06:18:44 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Check whether a button for a button is hidden or not.
|
|
|
|
* Events will be sent anyway but they can be ignored by the user if this function returns `true`
|
|
|
|
* @param btnm pointer to a button matrix object
|
|
|
|
* @param btn_id the index a button not counting new line characters. (The return value of lv_btnm_get_pressed/released)
|
|
|
|
* @return true: hidden; false: not hidden
|
2017-11-10 15:01:40 +01:00
|
|
|
*/
|
2019-03-12 06:20:45 +01:00
|
|
|
bool lv_btnm_get_btn_hidden(lv_obj_t * btnm, uint16_t btn_id);
|
2017-11-10 15:01:40 +01:00
|
|
|
|
2018-12-15 21:44:44 -05:00
|
|
|
/**
|
2019-03-11 06:18:44 +01:00
|
|
|
* Check whether a button for a button is inactive or not.
|
|
|
|
* Events will be sent anyway but they can be ignored by the user if this function returns `true`
|
|
|
|
* @param btnm pointer to a button matrix object
|
|
|
|
* @param btn_id the index a button not counting new line characters. (The return value of lv_btnm_get_pressed/released)
|
|
|
|
* @return true: inactive; false: not inactive
|
|
|
|
*/
|
2019-03-12 06:20:45 +01:00
|
|
|
bool lv_btnm_get_btn_inactive(lv_obj_t * btnm, uint16_t btn_id);
|
2019-03-11 06:18:44 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if the button can be toggled or not
|
2018-12-15 21:44:44 -05:00
|
|
|
* @param btnm pointer to button matrix object
|
2019-03-11 06:18:44 +01:00
|
|
|
* @return btn_id index a of a button not counting "\n". (The return value of lv_btnm_get_pressed/released)
|
2018-12-15 21:44:44 -05:00
|
|
|
*/
|
2019-03-12 06:20:45 +01:00
|
|
|
bool lv_btnm_get_btn_toggle(const lv_obj_t * btnm, int16_t btn_id);
|
2018-12-15 21:44:44 -05:00
|
|
|
|
2019-03-11 06:18:44 +01:00
|
|
|
/**
|
|
|
|
* Check if the button is toggled or not
|
|
|
|
* @param btnm pointer to button matrix object
|
|
|
|
* @return btn_id index a of a button not counting "\n". (The return value of lv_btnm_get_pressed/released)
|
|
|
|
*/
|
|
|
|
bool lv_btnm_get_btn_toggle_state(const lv_obj_t * btnm, int16_t btn_id);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a style of a button matrix
|
|
|
|
* @param btnm pointer to a button matrix object
|
|
|
|
* @param type which style should be get
|
|
|
|
* @return style pointer to a style
|
|
|
|
*/
|
|
|
|
lv_style_t * lv_btnm_get_style(const lv_obj_t * btnm, lv_btnm_style_t type);
|
2016-09-30 13:35:54 +02:00
|
|
|
/**********************
|
|
|
|
* MACROS
|
|
|
|
**********************/
|
|
|
|
|
2019-03-07 00:05:16 +01:00
|
|
|
#endif /*LV_USE_BTNM*/
|
2016-09-30 13:35:54 +02:00
|
|
|
|
2017-07-09 15:32:49 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
} /* extern "C" */
|
|
|
|
#endif
|
|
|
|
|
2016-12-18 22:07:03 +01:00
|
|
|
#endif /*LV_BTNM_H*/
|