1
0
mirror of https://github.com/lvgl/lvgl.git synced 2025-01-14 06:42:58 +08:00
lvgl/lv_obj/lv_obj.h

258 lines
7.9 KiB
C
Raw Normal View History

2016-06-08 07:25:08 +02:00
/**
* @file lv_base_obj.h
*
*/
#ifndef LV_OBJ_H
#define LV_OBJ_H
/*********************
* INCLUDES
*********************/
#include <lvgl/lv_misc/2d.h>
#include <stddef.h>
#include <stdbool.h>
#include "misc/mem/dyn_mem.h"
#include "misc/mem/linked_list.h"
#include "misc/others/color.h"
/*********************
* DEFINES
*********************/
/*Error check of lv_conf.h*/
#if LV_HOR_RES == 0 || LV_VER_RES == 0
#error "LV: LV_HOR_RES and LV_VER_RES must be greater then 0"
#endif
#if LV_DOWNSCALE != 1 && LV_DOWNSCALE != 2 && LV_DOWNSCALE != 4
#error "LV: LV_DOWNSCALE can be only 1, 2 or 4"
#endif
#if LV_VDB_SIZE == 0 && (LV_DOWNSCALE != 1 || LV_UPSCALE_MAP != 0 || LV_UPSCALE_FONT != 0 || LV_UPSCALE_STYLE != 0)
#error "LV: If LV_VDB_SIZE == 0 then LV_DOWNSCALE must be 1, LV_UPSCALE_MAP 0, LV_UPSCALE_FONT 0, LV_UPSCALE_STYLE 0"
#endif
/*New defines*/
#if LV_UPSCALE_SYTLE != 0
#define LV_STYLE_MULT LV_DOWNSCALE
#else
#define LV_STYLE_MULT 1
#endif
2016-06-15 09:38:20 +02:00
#define LV_OBJ_DEF_WIDTH (80 * LV_DOWNSCALE)
#define LV_OBJ_DEF_HEIGHT (60 * LV_DOWNSCALE)
2016-07-12 15:05:17 +02:00
#define ANIM_IN 0x00 /*Animation to show an object. 'OR' it with lv_anim_builtin_t*/
#define ANIM_OUT 0x80 /*Animation to hide an object. 'OR' it with lv_anim_builtin_t*/
#define ANIM_DIR_MASK 0x80 /*ANIM_IN/ANIM_OUT mask*/
2016-06-08 07:25:08 +02:00
/**********************
* TYPEDEFS
**********************/
struct __LV_OBJ_T;
typedef enum
{
LV_DESIGN_DRAW,
LV_DESIGN_COVER_CHK,
}lv_design_mode_t;
typedef bool (* lv_design_f_t) (struct __LV_OBJ_T* obj_dp, const area_t * mask_p, lv_design_mode_t mode);
typedef enum
{
LV_SIGNAL_CLEANUP,
LV_SIGNAL_PRESSED,
LV_SIGNAL_PRESS_LOST,
LV_SIGNAL_RELEASED,
LV_SIGNAL_LONG_PRESS,
LV_SIGNAL_DRAG_BEGIN,
LV_SIGNAL_DRAG_END,
LV_SIGNAL_CHILD_CHG,
LV_SIGNAL_CORD_CHG,
LV_SIGNAL_STYLE_CHG,
}lv_signal_t;
typedef bool (* lv_signal_f_t) (struct __LV_OBJ_T* obj_dp, lv_signal_t sign, void * param);
typedef struct __LV_OBJ_T
{
struct __LV_OBJ_T* par_dp;
ll_dsc_t child_ll;
area_t cords;
lv_signal_f_t signal_f;
lv_design_f_t design_f;
2016-06-08 07:25:08 +02:00
void * ext_dp; /*The object attributes can be extended here*/
void * style_p; /*Object specific style*/
#if LV_OBJ_FREE_P != 0
void * free_p; /*Application specific pointer (set it freely)*/
#endif
2016-06-08 07:25:08 +02:00
/*Attributes and states*/
uint8_t click_en :1; /*1: can be pressed by a display input device*/
uint8_t drag_en :1; /*1: enable the dragging*/
uint8_t drag_throw_en:1; /*1: Enable throwing with drag*/
uint8_t drag_parent :1; /*1. Parent will be dragged instead*/
uint8_t style_iso :1; /*1: The object has got an own style*/
uint8_t hidden :1; /*1: Object is hidden*/
uint8_t top_en :1; /*1: If the object or its children is clicked it goes to the foreground*/
uint8_t child_chg_off:1; /*1: Disable the child change signal. Useful when moving the children*/
opa_t opa;
2016-06-08 07:25:08 +02:00
uint8_t free_num; /*Application specific identifier (set it freely)*/
}lv_obj_t;
typedef enum
{
LV_ALIGN_CENTER = 0,
LV_ALIGN_IN_TOP_LEFT,
LV_ALIGN_IN_TOP_MID,
LV_ALIGN_IN_TOP_RIGHT,
LV_ALIGN_IN_BOTTOM_LEFT,
LV_ALIGN_IN_BOTTOM_MID,
LV_ALIGN_IN_BOTTOM_RIGHT,
LV_ALIGN_IN_LEFT_MID,
LV_ALIGN_IN_RIGHT_MID,
LV_ALIGN_OUT_TOP_LEFT,
LV_ALIGN_OUT_TOP_MID,
LV_ALIGN_OUT_TOP_RIGHT,
LV_ALIGN_OUT_BOTTOM_LEFT,
LV_ALIGN_OUT_BOTTOM_MID,
LV_ALIGN_OUT_BOTTOM_RIGHT,
LV_ALIGN_OUT_LEFT_TOP,
LV_ALIGN_OUT_LEFT_MID,
LV_ALIGN_OUT_LEFT_BOTTOM,
LV_ALIGN_OUT_RIGHT_TOP,
LV_ALIGN_OUT_RIGHT_MID,
LV_ALIGN_OUT_RIGHT_BOTTOM,
}lv_align_t;
2016-06-20 07:58:54 +02:00
2016-06-08 07:25:08 +02:00
typedef struct
{
color_t color;
2016-07-12 01:16:27 +02:00
uint8_t transp :1;
2016-06-08 07:25:08 +02:00
}lv_objs_t;
typedef enum
{
LV_OBJS_DEF,
LV_OBJS_SCR,
2016-07-12 01:16:27 +02:00
LV_OBJS_TRANSP,
2016-06-08 07:25:08 +02:00
}lv_objs_builtin_t;
2016-07-12 15:05:17 +02:00
typedef enum
{
LV_ANIM_NONE = 0,
2016-09-27 13:43:01 +02:00
LV_ANIM_FADE, /*Animate the opacity*/
LV_ANIM_FLOAT_TOP, /*Float from/to the top*/
LV_ANIM_FLOAT_LEFT, /*Float from/to the left*/
LV_ANIM_FLOAT_BOTTOM, /*Float from/to the bottom*/
LV_ANIM_FLOAT_RIGHT, /*Float from/to the right*/
LV_ANIM_GROW_H, /*Grow/shrink horizontally*/
LV_ANIM_GROW_V, /*Grow/shrink vertically*/
2016-07-12 15:05:17 +02:00
}lv_anim_builtin_t;
2016-06-08 07:25:08 +02:00
/**********************
* GLOBAL PROTOTYPES
**********************/
void lv_init(void);
void lv_obj_inv(lv_obj_t* obj_dp);
void lv_obj_refr_style(lv_obj_t* obj_dp);
void lv_style_refr_all(void * style_p);
/*Create and delete*/
lv_obj_t* lv_obj_create(lv_obj_t* parent_dp, lv_obj_t * copy_dp);
void lv_obj_del(lv_obj_t* obj_dp);
/*Virtual functions*/
bool lv_obj_signal(lv_obj_t* obj_dp, lv_signal_t sign, void * param);
/*SETTER FUNCTIONS*/
/*Parent/children set*/
void lv_obj_set_parent(lv_obj_t* obj_dp, lv_obj_t* parent_dp);
/*Coordinate set (set_cord_f will be called)*/
void lv_obj_set_pos(lv_obj_t* obj_dp, cord_t x, cord_t y);
void lv_obj_set_pos_us(lv_obj_t* obj_dp, cord_t x, cord_t y);
void lv_obj_set_x(lv_obj_t* obj_dp, cord_t x);
void lv_obj_set_x_us(lv_obj_t* obj_dp, cord_t x);
void lv_obj_set_y(lv_obj_t* obj_dp, cord_t y);
void lv_obj_set_y_us(lv_obj_t* obj_dp, cord_t y);
void lv_obj_set_size(lv_obj_t* obj_dp, cord_t w, cord_t h);
void lv_obj_set_size_us(lv_obj_t* obj_dp, cord_t w, cord_t h);
void lv_obj_set_width(lv_obj_t* obj_dp, cord_t w);
void lv_obj_set_width_us(lv_obj_t* obj_dp, cord_t w);
void lv_obj_set_height(lv_obj_t* obj_dp, cord_t h);
void lv_obj_set_height_us(lv_obj_t* obj_dp, cord_t h);
void lv_obj_align(lv_obj_t* obj_dp,lv_obj_t* base_dp, lv_align_t align, cord_t x_mod, cord_t y_mod);
void lv_obj_align_us(lv_obj_t* obj_dp,lv_obj_t* base_dp, lv_align_t align, cord_t x_mod, cord_t y_mod);
/*Appearance set*/
void lv_obj_set_hidden(lv_obj_t* obj_dp, bool hidden_en);
void lv_obj_set_opa(lv_obj_t* obj_dp, opa_t opa);
void lv_obj_set_opar(lv_obj_t* obj_dp, opa_t opa);
/*Attribute set*/
void lv_obj_set_click(lv_obj_t* obj_dp, bool click_en);
void lv_obj_set_top(lv_obj_t* obj_dp, bool click_en);
void lv_obj_set_drag(lv_obj_t* obj_dp, bool drag_en);
void lv_obj_set_drag_throw(lv_obj_t* obj_dp, bool dragthr_en);
void lv_obj_set_drag_parent(lv_obj_t* obj_dp, bool dragpar_en);
void lv_obj_set_signal_f(lv_obj_t* obj_dp, lv_signal_f_t fp);
void lv_obj_set_design_f(lv_obj_t* obj_dp, lv_design_f_t fp);
/*Other set*/
void * lv_obj_alloc_ext(lv_obj_t* obj_dp, uint16_t ext_size);
void lv_obj_set_style(lv_obj_t* obj_dp, void * style_p);
void * lv_obj_iso_style(lv_obj_t * obj_dp, uint32_t style_size);
void lv_obj_set_free_num(lv_obj_t* obj_dp, uint8_t free_num);
void lv_obj_set_free_p(lv_obj_t* obj_dp, void * free_p);
2016-07-12 15:05:17 +02:00
void lv_obj_anim(lv_obj_t * obj_dp, lv_anim_builtin_t anim, uint16_t time, uint16_t delay, void (*cb) (lv_obj_t *));
2016-06-08 07:25:08 +02:00
/*GETTER FUNCTIONS*/
/*Screen get*/
lv_obj_t* lv_scr_act(void);
void lv_scr_load(lv_obj_t* scr_dp);
/*Parent/children get*/
lv_obj_t* lv_obj_get_scr(lv_obj_t* obj_dp);
lv_obj_t* lv_obj_get_parent(lv_obj_t* obj_dp);
lv_obj_t * lv_obj_get_child(lv_obj_t * obj_dp, lv_obj_t * child_dp);
/*Coordinate get*/
void lv_obj_get_cords(lv_obj_t* obj_dp, area_t * cords_p);
cord_t lv_obj_get_x(lv_obj_t* obj_dp);
cord_t lv_obj_get_y(lv_obj_t* obj_dp);
cord_t lv_obj_get_width(lv_obj_t* obj_dp);
cord_t lv_obj_get_height(lv_obj_t* obj_dp);
/*Appearance get*/
bool lv_obj_get_hidden(lv_obj_t* obj_dp);
opa_t lv_obj_get_opa(lv_obj_t* obj_dp);
/*Attribute get*/
bool lv_obj_get_click(lv_obj_t* obj_dp);
bool lv_obj_get_top(lv_obj_t* obj_dp);
bool lv_obj_get_drag(lv_obj_t* obj_dp);
bool lv_obj_get_drag_throw(lv_obj_t* obj_dp);
bool lv_obj_get_drag_parent(lv_obj_t* obj_dp);
/*Virtual functions get*/
lv_design_f_t lv_obj_get_design_f(lv_obj_t* obj_dp);
lv_signal_f_t lv_obj_get_signal_f(lv_obj_t* obj_dp);
/*Other get*/
void * lv_obj_get_ext(lv_obj_t* obj_dp);
void * lv_obj_get_style(lv_obj_t* obj_dp);
uint8_t lv_obj_get_free_num(lv_obj_t* obj_dp);
lv_objs_t * lv_objs_get(lv_objs_builtin_t style, lv_objs_t * copy_p);
/**********************
* MACROS
**********************/
#define LV_SA(obj_dp, style_type) ((style_type *) obj_dp->style_p)
2016-09-30 13:35:54 +02:00
#define LV_EA(obj_dp, ext_type) ((ext_type *) obj_dp->ext_dp)
2016-06-08 07:25:08 +02:00
#endif