/**1* @file lv_btn.h2*3*/45#ifndef LV_BTN_H6#define LV_BTN_H78#ifdef __cplusplus9extern "C" {10#endif1112/*********************13* INCLUDES14*********************/15#ifdef LV_CONF_INCLUDE_SIMPLE16#include "lv_conf.h"17#else18#include "../../lv_conf.h"19#endif2021#if USE_LV_BTN != 02223/*Testing of dependencies*/24#if USE_LV_CONT == 025#error "lv_btn: lv_cont is required. Enable it in lv_conf.h (USE_LV_CONT 1) "26#endif2728#include "lv_cont.h"29#include "../lv_core/lv_indev.h"3031/*********************32* DEFINES33*********************/3435/**********************36* TYPEDEFS37**********************/3839/* Button states40* It can be used not only by buttons but other button-like objects too*/41enum42{43LV_BTN_STATE_REL,44LV_BTN_STATE_PR,45LV_BTN_STATE_TGL_REL,46LV_BTN_STATE_TGL_PR,47LV_BTN_STATE_INA,48LV_BTN_STATE_NUM,49};50typedef uint8_t lv_btn_state_t;5152enum53{54LV_BTN_ACTION_CLICK,55LV_BTN_ACTION_PR,56LV_BTN_ACTION_LONG_PR,57LV_BTN_ACTION_LONG_PR_REPEAT,58LV_BTN_ACTION_NUM,59};60typedef uint8_t lv_btn_action_t;616263/*Data of button*/64typedef struct65{66lv_cont_ext_t cont; /*Ext. of ancestor*/67/*New data for this type */68lv_action_t actions[LV_BTN_ACTION_NUM];69lv_style_t * styles[LV_BTN_STATE_NUM]; /*Styles in each state*/70lv_btn_state_t state; /*Current state of the button from 'lv_btn_state_t' enum*/71int idx;72#if LV_BTN_INK_EFFECT73uint16_t ink_in_time; /*[ms] Time of ink fill effect (0: disable ink effect)*/74uint16_t ink_wait_time; /*[ms] Wait before the ink disappears */75uint16_t ink_out_time; /*[ms] Time of ink disappearing*/76#endif77uint8_t toggle :1; /*1: Toggle enabled*/78uint8_t long_pr_action_executed :1; /*1: Long press action executed (Handled by the library)*/79} lv_btn_ext_t;8081/*Styles*/82enum {83LV_BTN_STYLE_REL,84LV_BTN_STYLE_PR,85LV_BTN_STYLE_TGL_REL,86LV_BTN_STYLE_TGL_PR,87LV_BTN_STYLE_INA,88};89typedef uint8_t lv_btn_style_t;9091/**********************92* GLOBAL PROTOTYPES93**********************/9495/**96* Create a button objects97* @param par pointer to an object, it will be the parent of the new button98* @param copy pointer to a button object, if not NULL then the new object will be copied from it99* @return pointer to the created button100*/101lv_obj_t * lv_btn_create(lv_obj_t * par, const lv_obj_t * copy);102103/*=====================104* Setter functions105*====================*/106107/**108* Enable the toggled states. On release the button will change from/to toggled state.109* @param btn pointer to a button object110* @param tgl true: enable toggled states, false: disable111*/112void lv_btn_set_toggle(lv_obj_t * btn, bool tgl);113114/**115* Set the state of the button116* @param btn pointer to a button object117* @param state the new state of the button (from lv_btn_state_t enum)118*/119void lv_btn_set_state(lv_obj_t * btn, lv_btn_state_t state);120121/**122* Toggle the state of the button (ON->OFF, OFF->ON)123* @param btn pointer to a button object124*/125void lv_btn_toggle(lv_obj_t * btn);126127/**128* Set a function to call when a button event happens129* @param btn pointer to a button object130* @param action type of event form 'lv_action_t' (press, release, long press, long press repeat)131*/132void lv_btn_set_action(lv_obj_t * btn, lv_btn_action_t type, lv_action_t action);133134/**135* Set the layout on a button136* @param btn pointer to a button object137* @param layout a layout from 'lv_cont_layout_t'138*/139static inline void lv_btn_set_layout(lv_obj_t * btn, lv_layout_t layout)140{141lv_cont_set_layout(btn, layout);142}143144/**145* Enable the horizontal or vertical fit.146* The button size will be set to involve the children horizontally or vertically.147* @param btn pointer to a button object148* @param hor_en true: enable the horizontal fit149* @param ver_en true: enable the vertical fit150*/151static inline void lv_btn_set_fit(lv_obj_t * btn, bool hor_en, bool ver_en)152{153lv_cont_set_fit(btn, hor_en, ver_en);154}155156/**157* Set time of the ink effect (draw a circle on click to animate in the new state)158* @param btn pointer to a button object159* @param time the time of the ink animation160*/161void lv_btn_set_ink_in_time(lv_obj_t * btn, uint16_t time);162163/**164* Set the wait time before the ink disappears165* @param btn pointer to a button object166* @param time the time of the ink animation167*/168void lv_btn_set_ink_wait_time(lv_obj_t * btn, uint16_t time);169170/**171* Set time of the ink out effect (animate to the released state)172* @param btn pointer to a button object173* @param time the time of the ink animation174*/175void lv_btn_set_ink_out_time(lv_obj_t * btn, uint16_t time);176177/**178* Set a style of a button.179* @param btn pointer to button object180* @param type which style should be set181* @param style pointer to a style182* */183void lv_btn_set_style(lv_obj_t * btn, lv_btn_style_t type, lv_style_t *style);184185/*=====================186* Getter functions187*====================*/188189/**190* Get the current state of the button191* @param btn pointer to a button object192* @return the state of the button (from lv_btn_state_t enum)193*/194lv_btn_state_t lv_btn_get_state(const lv_obj_t * btn);195196/**197* Get the toggle enable attribute of the button198* @param btn pointer to a button object199* @return ture: toggle enabled, false: disabled200*/201bool lv_btn_get_toggle(const lv_obj_t * btn);202203/**204* Get the release action of a button205* @param btn pointer to a button object206* @return pointer to the release action function207*/208lv_action_t lv_btn_get_action(const lv_obj_t * btn, lv_btn_action_t type);209210/**211* Get the layout of a button212* @param btn pointer to button object213* @return the layout from 'lv_cont_layout_t'214*/215static inline lv_layout_t lv_btn_get_layout(const lv_obj_t * btn)216{217return lv_cont_get_layout(btn);218}219220/**221* Get horizontal fit enable attribute of a button222* @param btn pointer to a button object223* @return true: horizontal fit is enabled; false: disabled224*/225static inline bool lv_btn_get_hor_fit(const lv_obj_t * btn)226{227return lv_cont_get_hor_fit(btn);228}229230/**231* Get vertical fit enable attribute of a container232* @param btn pointer to a button object233* @return true: vertical fit is enabled; false: disabled234*/235static inline bool lv_btn_get_ver_fit(const lv_obj_t * btn)236{237return lv_cont_get_ver_fit(btn);238}239240/**241* Get time of the ink in effect (draw a circle on click to animate in the new state)242* @param btn pointer to a button object243* @return the time of the ink animation244*/245uint16_t lv_btn_get_ink_in_time(const lv_obj_t * btn);246247/**248* Get the wait time before the ink disappears249* @param btn pointer to a button object250* @return the time of the ink animation251*/252uint16_t lv_btn_get_ink_wait_time(const lv_obj_t * btn);253254/**255* Get time of the ink out effect (animate to the releases state)256* @param btn pointer to a button object257* @return the time of the ink animation258*/259uint16_t lv_btn_get_ink_out_time(const lv_obj_t * btn);260261/**262* Get style of a button.263* @param btn pointer to button object264* @param type which style should be get265* @return style pointer to the style266* */267lv_style_t * lv_btn_get_style(const lv_obj_t * btn, lv_btn_style_t type);268269/**********************270* MACROS271**********************/272273#endif /*USE_LV_BUTTON*/274275#ifdef __cplusplus276} /* extern "C" */277#endif278279#endif /*LV_BTN_H*/280281282