/**1* @file lv_imgbtn.h2*3*/45#ifndef LV_IMGBTN_H6#define LV_IMGBTN_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_IMGBTN != 02223/*Testing of dependencies*/24#if USE_LV_BTN == 025#error "lv_imgbtn: lv_btn is required. Enable it in lv_conf.h (USE_LV_BTN 1) "26#endif2728#include "../lv_core/lv_obj.h"29#include "lv_btn.h"30#include "../lv_draw/lv_draw_img.h"3132/*********************33* DEFINES34*********************/3536/**********************37* TYPEDEFS38**********************/39/*Data of image button*/40typedef struct {41lv_btn_ext_t btn; /*Ext. of ancestor*/42/*New data for this type */43int idx;44#if LV_IMGBTN_TILED == 045const void * img_src[LV_BTN_STATE_NUM]; /*Store images to each state*/46#else47const void * img_src_left[LV_BTN_STATE_NUM]; /*Store left side images to each state*/48const void * img_src_mid[LV_BTN_STATE_NUM]; /*Store center images to each state*/49const void * img_src_right[LV_BTN_STATE_NUM]; /*Store right side images to each state*/50#endif51lv_img_cf_t act_cf; /*Color format of the currently active image*/52} lv_imgbtn_ext_t;535455/*Styles*/56enum {57LV_IMGBTN_STYLE_REL,58LV_IMGBTN_STYLE_PR,59LV_IMGBTN_STYLE_TGL_REL,60LV_IMGBTN_STYLE_TGL_PR,61LV_IMGBTN_STYLE_INA,62};63typedef uint8_t lv_imgbtn_style_t;646566/**********************67* GLOBAL PROTOTYPES68**********************/6970/**71* Create a image button objects72* @param par pointer to an object, it will be the parent of the new image button73* @param copy pointer to a image button object, if not NULL then the new object will be copied from it74* @return pointer to the created image button75*/76lv_obj_t * lv_imgbtn_create(lv_obj_t * par, const lv_obj_t * copy);7778/*======================79* Add/remove functions80*=====================*/818283/*=====================84* Setter functions85*====================*/8687#if LV_IMGBTN_TILED == 088/**89* Set images for a state of the image button90* @param imgbtn pointer to an image button object91* @param state for which state set the new image (from `lv_btn_state_t`) `92* @param src pointer to an image source (a C array or path to a file)93*/94void lv_imgbtn_set_src(lv_obj_t * imgbtn, lv_btn_state_t state, const void * src);95#else96/**97* Set images for a state of the image button98* @param imgbtn pointer to an image button object99* @param state for which state set the new image (from `lv_btn_state_t`) `100* @param src_left pointer to an image source for the left side of the button (a C array or path to a file)101* @param src_mid pointer to an image source for the middle of the button (ideally 1px wide) (a C array or path to a file)102* @param src_right pointer to an image source for the right side of the button (a C array or path to a file)103*/104void lv_imgbtn_set_src(lv_obj_t * imgbtn, lv_btn_state_t state, const void * src_left, const void * src_mid, const void * src_right);105106#endif107108/**109* Enable the toggled states. On release the button will change from/to toggled state.110* @param imgbtn pointer to an image button object111* @param tgl true: enable toggled states, false: disable112*/113static inline void lv_imgbtn_set_toggle(lv_obj_t * imgbtn, bool tgl)114{115lv_btn_set_toggle(imgbtn, tgl);116}117118/**119* Set the state of the image button120* @param imgbtn pointer to an image button object121* @param state the new state of the button (from lv_btn_state_t enum)122*/123static inline void lv_imgbtn_set_state(lv_obj_t * imgbtn, lv_btn_state_t state)124{125lv_btn_set_state(imgbtn, state);126}127128/**129* Toggle the state of the image button (ON->OFF, OFF->ON)130* @param imgbtn pointer to a image button object131*/132static inline void lv_imgbtn_toggle(lv_obj_t * imgbtn)133{134lv_btn_toggle(imgbtn);135}136137/**138* Set a function to call when a button event happens139* @param imgbtn pointer to an image button object140* @param action type of event form 'lv_action_t' (press, release, long press, long press repeat)141*/142static inline void lv_imgbtn_set_action(lv_obj_t * imgbtn, lv_btn_action_t type, lv_action_t action)143{144lv_btn_set_action(imgbtn, type, action);145}146147/**148* Set a style of a image button.149* @param imgbtn pointer to image button object150* @param type which style should be set151* @param style pointer to a style152*/153void lv_imgbtn_set_style(lv_obj_t * imgbtn, lv_imgbtn_style_t type, lv_style_t *style);154155/*=====================156* Getter functions157*====================*/158159160#if LV_IMGBTN_TILED == 0161/**162* Get the images in a given state163* @param imgbtn pointer to an image button object164* @param state the state where to get the image (from `lv_btn_state_t`) `165* @return pointer to an image source (a C array or path to a file)166*/167const void * lv_imgbtn_get_src(lv_obj_t * imgbtn, lv_btn_state_t state);168169#else170171/**172* Get the left image in a given state173* @param imgbtn pointer to an image button object174* @param state the state where to get the image (from `lv_btn_state_t`) `175* @return pointer to the left image source (a C array or path to a file)176*/177const void * lv_imgbtn_get_src_left(lv_obj_t * imgbtn, lv_btn_state_t state);178179/**180* Get the middle image in a given state181* @param imgbtn pointer to an image button object182* @param state the state where to get the image (from `lv_btn_state_t`) `183* @return pointer to the middle image source (a C array or path to a file)184*/185const void * lv_imgbtn_get_src_middle(lv_obj_t * imgbtn, lv_btn_state_t state);186187/**188* Get the right image in a given state189* @param imgbtn pointer to an image button object190* @param state the state where to get the image (from `lv_btn_state_t`) `191* @return pointer to the left image source (a C array or path to a file)192*/193const void * lv_imgbtn_get_src_right(lv_obj_t * imgbtn, lv_btn_state_t state);194195#endif196/**197* Get the current state of the image button198* @param imgbtn pointer to a image button object199* @return the state of the button (from lv_btn_state_t enum)200*/201static inline lv_btn_state_t lv_imgbtn_get_state(const lv_obj_t * imgbtn)202{203return lv_btn_get_state(imgbtn);204}205206/**207* Get the toggle enable attribute of the image button208* @param imgbtn pointer to a image button object209* @return ture: toggle enabled, false: disabled210*/211static inline bool lv_imgbtn_get_toggle(const lv_obj_t * imgbtn)212{213return lv_btn_get_toggle(imgbtn);214}215216/**217* Get the release action of a image button218* @param imgbtn pointer to a image button object219* @return pointer to the release action function220*/221static inline lv_action_t lv_imgbtn_get_action(const lv_obj_t * imgbtn, lv_btn_action_t type)222{223return lv_btn_get_action(imgbtn, type);224}225226/**227* Get style of a image button.228* @param imgbtn pointer to image button object229* @param type which style should be get230* @return style pointer to the style231*/232lv_style_t * lv_imgbtn_get_style(const lv_obj_t * imgbtn, lv_imgbtn_style_t type);233234/*=====================235* Other functions236*====================*/237238/**********************239* MACROS240**********************/241242#endif /*USE_LV_IMGBTN*/243244#ifdef __cplusplus245} /* extern "C" */246#endif247248#endif /*LV_IMGBTN_H*/249250251