1
0
mirror of https://github.com/lvgl/lvgl.git synced 2025-01-28 07:03:00 +08:00
lvgl/lv_objx/lv_btn.h

163 lines
4.2 KiB
C
Raw Normal View History

2016-06-08 07:25:08 +02:00
/**
* @file lv_button.h
2016-06-08 07:25:08 +02:00
*
*/
#ifndef lv_btn_H
#define lv_btn_H
2016-06-08 07:25:08 +02:00
2017-07-09 15:32:49 +02:00
#ifdef __cplusplus
extern "C" {
#endif
2016-06-08 07:25:08 +02:00
/*********************
* INCLUDES
*********************/
#include "lv_conf.h"
#if USE_LV_BUTTON != 0
2016-06-08 07:25:08 +02:00
2017-01-02 10:48:21 +01:00
/*Testing of dependencies*/
2017-04-24 16:16:36 +02:00
#if USE_LV_CONT == 0
#error "lv_btn: lv_cont is required. Enable it in lv_conf.h (USE_LV_CONT 1) "
2017-01-02 10:48:21 +01:00
#endif
#include "lv_cont.h"
2017-10-09 15:21:26 +02:00
#include <lvgl/lv_obj/lv_indev.h>
2016-06-08 07:25:08 +02:00
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
2017-04-11 10:50:57 +02:00
/*Button states*/
2016-06-08 07:25:08 +02:00
typedef enum
{
LV_BTN_STATE_OFF_RELEASED,
LV_BTN_STATE_OFF_PRESSED,
LV_BTN_STATE_ON_RELEASED,
LV_BTN_STATE_ON_PRESSED,
LV_BTN_STATE_INACTIVE,
2016-06-15 09:38:20 +02:00
LV_BTN_STATE_NUM,
2016-06-08 07:25:08 +02:00
}lv_btn_state_t;
typedef enum
{
LV_BTN_ACTION_RELEASE,
LV_BTN_ACTION_PRESS,
LV_BTN_ACTION_LONG_PRESS,
LV_BTN_ACTION_LONG_PRESS_REPEATE,
LV_BTN_ACTION_NUM,
}lv_btn_action_t;
/*Data of button*/
2016-12-17 10:50:28 +01:00
typedef struct
{
2017-04-13 16:12:03 +02:00
lv_cont_ext_t cont; /*Ext. of ancestor*/
/*New data for this type */
lv_action_t actions[LV_BTN_ACTION_NUM];
lv_style_t * styles[LV_BTN_STATE_NUM]; /*Styles in each state*/
lv_btn_state_t state; /*Current state of the button from 'lv_btn_state_t' enum*/
uint8_t toggle :1; /*1: Toggle enabled*/
uint8_t long_press_action_executed :1; /*1: Long press action executed (Handled by the library)*/
}lv_btn_ext_t;
2016-06-08 07:25:08 +02:00
/**********************
* GLOBAL PROTOTYPES
**********************/
/**
* Create a button objects
* @param par pointer to an object, it will be the parent of the new button
* @param copy pointer to a button object, if not NULL then the new object will be copied from it
* @return pointer to the created button
*/
2016-10-07 11:15:46 +02:00
lv_obj_t * lv_btn_create(lv_obj_t * par, lv_obj_t * copy);
2016-06-08 07:25:08 +02:00
/**
* Signal function of the button
* @param btn pointer to a button object
* @param sign a signal type from lv_signal_t enum
* @param param pointer to a signal specific variable
*/
2016-10-07 11:15:46 +02:00
bool lv_btn_signal(lv_obj_t * btn, lv_signal_t sign, void * param);
2016-06-08 07:25:08 +02:00
/**
* Enable the toggled states
* @param btn pointer to a button object
* @param tgl true: enable toggled states, false: disable
*/
void lv_btn_set_toggle(lv_obj_t * btn, bool tgl);
/**
* Set the state of the button
* @param btn pointer to a button object
* @param state the new state of the button (from lv_btn_state_t enum)
*/
2016-10-07 11:15:46 +02:00
void lv_btn_set_state(lv_obj_t * btn, lv_btn_state_t state);
/**
* Set a function to call when the button is pressed
* @param btn pointer to a button object
* @param pr_action pointer to function
*/
void lv_btn_set_action(lv_obj_t * btn, lv_btn_action_t type, lv_action_t action);
2016-06-08 07:25:08 +02:00
2017-04-21 09:15:39 +02:00
/**
* Set styles of a button is each state
* @param btn pointer to button object
* @param rel pointer to a style for releases state
* @param pr pointer to a style for pressed state
* @param trel pointer to a style for toggled releases state
* @param tpr pointer to a style for toggled pressed state
* @param ina pointer to a style for inactive state
*/
void lv_btn_set_style(lv_obj_t * btn, lv_btn_state_t state, lv_style_t * style);
void lv_btn_set_style_all(lv_obj_t * btn, lv_style_t ** style_array);
/**
* Get the current state of the button
* @param btn pointer to a button object
* @return the state of the button (from lv_btn_state_t enum)
*/
2016-10-07 11:15:46 +02:00
lv_btn_state_t lv_btn_get_state(lv_obj_t * btn);
2016-06-08 07:25:08 +02:00
/**
* Get the toggle enable attribute of the button
* @param btn pointer to a button object
* @return ture: toggle enabled, false: disabled
*/
bool lv_btn_get_toggle(lv_obj_t * btn);
/**
* Get the release action of a button
* @param btn pointer to a button object
* @return pointer to the release action function
*/
lv_action_t lv_btn_get_action(lv_obj_t * btn, lv_btn_action_t type);
/**
* Get the press action of a button
* @param btn pointer to a button object
* @return pointer to the press action function
*/
lv_action_t lv_btn_get_pr_action(lv_obj_t * btn);
lv_style_t * lv_btn_get_style(lv_obj_t * btn, lv_btn_state_t state);
2017-04-21 09:15:39 +02:00
2016-06-08 07:25:08 +02:00
/**********************
* MACROS
**********************/
#endif /*USE_LV_BUTTON*/
2016-06-08 07:25:08 +02:00
2017-07-09 15:32:49 +02:00
#ifdef __cplusplus
} /* extern "C" */
2016-06-08 07:25:08 +02:00
#endif
2017-07-09 15:32:49 +02:00
#endif /*lv_btn_H*/