1
0
mirror of https://github.com/lvgl/lvgl.git synced 2025-01-21 06:53:01 +08:00
lvgl/src/lv_widgets/lv_imgbtn.h

207 lines
5.8 KiB
C
Raw Normal View History

2018-09-06 20:57:59 +02:00
/**
* @file lv_imgbtn.h
*
*/
#ifndef LV_IMGBTN_H
#define LV_IMGBTN_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#include "../lv_conf_internal.h"
2018-09-06 20:57:59 +02:00
#if LV_USE_IMGBTN != 0
2018-09-06 20:57:59 +02:00
/*Testing of dependencies*/
#if LV_USE_BTN == 0
#error "lv_imgbtn: lv_btn is required. Enable it in lv_conf.h (LV_USE_BTN 1) "
2018-09-06 20:57:59 +02:00
#endif
#include "../lv_core/lv_obj.h"
#include "lv_btn.h"
#include "../lv_draw/lv_draw_img.h"
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/*Data of image button*/
2019-04-04 07:15:40 +02:00
typedef struct
{
2018-09-06 20:57:59 +02:00
lv_btn_ext_t btn; /*Ext. of ancestor*/
/*New data for this type */
2018-11-20 17:05:55 +01:00
#if LV_IMGBTN_TILED == 0
2020-02-13 13:56:08 +01:00
const void * img_src[_LV_BTN_STATE_LAST]; /*Store images to each state*/
2018-11-20 17:05:55 +01:00
#else
2019-06-27 07:16:15 +02:00
const void * img_src_left[_LV_BTN_STATE_NUM]; /*Store left side images to each state*/
const void * img_src_mid[_LV_BTN_STATE_NUM]; /*Store center images to each state*/
const void * img_src_right[_LV_BTN_STATE_NUM]; /*Store right side images to each state*/
2018-11-20 17:05:55 +01:00
#endif
2019-04-04 07:15:40 +02:00
lv_img_cf_t act_cf; /*Color format of the currently active image*/
2018-09-06 20:57:59 +02:00
} lv_imgbtn_ext_t;
2020-01-10 11:10:07 +01:00
/*Parts of the image button*/
2018-09-18 13:59:40 +02:00
enum {
2020-01-10 11:10:07 +01:00
LV_IMGBTN_PART_MAIN = LV_BTN_PART_MAIN,
2018-09-18 13:59:40 +02:00
};
2020-01-10 11:10:07 +01:00
typedef uint8_t lv_imgbtn_part_t;
2018-09-06 20:57:59 +02:00
/**********************
* GLOBAL PROTOTYPES
**********************/
/**
* Create a image button objects
* @param par pointer to an object, it will be the parent of the new image button
2019-04-04 07:15:40 +02:00
* @param copy pointer to a image button object, if not NULL then the new object will be copied from
* it
2018-09-06 20:57:59 +02:00
* @return pointer to the created image button
*/
lv_obj_t * lv_imgbtn_create(lv_obj_t * par, const lv_obj_t * copy);
/*======================
* Add/remove functions
*=====================*/
/*=====================
* Setter functions
*====================*/
2018-11-20 17:05:55 +01:00
#if LV_IMGBTN_TILED == 0
2018-09-06 20:57:59 +02:00
/**
* Set images for a state of the image button
* @param imgbtn pointer to an image button object
* @param state for which state set the new image (from `lv_btn_state_t`) `
* @param src pointer to an image source (a C array or path to a file)
*/
2018-09-20 23:31:07 +02:00
void lv_imgbtn_set_src(lv_obj_t * imgbtn, lv_btn_state_t state, const void * src);
2018-11-20 17:05:55 +01:00
#else
/**
* Set images for a state of the image button
* @param imgbtn pointer to an image button object
* @param state for which state set the new image (from `lv_btn_state_t`) `
2019-04-04 07:15:40 +02:00
* @param src_left pointer to an image source for the left side of the button (a C array or path to
* a file)
* @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)
* @param src_right pointer to an image source for the right side of the button (a C array or path
* to a file)
2018-11-20 17:05:55 +01:00
*/
2019-06-06 06:05:40 +02:00
void 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);
2018-11-20 17:05:55 +01:00
#endif
2018-09-06 20:57:59 +02:00
/**
* Enable the toggled states. On release the button will change from/to toggled state.
* @param imgbtn pointer to an image button object
* @param tgl true: enable toggled states, false: disable
*/
2020-02-13 13:56:08 +01:00
static inline void lv_imgbtn_set_checkable(lv_obj_t * imgbtn, bool tgl)
2018-09-06 20:57:59 +02:00
{
2020-02-13 13:56:08 +01:00
lv_btn_set_checkable(imgbtn, tgl);
2018-09-06 20:57:59 +02:00
}
/**
* Set the state of the image button
* @param imgbtn pointer to an image button object
* @param state the new state of the button (from lv_btn_state_t enum)
*/
static inline void lv_imgbtn_set_state(lv_obj_t * imgbtn, lv_btn_state_t state)
{
lv_btn_set_state(imgbtn, state);
}
/**
* Toggle the state of the image button (ON->OFF, OFF->ON)
* @param imgbtn pointer to a image button object
*/
static inline void lv_imgbtn_toggle(lv_obj_t * imgbtn)
{
lv_btn_toggle(imgbtn);
}
/*=====================
* Getter functions
*====================*/
2019-01-03 15:57:31 +01:00
#if LV_IMGBTN_TILED == 0
2018-09-06 20:57:59 +02:00
/**
* Get the images in a given state
* @param imgbtn pointer to an image button object
* @param state the state where to get the image (from `lv_btn_state_t`) `
* @return pointer to an image source (a C array or path to a file)
*/
2018-09-23 21:54:55 +02:00
const void * lv_imgbtn_get_src(lv_obj_t * imgbtn, lv_btn_state_t state);
2018-09-06 20:57:59 +02:00
2019-01-03 15:57:31 +01:00
#else
/**
* Get the left image in a given state
* @param imgbtn pointer to an image button object
* @param state the state where to get the image (from `lv_btn_state_t`) `
* @return pointer to the left image source (a C array or path to a file)
*/
const void * lv_imgbtn_get_src_left(lv_obj_t * imgbtn, lv_btn_state_t state);
/**
* Get the middle image in a given state
* @param imgbtn pointer to an image button object
* @param state the state where to get the image (from `lv_btn_state_t`) `
* @return pointer to the middle image source (a C array or path to a file)
*/
const void * lv_imgbtn_get_src_middle(lv_obj_t * imgbtn, lv_btn_state_t state);
/**
* Get the right image in a given state
* @param imgbtn pointer to an image button object
* @param state the state where to get the image (from `lv_btn_state_t`) `
* @return pointer to the left image source (a C array or path to a file)
*/
const void * lv_imgbtn_get_src_right(lv_obj_t * imgbtn, lv_btn_state_t state);
#endif
2018-09-06 20:57:59 +02:00
/**
* Get the current state of the image button
* @param imgbtn pointer to a image button object
* @return the state of the button (from lv_btn_state_t enum)
*/
static inline lv_btn_state_t lv_imgbtn_get_state(const lv_obj_t * imgbtn)
{
return lv_btn_get_state(imgbtn);
}
/**
* Get the toggle enable attribute of the image button
* @param imgbtn pointer to a image button object
* @return ture: toggle enabled, false: disabled
*/
2020-02-13 13:56:08 +01:00
static inline bool lv_imgbtn_get_checkable(const lv_obj_t * imgbtn)
2018-09-06 20:57:59 +02:00
{
2020-02-13 13:56:08 +01:00
return lv_btn_get_checkable(imgbtn);
2018-09-06 20:57:59 +02:00
}
/*=====================
* Other functions
*====================*/
/**********************
* MACROS
**********************/
2019-04-04 07:15:40 +02:00
#endif /*LV_USE_IMGBTN*/
2018-09-06 20:57:59 +02:00
#ifdef __cplusplus
} /* extern "C" */
#endif
2019-04-04 07:15:40 +02:00
#endif /*LV_IMGBTN_H*/