BigW Consortium Gitlab

Commit ab21e705 by Gabor

lv_group: add lv_group.c,h

parent 4fd0dfc7
/**
* @file lv_group.c
*
*/
/*********************
* INCLUDES
*********************/
#include <stddef.h>
#include "lv_group.h"
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
static void style_activate_def(lv_style_t * style);
/**********************
* STATIC VARIABLES
**********************/
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
lv_group_t * lv_group_create(void)
{
lv_group_t * group = dm_alloc(sizeof(lv_group_t));
ll_init(&group->obj_ll, sizeof(lv_obj_t *));
group->style_activate = style_activate_def;
group->actve_obj = NULL;
return group;
}
void lv_group_add(lv_group_t * group, lv_obj_t * obj)
{
obj->group_p = group;
lv_obj_t ** next = ll_ins_tail(&group->obj_ll);
*next = obj;
}
void lv_group_activate_obj(lv_group_t * group, lv_obj_t * obj)
{
}
void lv_group_set_style_cb(lv_group_t * group, void (*style_cb)(lv_style_t * style))
{
group->style_activate = style_cb;
}
void lv_group_activate_next(lv_group_t * group)
{
if(group->actve_obj != NULL) lv_obj_inv(*group->actve_obj);
lv_obj_t ** obj_next;
if(group->actve_obj == NULL) obj_next = ll_get_head(&group->obj_ll);
else obj_next = ll_get_next(&group->obj_ll, group->actve_obj);
if(obj_next == NULL) obj_next = ll_get_head(&group->obj_ll);
group->actve_obj = obj_next;
if(group->actve_obj != NULL) lv_obj_inv(*group->actve_obj);
}
void lv_group_activate_prev(lv_group_t * group)
{
if(group->actve_obj != NULL) lv_obj_inv(*group->actve_obj);
lv_obj_t ** obj_next;
if(group->actve_obj == NULL) obj_next = ll_get_tail(&group->obj_ll);
else obj_next = ll_get_prev(&group->obj_ll, group->actve_obj);
if(obj_next == NULL) obj_next = ll_get_tail(&group->obj_ll);
group->actve_obj = obj_next;
if(group->actve_obj != NULL) lv_obj_inv(*group->actve_obj);
}
/**********************
* STATIC FUNCTIONS
**********************/
static void style_activate_def(lv_style_t * style)
{
style->bcolor = COLOR_ORANGE;
style->bopa = OPA_COVER;
style->bwidth = style->bwidth * 2;
style->mcolor = color_mix(style->mcolor, COLOR_ORANGE, OPA_80);
style->gcolor = color_mix(style->gcolor, COLOR_ORANGE, OPA_80);
}
/**
* @file lv_group.h
*
*/
#ifndef LV_GROUP_H
#define LV_GROUP_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#include "lv_obj.h"
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
typedef struct
{
ll_dsc_t obj_ll;
lv_obj_t ** actve_obj;
void (*style_activate)(lv_style_t * style);
lv_style_t style_tmp;
}lv_group_t;
/**********************
* GLOBAL PROTOTYPES
**********************/
lv_group_t * lv_group_create(void);
void lv_group_add(lv_group_t * group, lv_obj_t * obj);
void lv_group_activate_obj(lv_group_t * group, lv_obj_t * obj);
void lv_group_activate_next(lv_group_t * group);
void lv_group_activate_prev(lv_group_t * group);
/**********************
* MACROS
**********************/
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /*LV_GROUP_H*/
......@@ -12,6 +12,7 @@
#include "lvgl/lv_obj/lv_dispi.h"
#include "lvgl/lv_obj/lv_obj.h"
#include "lvgl/lv_obj/lv_refr.h"
#include "lvgl/lv_obj/lv_group.h"
#include "lvgl/lv_app/lv_app.h"
#include "lvgl/lv_draw/lv_draw_rbasic.h"
#include "misc/gfx/anim.h"
......@@ -1234,20 +1235,35 @@ cord_t lv_obj_get_ext_size(lv_obj_t * obj)
*/
lv_style_t * lv_obj_get_style(lv_obj_t * obj)
{
if(obj->style_p != NULL) return obj->style_p;
else {
lv_style_t * style_act = obj->style_p;
if(style_act == NULL) {
lv_obj_t * par = obj->par;
while(par != NULL) {
if(par->style_p != NULL) {
if(par->style_p->glass == 0) return par->style_p;
if(par->style_p->glass == 0) {
style_act = par->style_p;
break;
}
}
par = par->par;
}
}
/*Never reach this, at least the screen has to be a style*/
return NULL;
if(obj->group_p != NULL) {
lv_obj_t * active_obj = NULL;
if(((lv_group_t *)obj->group_p)->actve_obj != NULL) {
active_obj = *((lv_group_t *)obj->group_p)->actve_obj;
}
if(active_obj == obj) {
lv_style_cpy(&((lv_group_t *)obj->group_p)->style_tmp, style_act);
((lv_group_t *)obj->group_p)->style_activate(&((lv_group_t *)obj->group_p)->style_tmp);
style_act = &((lv_group_t *)obj->group_p)->style_tmp;
}
}
return style_act;
}
/*-----------------
......
......@@ -106,6 +106,8 @@ typedef struct __LV_OBJ_T
void * free_p; /*Application specific pointer (set it freely)*/
#endif
void * group_p; /*Pointer to the group of the object*/
/*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*/
......@@ -159,13 +161,6 @@ typedef enum
LV_ALIGN_OUT_RIGHT_BOTTOM,
}lv_align_t;
typedef struct
{
color_t color;
opa_t opa;
}lv_objs_t;
typedef enum
{
LV_ANIM_NONE = 0,
......@@ -473,6 +468,7 @@ void lv_obj_set_free_num(lv_obj_t * obj, uint8_t free_num);
*/
void lv_obj_set_free_p(lv_obj_t * obj, void * free_p);
#endif
/**
* Animate an object
* @param obj pointer to an object to animate
......
......@@ -17,6 +17,7 @@ extern "C" {
/*Test misc. module version*/
#include "misc/misc.h"
#include "lv_obj/lv_obj.h"
#include "lv_obj/lv_group.h"
#include "lv_objx/lv_btn.h"
#include "lv_objx/lv_img.h"
#include "lv_objx/lv_label.h"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment