2016-06-08 07:25:08 +02:00
|
|
|
/**
|
2017-10-20 15:37:50 +02:00
|
|
|
* @file lv_btn.h
|
2018-06-19 09:49:58 +02:00
|
|
|
*
|
2016-06-08 07:25:08 +02:00
|
|
|
*/
|
|
|
|
|
2017-10-20 15:37:50 +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
|
|
|
|
*********************/
|
2019-12-26 02:49:30 +01:00
|
|
|
#include "../lv_conf_internal.h"
|
2018-07-07 11:53:22 +02:00
|
|
|
|
2019-03-07 00:05:16 +01:00
|
|
|
#if LV_USE_BTN != 0
|
2016-06-08 07:25:08 +02:00
|
|
|
|
2017-01-02 10:48:21 +01:00
|
|
|
/*Testing of dependencies*/
|
2019-03-07 00:05:16 +01:00
|
|
|
#if LV_USE_CONT == 0
|
|
|
|
#error "lv_btn: lv_cont is required. Enable it in lv_conf.h (LV_USE_CONT 1) "
|
2017-01-02 10:48:21 +01:00
|
|
|
#endif
|
|
|
|
|
2017-08-23 14:39:09 +02:00
|
|
|
#include "lv_cont.h"
|
2017-11-30 11:35:33 +01:00
|
|
|
#include "../lv_core/lv_indev.h"
|
2016-06-08 07:25:08 +02:00
|
|
|
|
|
|
|
/*********************
|
|
|
|
* DEFINES
|
|
|
|
*********************/
|
|
|
|
|
|
|
|
/**********************
|
|
|
|
* TYPEDEFS
|
|
|
|
**********************/
|
|
|
|
|
2019-06-19 00:35:35 +02:00
|
|
|
/** Possible states of a button.
|
2018-09-06 20:57:59 +02:00
|
|
|
* It can be used not only by buttons but other button-like objects too*/
|
2019-04-04 07:15:40 +02:00
|
|
|
enum {
|
2020-02-13 13:56:08 +01:00
|
|
|
LV_BTN_STATE_RELEASED,
|
|
|
|
LV_BTN_STATE_PRESSED,
|
|
|
|
LV_BTN_STATE_CHECKED_RELEASED,
|
|
|
|
LV_BTN_STATE_CHECKED_PRESSED,
|
|
|
|
LV_BTN_STATE_DISABLED,
|
|
|
|
_LV_BTN_STATE_LAST, /* Number of states*/
|
2018-09-18 13:59:40 +02:00
|
|
|
};
|
|
|
|
typedef uint8_t lv_btn_state_t;
|
2016-06-08 07:25:08 +02:00
|
|
|
|
2019-06-27 07:16:15 +02:00
|
|
|
/** Extended data of button*/
|
2020-02-26 19:48:27 +01:00
|
|
|
typedef struct {
|
2019-06-27 07:16:15 +02:00
|
|
|
/** Ext. of ancestor*/
|
|
|
|
lv_cont_ext_t cont;
|
|
|
|
|
|
|
|
/** 1: Toggle enabled*/
|
2020-02-23 07:16:40 +01:00
|
|
|
uint8_t checkable : 1;
|
2018-06-19 09:49:58 +02:00
|
|
|
} lv_btn_ext_t;
|
2017-01-14 23:54:16 +01:00
|
|
|
|
2019-06-27 07:16:15 +02:00
|
|
|
/**Styles*/
|
2018-09-18 13:59:40 +02:00
|
|
|
enum {
|
2020-02-26 19:48:27 +01:00
|
|
|
LV_BTN_PART_MAIN = LV_OBJ_PART_MAIN,
|
2020-01-24 14:55:56 +01:00
|
|
|
_LV_BTN_PART_VIRTUAL_LAST,
|
|
|
|
_LV_BTN_PART_REAL_LAST = _LV_OBJ_PART_REAL_LAST,
|
2018-09-18 13:59:40 +02:00
|
|
|
};
|
2019-12-31 06:10:50 +01:00
|
|
|
typedef uint8_t lv_btn_part_t;
|
2016-06-08 07:25:08 +02:00
|
|
|
|
|
|
|
/**********************
|
|
|
|
* GLOBAL PROTOTYPES
|
|
|
|
**********************/
|
2017-01-13 23:27:49 +01:00
|
|
|
|
|
|
|
/**
|
2019-07-10 11:56:36 +02:00
|
|
|
* Create a button object
|
2017-01-13 23:27:49 +01:00
|
|
|
* @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
|
|
|
|
*/
|
2018-07-30 06:52:29 +02:00
|
|
|
lv_obj_t * lv_btn_create(lv_obj_t * par, const lv_obj_t * copy);
|
2016-06-08 07:25:08 +02:00
|
|
|
|
2017-11-10 15:01:40 +01:00
|
|
|
/*=====================
|
|
|
|
* Setter functions
|
|
|
|
*====================*/
|
|
|
|
|
2017-01-13 23:27:49 +01:00
|
|
|
/**
|
2017-11-10 15:01:40 +01:00
|
|
|
* Enable the toggled states. On release the button will change from/to toggled state.
|
2017-01-13 23:27:49 +01:00
|
|
|
* @param btn pointer to a button object
|
|
|
|
* @param tgl true: enable toggled states, false: disable
|
|
|
|
*/
|
2020-02-13 13:56:08 +01:00
|
|
|
void lv_btn_set_checkable(lv_obj_t * btn, bool tgl);
|
2017-01-13 23:27:49 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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);
|
2017-01-13 23:27:49 +01:00
|
|
|
|
2017-10-20 15:37:50 +02:00
|
|
|
/**
|
|
|
|
* Toggle the state of the button (ON->OFF, OFF->ON)
|
|
|
|
* @param btn pointer to a button object
|
|
|
|
*/
|
|
|
|
void lv_btn_toggle(lv_obj_t * btn);
|
|
|
|
|
2017-11-10 15:01:40 +01:00
|
|
|
/**
|
|
|
|
* Set the layout on a button
|
|
|
|
* @param btn pointer to a button object
|
|
|
|
* @param layout a layout from 'lv_cont_layout_t'
|
|
|
|
*/
|
2017-11-17 15:43:08 +01:00
|
|
|
static inline void lv_btn_set_layout(lv_obj_t * btn, lv_layout_t layout)
|
2017-11-10 15:01:40 +01:00
|
|
|
{
|
|
|
|
lv_cont_set_layout(btn, layout);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-02-24 06:24:36 +01:00
|
|
|
* Set the fit policy in all 4 directions separately.
|
2019-07-10 11:56:36 +02:00
|
|
|
* It tells how to change the button size automatically.
|
2017-11-10 15:01:40 +01:00
|
|
|
* @param btn pointer to a button object
|
2019-02-24 06:24:36 +01:00
|
|
|
* @param left left fit policy from `lv_fit_t`
|
|
|
|
* @param right right fit policy from `lv_fit_t`
|
2019-07-10 11:56:36 +02:00
|
|
|
* @param top top fit policy from `lv_fit_t`
|
2019-02-24 06:24:36 +01:00
|
|
|
* @param bottom bottom fit policy from `lv_fit_t`
|
2017-11-10 15:01:40 +01:00
|
|
|
*/
|
2019-06-06 06:05:40 +02:00
|
|
|
static inline void lv_btn_set_fit4(lv_obj_t * btn, lv_fit_t left, lv_fit_t right, lv_fit_t top, lv_fit_t bottom)
|
2017-11-10 15:01:40 +01:00
|
|
|
{
|
2019-02-24 06:24:36 +01:00
|
|
|
lv_cont_set_fit4(btn, left, right, top, bottom);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the fit policy horizontally and vertically separately.
|
2019-07-10 11:56:36 +02:00
|
|
|
* It tells how to change the button size automatically.
|
2019-02-24 06:24:36 +01:00
|
|
|
* @param btn pointer to a button object
|
2019-07-10 11:56:36 +02:00
|
|
|
* @param hor horizontal fit policy from `lv_fit_t`
|
2019-02-24 06:24:36 +01:00
|
|
|
* @param ver vertical fit policy from `lv_fit_t`
|
|
|
|
*/
|
|
|
|
static inline void lv_btn_set_fit2(lv_obj_t * btn, lv_fit_t hor, lv_fit_t ver)
|
|
|
|
{
|
|
|
|
lv_cont_set_fit2(btn, hor, ver);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the fit policy in all 4 direction at once.
|
2019-07-10 11:56:36 +02:00
|
|
|
* It tells how to change the button size automatically.
|
2019-02-24 06:24:36 +01:00
|
|
|
* @param btn pointer to a button object
|
|
|
|
* @param fit fit policy from `lv_fit_t`
|
|
|
|
*/
|
2019-07-10 11:56:36 +02:00
|
|
|
static inline void lv_btn_set_fit(lv_obj_t * btn, lv_fit_t fit)
|
2019-02-24 06:24:36 +01:00
|
|
|
{
|
2019-07-10 11:56:36 +02:00
|
|
|
lv_cont_set_fit(btn, fit);
|
2017-11-10 15:01:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*=====================
|
|
|
|
* Getter functions
|
|
|
|
*====================*/
|
2017-04-13 10:20:35 +02:00
|
|
|
|
2017-01-13 23:27:49 +01: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)
|
|
|
|
*/
|
2018-07-30 06:52:29 +02:00
|
|
|
lv_btn_state_t lv_btn_get_state(const lv_obj_t * btn);
|
2016-06-08 07:25:08 +02:00
|
|
|
|
2017-01-13 23:27:49 +01:00
|
|
|
/**
|
|
|
|
* Get the toggle enable attribute of the button
|
|
|
|
* @param btn pointer to a button object
|
2020-02-23 07:16:40 +01:00
|
|
|
* @return true: checkable enabled, false: disabled
|
2017-01-13 23:27:49 +01:00
|
|
|
*/
|
2020-02-13 13:56:08 +01:00
|
|
|
bool lv_btn_get_checkable(const lv_obj_t * btn);
|
2017-01-13 23:27:49 +01:00
|
|
|
|
2017-11-03 13:39:37 +01:00
|
|
|
/**
|
|
|
|
* Get the layout of a button
|
|
|
|
* @param btn pointer to button object
|
|
|
|
* @return the layout from 'lv_cont_layout_t'
|
|
|
|
*/
|
2018-07-30 06:52:29 +02:00
|
|
|
static inline lv_layout_t lv_btn_get_layout(const lv_obj_t * btn)
|
2017-11-03 13:39:37 +01:00
|
|
|
{
|
|
|
|
return lv_cont_get_layout(btn);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-02-24 06:24:36 +01:00
|
|
|
* Get the left fit mode
|
2017-11-03 13:39:37 +01:00
|
|
|
* @param btn pointer to a button object
|
2019-02-24 06:24:36 +01:00
|
|
|
* @return an element of `lv_fit_t`
|
2017-11-03 13:39:37 +01:00
|
|
|
*/
|
2019-02-24 06:24:36 +01:00
|
|
|
static inline lv_fit_t lv_btn_get_fit_left(const lv_obj_t * btn)
|
2017-11-03 13:39:37 +01:00
|
|
|
{
|
2019-02-24 06:24:36 +01:00
|
|
|
return lv_cont_get_fit_left(btn);
|
2017-11-03 13:39:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-02-24 06:24:36 +01:00
|
|
|
* Get the right fit mode
|
2017-11-03 13:39:37 +01:00
|
|
|
* @param btn pointer to a button object
|
2019-02-24 06:24:36 +01:00
|
|
|
* @return an element of `lv_fit_t`
|
2017-11-03 13:39:37 +01:00
|
|
|
*/
|
2019-02-24 06:24:36 +01:00
|
|
|
static inline lv_fit_t lv_btn_get_fit_right(const lv_obj_t * btn)
|
2017-11-03 13:39:37 +01:00
|
|
|
{
|
2019-02-24 06:24:36 +01:00
|
|
|
return lv_cont_get_fit_right(btn);
|
2017-11-03 13:39:37 +01:00
|
|
|
}
|
2018-08-26 13:49:23 +02:00
|
|
|
|
2019-02-24 06:24:36 +01:00
|
|
|
/**
|
|
|
|
* Get the top fit mode
|
|
|
|
* @param btn pointer to a button object
|
|
|
|
* @return an element of `lv_fit_t`
|
|
|
|
*/
|
|
|
|
static inline lv_fit_t lv_btn_get_fit_top(const lv_obj_t * btn)
|
|
|
|
{
|
|
|
|
return lv_cont_get_fit_top(btn);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the bottom fit mode
|
|
|
|
* @param btn pointer to a button object
|
|
|
|
* @return an element of `lv_fit_t`
|
|
|
|
*/
|
|
|
|
static inline lv_fit_t lv_btn_get_fit_bottom(const lv_obj_t * btn)
|
|
|
|
{
|
|
|
|
return lv_cont_get_fit_bottom(btn);
|
|
|
|
}
|
|
|
|
|
2016-06-08 07:25:08 +02:00
|
|
|
/**********************
|
|
|
|
* MACROS
|
|
|
|
**********************/
|
|
|
|
|
2019-04-04 07:15:40 +02:00
|
|
|
#endif /*LV_USE_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
|
|
|
|
2019-04-04 07:15:40 +02:00
|
|
|
#endif /*LV_BTN_H*/
|