mirror of
https://github.com/lvgl/lvgl.git
synced 2025-01-28 07:03:00 +08:00
minor fix for obj class (#2154)
* fix(class): correct the typo error in comment * fix(class): return directly if the memory allocation fail * fix(class): remove the unused code * fix(class): remove parent argument from lv_obj_construct since this argumnet is really used * fix(class): replace stddef.h with stdint.h since uint32_t is defined in stdint.h
This commit is contained in:
parent
85a7c5e66a
commit
5f993286a2
@ -24,7 +24,7 @@
|
|||||||
/**********************
|
/**********************
|
||||||
* STATIC PROTOTYPES
|
* STATIC PROTOTYPES
|
||||||
**********************/
|
**********************/
|
||||||
static void lv_obj_construct(lv_obj_t * obj, lv_obj_t * parent, const lv_obj_t * copy);
|
static void lv_obj_construct(lv_obj_t * obj, const lv_obj_t * copy);
|
||||||
static uint32_t get_instance_size(const lv_obj_class_t * class_p);
|
static uint32_t get_instance_size(const lv_obj_class_t * class_p);
|
||||||
|
|
||||||
/**********************
|
/**********************
|
||||||
@ -44,14 +44,12 @@ lv_obj_t * lv_obj_create_from_class(const lv_obj_class_t * class_p, lv_obj_t * p
|
|||||||
LV_TRACE_OBJ_CREATE("Creating object with %p class on %p parent", class_p, parent);
|
LV_TRACE_OBJ_CREATE("Creating object with %p class on %p parent", class_p, parent);
|
||||||
uint32_t s = get_instance_size(class_p);
|
uint32_t s = get_instance_size(class_p);
|
||||||
lv_obj_t * obj = lv_mem_alloc(s);
|
lv_obj_t * obj = lv_mem_alloc(s);
|
||||||
|
if(obj == NULL) return NULL;
|
||||||
lv_memset_00(obj, s);
|
lv_memset_00(obj, s);
|
||||||
obj->class_p = class_p;
|
obj->class_p = class_p;
|
||||||
obj->parent = parent;
|
obj->parent = parent;
|
||||||
const lv_obj_class_t * class_start = class_p;
|
|
||||||
|
|
||||||
while(class_start && class_start->constructor_cb == NULL) class_start = class_start->base_class;
|
lv_obj_construct(obj, copy);
|
||||||
|
|
||||||
lv_obj_construct(obj, parent, copy);
|
|
||||||
|
|
||||||
if(parent) {
|
if(parent) {
|
||||||
/*Send a Call the ancestor's event handler to the parent to notify it about the new child.
|
/*Send a Call the ancestor's event handler to the parent to notify it about the new child.
|
||||||
@ -63,7 +61,6 @@ lv_obj_t * lv_obj_create_from_class(const lv_obj_class_t * class_p, lv_obj_t * p
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(!copy) lv_theme_apply(obj);
|
if(!copy) lv_theme_apply(obj);
|
||||||
// else lv_style_list_copy(&checkbox->style_indic, &checkbox_copy->style_indic);
|
|
||||||
|
|
||||||
LV_TRACE_OBJ_CREATE("Object created at %p address with %p class on %p parent", obj, class_p, parent);
|
LV_TRACE_OBJ_CREATE("Object created at %p address with %p class on %p parent", obj, class_p, parent);
|
||||||
return obj;
|
return obj;
|
||||||
@ -74,7 +71,7 @@ void _lv_obj_destruct(lv_obj_t * obj)
|
|||||||
if(obj->class_p->destructor_cb) obj->class_p->destructor_cb(obj);
|
if(obj->class_p->destructor_cb) obj->class_p->destructor_cb(obj);
|
||||||
|
|
||||||
if(obj->class_p->base_class) {
|
if(obj->class_p->base_class) {
|
||||||
/*Don't let the descendant methods run during constructing the ancestor type*/
|
/*Don't let the descendant methods run during destructing the ancestor type*/
|
||||||
obj->class_p = obj->class_p->base_class;
|
obj->class_p = obj->class_p->base_class;
|
||||||
|
|
||||||
/*Call the base class's destructor too*/
|
/*Call the base class's destructor too*/
|
||||||
@ -98,7 +95,7 @@ bool lv_obj_is_editable(struct _lv_obj_t * obj)
|
|||||||
* STATIC FUNCTIONS
|
* STATIC FUNCTIONS
|
||||||
**********************/
|
**********************/
|
||||||
|
|
||||||
static void lv_obj_construct(lv_obj_t * obj, lv_obj_t * parent, const lv_obj_t * copy)
|
static void lv_obj_construct(lv_obj_t * obj, const lv_obj_t * copy)
|
||||||
{
|
{
|
||||||
const lv_obj_class_t * original_class_p = obj->class_p;
|
const lv_obj_class_t * original_class_p = obj->class_p;
|
||||||
|
|
||||||
@ -107,16 +104,15 @@ static void lv_obj_construct(lv_obj_t * obj, lv_obj_t * parent, const lv_obj_t *
|
|||||||
obj->class_p = obj->class_p->base_class;
|
obj->class_p = obj->class_p->base_class;
|
||||||
|
|
||||||
/*Construct the base first*/
|
/*Construct the base first*/
|
||||||
lv_obj_construct(obj, parent, copy);
|
lv_obj_construct(obj, copy);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*Restore the original class*/
|
/*Restore the original class*/
|
||||||
obj->class_p = original_class_p;
|
obj->class_p = original_class_p;
|
||||||
|
|
||||||
if(obj->class_p->constructor_cb) obj->class_p->constructor_cb(obj, copy);
|
if(obj->class_p->constructor_cb) obj->class_p->constructor_cb(obj, copy);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint32_t get_instance_size(const lv_obj_class_t * class_p)
|
static uint32_t get_instance_size(const lv_obj_class_t * class_p)
|
||||||
{
|
{
|
||||||
/*Find a base in which instance size is set*/
|
/*Find a base in which instance size is set*/
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* @file struct _lv_obj_tree.h
|
* @file lv_obj_class.h
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -13,7 +13,7 @@ extern "C" {
|
|||||||
/*********************
|
/*********************
|
||||||
* INCLUDES
|
* INCLUDES
|
||||||
*********************/
|
*********************/
|
||||||
#include <stddef.h>
|
#include <stdint.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
/*********************
|
/*********************
|
||||||
@ -28,7 +28,7 @@ extern "C" {
|
|||||||
struct _lv_obj_t;
|
struct _lv_obj_t;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
LV_OBJ_CLASS_EDITABLE_INHERIT, /**< Check the base class. Must have 0 value to let he zero initialized class inherit*/
|
LV_OBJ_CLASS_EDITABLE_INHERIT, /**< Check the base class. Must have 0 value to let zero initialized class inherit*/
|
||||||
LV_OBJ_CLASS_EDITABLE_TRUE,
|
LV_OBJ_CLASS_EDITABLE_TRUE,
|
||||||
LV_OBJ_CLASS_EDITABLE_FALSE,
|
LV_OBJ_CLASS_EDITABLE_FALSE,
|
||||||
}lv_obj_class_editable_t;
|
}lv_obj_class_editable_t;
|
||||||
@ -37,13 +37,13 @@ typedef enum {
|
|||||||
* Describe the common methods of every object.
|
* Describe the common methods of every object.
|
||||||
* Similar to a C++ class.
|
* Similar to a C++ class.
|
||||||
*/
|
*/
|
||||||
typedef struct _lv_obj_class_t{
|
typedef struct _lv_obj_class_t {
|
||||||
const struct _lv_obj_class_t * base_class;
|
const struct _lv_obj_class_t * base_class;
|
||||||
void (*constructor_cb)(struct _lv_obj_t * obj, const struct _lv_obj_t * copy);
|
void (*constructor_cb)(struct _lv_obj_t * obj, const struct _lv_obj_t * copy);
|
||||||
void (*destructor_cb)(struct _lv_obj_t * obj);
|
void (*destructor_cb)(struct _lv_obj_t * obj);
|
||||||
lv_event_cb_t event_cb; /**< Object type specific event function*/
|
lv_event_cb_t event_cb; /**< Object type specific event function*/
|
||||||
uint32_t editable :2; /**< Value from ::lv_obj_class_editable_t*/
|
uint32_t editable : 2; /**< Value from ::lv_obj_class_editable_t*/
|
||||||
uint32_t instance_size :20;
|
uint32_t instance_size : 20;
|
||||||
}lv_obj_class_t;
|
}lv_obj_class_t;
|
||||||
|
|
||||||
/**********************
|
/**********************
|
||||||
@ -52,7 +52,7 @@ typedef struct _lv_obj_class_t{
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Create an object form a class descriptor
|
* Create an object form a class descriptor
|
||||||
* @param class_p pointer to a class
|
* @param class_p pointer to a class
|
||||||
* @param parent pointer to an object where the new object should be created
|
* @param parent pointer to an object where the new object should be created
|
||||||
* @param copy pointer to an other object with the same type to copy (DEPRECATED will be removed in v9)
|
* @param copy pointer to an other object with the same type to copy (DEPRECATED will be removed in v9)
|
||||||
* @return pointer to the created object
|
* @return pointer to the created object
|
||||||
|
Loading…
x
Reference in New Issue
Block a user