2017-04-13 10:20:35 +02:00
|
|
|
/**
|
|
|
|
* @file lv_style.h
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef LV_STYLE_H
|
|
|
|
#define LV_STYLE_H
|
|
|
|
|
2017-07-09 15:32:49 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2017-04-13 10:20:35 +02:00
|
|
|
/*********************
|
|
|
|
* INCLUDES
|
|
|
|
*********************/
|
|
|
|
#include <stdbool.h>
|
2019-06-06 05:55:17 +02:00
|
|
|
#include "../lv_font/lv_font.h"
|
2017-11-23 20:42:14 +01:00
|
|
|
#include "../lv_misc/lv_color.h"
|
|
|
|
#include "../lv_misc/lv_area.h"
|
|
|
|
#include "../lv_misc/lv_anim.h"
|
2017-04-13 10:20:35 +02:00
|
|
|
|
|
|
|
/*********************
|
|
|
|
* DEFINES
|
|
|
|
*********************/
|
2019-06-27 18:07:26 -04:00
|
|
|
#define LV_RADIUS_CIRCLE (LV_COORD_MAX) /**< A very big radius to always draw as circle*/
|
2019-09-27 03:28:44 +02:00
|
|
|
#define LV_STYLE_DEGUG_SENTINEL_VALUE 0x12345678
|
2017-04-13 10:20:35 +02:00
|
|
|
|
2019-10-03 23:20:50 +03:00
|
|
|
LV_EXPORT_CONST_INT(LV_RADIUS_CIRCLE);
|
|
|
|
|
2017-04-13 10:20:35 +02:00
|
|
|
/**********************
|
|
|
|
* TYPEDEFS
|
|
|
|
**********************/
|
2017-04-21 09:15:39 +02:00
|
|
|
|
2017-11-17 15:43:08 +01:00
|
|
|
/*Border types (Use 'OR'ed values)*/
|
2019-04-04 07:15:40 +02:00
|
|
|
enum {
|
|
|
|
LV_BORDER_NONE = 0x00,
|
|
|
|
LV_BORDER_BOTTOM = 0x01,
|
|
|
|
LV_BORDER_TOP = 0x02,
|
|
|
|
LV_BORDER_LEFT = 0x04,
|
|
|
|
LV_BORDER_RIGHT = 0x08,
|
|
|
|
LV_BORDER_FULL = 0x0F,
|
2019-06-27 18:07:26 -04:00
|
|
|
LV_BORDER_INTERNAL = 0x10, /**< FOR matrix-like objects (e.g. Button matrix)*/
|
2018-09-18 13:59:40 +02:00
|
|
|
};
|
|
|
|
typedef uint8_t lv_border_part_t;
|
2017-11-17 15:43:08 +01:00
|
|
|
|
2017-04-24 12:08:24 +02:00
|
|
|
/*Shadow types*/
|
2019-04-04 07:15:40 +02:00
|
|
|
enum {
|
2019-06-27 18:07:26 -04:00
|
|
|
LV_SHADOW_BOTTOM = 0, /**< Only draw bottom shadow */
|
|
|
|
LV_SHADOW_FULL, /**< Draw shadow on all sides */
|
2018-09-18 13:59:40 +02:00
|
|
|
};
|
|
|
|
typedef uint8_t lv_shadow_type_t;
|
2017-04-24 12:08:24 +02:00
|
|
|
|
2019-06-27 18:07:26 -04:00
|
|
|
/**
|
|
|
|
* Objects in LittlevGL can be assigned a style - which holds information about
|
|
|
|
* how the object should be drawn.
|
|
|
|
*
|
|
|
|
* This allows for easy customization without having to modify the object's design
|
|
|
|
* function.
|
|
|
|
*/
|
2017-04-13 10:20:35 +02:00
|
|
|
typedef struct
|
|
|
|
{
|
2019-06-27 18:07:26 -04:00
|
|
|
uint8_t glass : 1; /**< 1: Do not inherit this style*/
|
2017-10-19 12:46:49 +02:00
|
|
|
|
2019-06-27 18:07:26 -04:00
|
|
|
/** Object background. */
|
2019-04-04 07:15:40 +02:00
|
|
|
struct
|
|
|
|
{
|
2019-06-27 18:07:26 -04:00
|
|
|
lv_color_t main_color; /**< Object's main background color. */
|
|
|
|
lv_color_t grad_color; /**< Second color. If not equal to `main_color` a gradient will be drawn for the background. */
|
|
|
|
lv_coord_t radius; /**< Object's corner radius. You can use #LV_RADIUS_CIRCLE if you want to draw a circle. */
|
|
|
|
lv_opa_t opa; /**< Object's opacity (0-255). */
|
2017-10-20 10:17:02 +02:00
|
|
|
|
2019-04-04 07:15:40 +02:00
|
|
|
struct
|
|
|
|
{
|
2019-06-27 18:07:26 -04:00
|
|
|
lv_color_t color; /**< Border color */
|
|
|
|
lv_coord_t width; /**< Border width */
|
|
|
|
lv_border_part_t part; /**< Which borders to draw */
|
|
|
|
lv_opa_t opa; /**< Border opacity. */
|
2018-06-19 09:49:58 +02:00
|
|
|
} border;
|
2017-10-20 10:17:02 +02:00
|
|
|
|
2019-06-27 18:07:26 -04:00
|
|
|
|
2019-04-04 07:15:40 +02:00
|
|
|
struct
|
|
|
|
{
|
2017-11-23 21:28:36 +01:00
|
|
|
lv_color_t color;
|
|
|
|
lv_coord_t width;
|
2019-06-27 18:07:26 -04:00
|
|
|
lv_shadow_type_t type; /**< Which parts of the shadow to draw */
|
2018-06-19 09:49:58 +02:00
|
|
|
} shadow;
|
2017-10-20 10:17:02 +02:00
|
|
|
|
2019-04-04 07:15:40 +02:00
|
|
|
struct
|
|
|
|
{
|
2019-03-13 23:58:33 +01:00
|
|
|
lv_coord_t top;
|
|
|
|
lv_coord_t bottom;
|
|
|
|
lv_coord_t left;
|
|
|
|
lv_coord_t right;
|
2017-11-23 21:28:36 +01:00
|
|
|
lv_coord_t inner;
|
2018-06-19 09:49:58 +02:00
|
|
|
} padding;
|
|
|
|
} body;
|
2017-10-18 16:07:19 +02:00
|
|
|
|
2019-06-27 18:07:26 -04:00
|
|
|
/** Style for text drawn by this object. */
|
2019-04-04 07:15:40 +02:00
|
|
|
struct
|
|
|
|
{
|
2019-06-27 18:07:26 -04:00
|
|
|
lv_color_t color; /**< Text color */
|
|
|
|
lv_color_t sel_color; /**< Text selection background color. */
|
2017-11-23 21:28:36 +01:00
|
|
|
const lv_font_t * font;
|
2019-06-27 18:07:26 -04:00
|
|
|
lv_coord_t letter_space; /**< Space between letters */
|
|
|
|
lv_coord_t line_space; /**< Space between lines (vertical) */
|
|
|
|
lv_opa_t opa; /**< Text opacity */
|
2018-06-19 09:49:58 +02:00
|
|
|
} text;
|
2017-10-18 16:07:19 +02:00
|
|
|
|
2019-06-27 18:07:26 -04:00
|
|
|
/**< Style of images. */
|
2019-04-04 07:15:40 +02:00
|
|
|
struct
|
|
|
|
{
|
2019-06-27 18:07:26 -04:00
|
|
|
lv_color_t color; /**< Color to recolor the image with */
|
|
|
|
lv_opa_t intense; /**< Opacity of recoloring (0 means no recoloring) */
|
|
|
|
lv_opa_t opa; /**< Opacity of whole image */
|
2018-06-19 09:49:58 +02:00
|
|
|
} image;
|
2017-10-18 16:07:19 +02:00
|
|
|
|
2019-06-27 18:07:26 -04:00
|
|
|
/**< Style of lines (not borders). */
|
2019-04-04 07:15:40 +02:00
|
|
|
struct
|
|
|
|
{
|
2017-11-23 21:28:36 +01:00
|
|
|
lv_color_t color;
|
|
|
|
lv_coord_t width;
|
|
|
|
lv_opa_t opa;
|
2019-06-27 18:07:26 -04:00
|
|
|
uint8_t rounded : 1; /**< 1: rounded line endings*/
|
2018-06-19 09:49:58 +02:00
|
|
|
} line;
|
2019-09-27 03:28:44 +02:00
|
|
|
|
|
|
|
#if LV_USE_DEBUG
|
|
|
|
#if LV_USE_ASSERT_STYLE
|
|
|
|
uint32_t debug_sentinel; /**<Should `LV_STYLE_DEGUG_SENTINEL_VALUE` to indicate that the style is valid*/
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2018-06-19 09:49:58 +02:00
|
|
|
} lv_style_t;
|
2017-04-13 10:20:35 +02:00
|
|
|
|
2019-03-07 00:05:16 +01:00
|
|
|
#if LV_USE_ANIMATION
|
2019-06-27 18:07:26 -04:00
|
|
|
/** Data structure for style animations. */
|
2019-04-04 07:15:40 +02:00
|
|
|
typedef struct
|
|
|
|
{
|
2019-05-15 18:27:26 +02:00
|
|
|
lv_style_t style_start; /*Save not only pointers because can be same as 'style_anim' then it
|
|
|
|
will be modified too*/
|
|
|
|
lv_style_t style_end;
|
|
|
|
lv_style_t * style_anim;
|
|
|
|
lv_anim_ready_cb_t ready_cb;
|
|
|
|
} lv_style_anim_dsc_t;
|
2019-04-22 08:45:07 +02:00
|
|
|
#endif
|
|
|
|
|
2019-05-15 18:27:26 +02:00
|
|
|
/**********************
|
|
|
|
* GLOBAL PROTOTYPES
|
|
|
|
**********************/
|
2019-04-22 08:45:07 +02:00
|
|
|
|
2019-05-15 18:27:26 +02:00
|
|
|
/**
|
|
|
|
* Init the basic styles
|
2017-07-28 13:57:56 +02:00
|
|
|
*/
|
2019-05-15 18:27:26 +02:00
|
|
|
void lv_style_init(void);
|
2019-05-15 06:15:12 +02:00
|
|
|
|
2019-05-15 18:27:26 +02:00
|
|
|
/**
|
|
|
|
* Copy a style to an other
|
|
|
|
* @param dest pointer to the destination style
|
|
|
|
* @param src pointer to the source style
|
|
|
|
*/
|
|
|
|
void lv_style_copy(lv_style_t * dest, const lv_style_t * src);
|
2019-05-15 06:15:12 +02:00
|
|
|
|
2019-05-15 18:27:26 +02:00
|
|
|
/**
|
|
|
|
* Mix two styles according to a given ratio
|
|
|
|
* @param start start style
|
|
|
|
* @param end end style
|
|
|
|
* @param res store the result style here
|
|
|
|
* @param ratio the ratio of mix [0..256]; 0: `start` style; 256: `end` style
|
|
|
|
*/
|
2019-06-06 06:05:40 +02:00
|
|
|
void lv_style_mix(const lv_style_t * start, const lv_style_t * end, lv_style_t * res, uint16_t ratio);
|
2019-05-15 06:15:12 +02:00
|
|
|
|
2019-05-15 18:27:26 +02:00
|
|
|
#if LV_USE_ANIMATION
|
2019-05-15 06:15:12 +02:00
|
|
|
|
2019-05-15 18:27:26 +02:00
|
|
|
/**
|
|
|
|
* Initialize an animation variable.
|
|
|
|
* E.g.:
|
|
|
|
* lv_anim_t a;
|
|
|
|
* lv_style_anim__init(&a);
|
|
|
|
* lv_style_anim_set_...(&a);
|
|
|
|
* lv_style_anim_create(&a);
|
|
|
|
* @param a pointer to an `lv_anim_t` variable to initialize
|
|
|
|
*/
|
|
|
|
void lv_style_anim_init(lv_anim_t * a);
|
2019-05-15 06:15:12 +02:00
|
|
|
|
2019-05-15 18:27:26 +02:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param a pointer to an initialized `lv_anim_t` variable
|
|
|
|
* @param to_anim pointer to the style to animate
|
|
|
|
* @param start pointer to a style to animate from (start value)
|
|
|
|
* @param end pointer to a style to animate to (end value)
|
|
|
|
*/
|
|
|
|
void lv_style_anim_set_styles(lv_anim_t * a, lv_style_t * to_anim, const lv_style_t * start, const lv_style_t * end);
|
2019-05-15 06:15:12 +02:00
|
|
|
|
2019-05-15 18:27:26 +02:00
|
|
|
/**
|
|
|
|
* Set the duration and delay of an animation
|
|
|
|
* @param a pointer to an initialized `lv_anim_t` variable
|
|
|
|
* @param duration duration of the animation in milliseconds
|
|
|
|
* @param delay delay before the animation in milliseconds
|
|
|
|
*/
|
|
|
|
static inline void lv_style_anim_set_time(lv_anim_t * a, uint16_t duration, uint16_t delay)
|
2019-05-15 06:15:12 +02:00
|
|
|
{
|
2019-05-15 18:27:26 +02:00
|
|
|
lv_anim_set_time(a, duration, delay);
|
2019-05-15 06:15:12 +02:00
|
|
|
}
|
|
|
|
|
2019-05-15 18:27:26 +02:00
|
|
|
/**
|
|
|
|
* Set a function call when the animation is ready
|
|
|
|
* @param a pointer to an initialized `lv_anim_t` variable
|
|
|
|
* @param ready_cb a function call when the animation is ready
|
|
|
|
*/
|
|
|
|
static inline void lv_style_anim_set_ready_cb(lv_anim_t * a, lv_anim_ready_cb_t ready_cb)
|
2019-05-15 06:15:12 +02:00
|
|
|
{
|
2019-06-23 12:48:58 -04:00
|
|
|
lv_style_anim_dsc_t * dsc = (lv_style_anim_dsc_t *)a->var;
|
2019-06-06 06:05:40 +02:00
|
|
|
dsc->ready_cb = ready_cb;
|
2019-05-15 06:15:12 +02:00
|
|
|
}
|
|
|
|
|
2019-05-15 18:27:26 +02:00
|
|
|
/**
|
|
|
|
* Make the animation to play back to when the forward direction is ready
|
|
|
|
* @param a pointer to an initialized `lv_anim_t` variable
|
|
|
|
* @param wait_time time in milliseconds to wait before starting the back direction
|
|
|
|
*/
|
|
|
|
static inline void lv_style_anim_set_playback(lv_anim_t * a, uint16_t wait_time)
|
2019-05-15 06:15:12 +02:00
|
|
|
{
|
2019-05-15 18:27:26 +02:00
|
|
|
lv_anim_set_playback(a, wait_time);
|
2019-05-15 06:15:12 +02:00
|
|
|
}
|
|
|
|
|
2019-05-15 18:27:26 +02:00
|
|
|
/**
|
|
|
|
* Disable playback. (Disabled after `lv_anim_init()`)
|
|
|
|
* @param a pointer to an initialized `lv_anim_t` variable
|
|
|
|
*/
|
|
|
|
static inline void lv_style_anim_clear_playback(lv_anim_t * a)
|
2019-05-15 06:15:12 +02:00
|
|
|
{
|
2019-05-15 18:27:26 +02:00
|
|
|
lv_anim_clear_playback(a);
|
2019-05-15 06:15:12 +02:00
|
|
|
}
|
|
|
|
|
2019-05-15 18:27:26 +02:00
|
|
|
/**
|
|
|
|
* Make the animation to start again when ready.
|
|
|
|
* @param a pointer to an initialized `lv_anim_t` variable
|
|
|
|
* @param wait_time time in milliseconds to wait before starting the animation again
|
|
|
|
*/
|
|
|
|
static inline void lv_style_anim_set_repeat(lv_anim_t * a, uint16_t wait_time)
|
2019-05-15 06:15:12 +02:00
|
|
|
{
|
2019-05-15 18:27:26 +02:00
|
|
|
lv_anim_set_repeat(a, wait_time);
|
2019-05-15 06:15:12 +02:00
|
|
|
}
|
|
|
|
|
2019-05-15 18:27:26 +02:00
|
|
|
/**
|
|
|
|
* Disable repeat. (Disabled after `lv_anim_init()`)
|
|
|
|
* @param a pointer to an initialized `lv_anim_t` variable
|
|
|
|
*/
|
|
|
|
static inline void lv_style_anim_clear_repeat(lv_anim_t * a)
|
2019-05-15 06:15:12 +02:00
|
|
|
{
|
2019-05-15 18:27:26 +02:00
|
|
|
lv_anim_clear_repeat(a);
|
2019-05-15 06:15:12 +02:00
|
|
|
}
|
|
|
|
|
2018-08-26 13:49:23 +02:00
|
|
|
/**
|
2019-05-15 18:27:26 +02:00
|
|
|
* Create an animation
|
|
|
|
* @param a an initialized 'anim_t' variable. Not required after call.
|
2018-08-26 13:49:23 +02:00
|
|
|
*/
|
2019-05-15 18:27:26 +02:00
|
|
|
static inline void lv_style_anim_create(lv_anim_t * a)
|
|
|
|
{
|
2019-05-20 07:50:39 -04:00
|
|
|
lv_anim_create(a);
|
2019-05-15 18:27:26 +02:00
|
|
|
}
|
2018-06-15 09:29:10 +02:00
|
|
|
|
2017-11-27 17:48:54 +01:00
|
|
|
#endif
|
2017-07-28 14:19:52 +02:00
|
|
|
|
2017-10-30 17:31:48 +01:00
|
|
|
/*************************
|
|
|
|
* GLOBAL VARIABLES
|
|
|
|
*************************/
|
|
|
|
extern lv_style_t lv_style_scr;
|
|
|
|
extern lv_style_t lv_style_transp;
|
2017-10-31 16:25:52 +01:00
|
|
|
extern lv_style_t lv_style_transp_fit;
|
2017-10-30 17:31:48 +01:00
|
|
|
extern lv_style_t lv_style_transp_tight;
|
|
|
|
extern lv_style_t lv_style_plain;
|
|
|
|
extern lv_style_t lv_style_plain_color;
|
|
|
|
extern lv_style_t lv_style_pretty;
|
|
|
|
extern lv_style_t lv_style_pretty_color;
|
2017-11-20 14:26:18 +01:00
|
|
|
extern lv_style_t lv_style_btn_rel;
|
|
|
|
extern lv_style_t lv_style_btn_pr;
|
|
|
|
extern lv_style_t lv_style_btn_tgl_rel;
|
2019-02-20 22:36:56 +01:00
|
|
|
extern lv_style_t lv_style_btn_tgl_pr;
|
2017-11-20 14:26:18 +01:00
|
|
|
extern lv_style_t lv_style_btn_ina;
|
2017-10-30 17:31:48 +01:00
|
|
|
|
2017-04-13 10:20:35 +02:00
|
|
|
/**********************
|
|
|
|
* MACROS
|
|
|
|
**********************/
|
|
|
|
|
2019-07-15 15:01:50 +02:00
|
|
|
/**
|
|
|
|
* Create and initialize a `static` style
|
|
|
|
* Example:
|
|
|
|
* LV_STYLE_CREATE(my_style, &lv_style_plain);
|
|
|
|
* is equivalent to
|
|
|
|
* static lv_style_t my_style;
|
|
|
|
* lv_style_copy(my_style, &lv_style_plain);
|
|
|
|
*
|
|
|
|
* If the style to copy is `NULL` `lv_style_plain` will be used.
|
|
|
|
*/
|
|
|
|
#define LV_STYLE_CREATE(name, copy_p) static lv_style_t name; lv_style_copy(&name, copy_p == NULL ? &lv_style_plain : copy_p);
|
|
|
|
|
2017-07-09 15:32:49 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
} /* extern "C" */
|
2017-04-13 10:20:35 +02:00
|
|
|
#endif
|
2017-07-09 15:32:49 +02:00
|
|
|
|
2019-04-04 07:15:40 +02:00
|
|
|
#endif /*LV_STYLE_H*/
|