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

174 lines
4.2 KiB
C
Raw Normal View History

2016-06-08 07:25:08 +02:00
/**
* @file lv_btn.h
*
*/
#ifndef LV_BTN_H
#define LV_BTN_H
/*********************
* INCLUDES
*********************/
#include "lv_conf.h"
2016-06-08 07:25:08 +02:00
#if USE_LV_BTN != 0
2017-01-02 10:48:21 +01:00
/*Testing of dependencies*/
#if USE_LV_RECT == 0
#error "lv_btn: lv_rect is required. Enable it in lv_conf.h (USE_LV_RECT 1) "
#endif
2016-06-08 07:25:08 +02:00
#include "lv_rect.h"
#include "../lv_obj/lv_dispi.h"
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
typedef enum
{
2016-06-15 09:38:20 +02:00
LV_BTN_STATE_PR,
LV_BTN_STATE_REL,
LV_BTN_STATE_TGL_PR,
LV_BTN_STATE_TGL_REL,
LV_BTN_STATE_INA,
LV_BTN_STATE_NUM,
2016-06-08 07:25:08 +02:00
}lv_btn_state_t;
2016-12-17 10:50:28 +01:00
typedef struct
{
uint8_t light_en :1;
uint8_t transp :1;
uint8_t empty :1;
}lv_btns_bits_t;
2016-10-07 11:15:46 +02:00
/*Style of button*/
2016-06-08 07:25:08 +02:00
typedef struct
{
2016-10-07 11:15:46 +02:00
lv_rects_t rects; /*Style of ancestor*/
/*New style element for this type */
2016-06-15 09:38:20 +02:00
color_t mcolor[LV_BTN_STATE_NUM];
color_t gcolor[LV_BTN_STATE_NUM];
color_t bcolor[LV_BTN_STATE_NUM];
color_t lcolor[LV_BTN_STATE_NUM];
2016-12-17 10:50:28 +01:00
lv_btns_bits_t flags[LV_BTN_STATE_NUM];
2016-06-08 07:25:08 +02:00
}lv_btns_t;
2016-10-07 11:15:46 +02:00
/*Built-in styles of button*/
2016-06-08 07:25:08 +02:00
typedef enum
{
LV_BTNS_DEF,
LV_BTNS_TRANSP,
LV_BTNS_BORDER,
}lv_btns_builtin_t;
2016-10-07 11:15:46 +02:00
/*Data of button*/
2016-06-08 07:25:08 +02:00
typedef struct
{
2016-10-07 11:15:46 +02:00
lv_rect_ext_t rect_ext; /*Ext. of ancestor*/
/*New data for this type */
lv_action_t pr_action;
lv_action_t rel_action;
lv_action_t lpr_action;
lv_action_t lpr_rep_action;
2016-06-08 07:25:08 +02:00
lv_btn_state_t state;
uint8_t tgl :1; /*1: Toggle enabled*/
uint8_t lpr_exec :1; /*1: long press action executed (Not for user)*/
}lv_btn_ext_t;
/**********************
* 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
*/
2016-10-07 11:15:46 +02:00
void lv_btn_set_tgl(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_pr_action(lv_obj_t * btn, lv_action_t pr_action);
/**
* Set a function to call when the button is released
* @param btn pointer to a button object
* @param rel_action pointer to functionREL
*/
void lv_btn_set_rel_action(lv_obj_t * btn, lv_action_t rel_action);
/**
* Set a function to call when the button is long pressed
* @param btn pointer to a button object
* @param lpr_action pointer to function
*/
void lv_btn_set_lpr_action(lv_obj_t * btn, lv_action_t lpr_action);
/**
* Set a function to called periodically after long press.
* @param btn pointer to a button object
* @param lpr_rep_action pointer to function
*/
void lv_btn_set_lpr_rep_action(lv_obj_t * btn, lv_action_t lpr_rep_action);
2016-06-08 07:25:08 +02:00
/**
* 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_tgl(lv_obj_t * btn);
/**
* Return with a pointer to a built-in style and/or copy it to a variable
* @param style a style name from lv_btns_builtin_t enum
* @param copy copy the style to this variable. (NULL if unused)
* @return pointer to an lv_btns_t style
*/
lv_btns_t * lv_btns_get(lv_btns_builtin_t style, lv_btns_t * copy);
2016-06-08 07:25:08 +02:00
/**********************
* MACROS
**********************/
#endif
#endif