1
0
mirror of https://github.com/lvgl/lvgl.git synced 2025-01-14 06:42:58 +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:
Xiang Xiao 2021-03-24 03:29:56 -07:00 committed by GitHub
parent 85a7c5e66a
commit 5f993286a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 18 deletions

View File

@ -24,7 +24,7 @@
/**********************
* 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);
/**********************
@ -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);
uint32_t s = get_instance_size(class_p);
lv_obj_t * obj = lv_mem_alloc(s);
if(obj == NULL) return NULL;
lv_memset_00(obj, s);
obj->class_p = class_p;
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, parent, copy);
lv_obj_construct(obj, copy);
if(parent) {
/*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);
// 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);
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->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;
/*Call the base class's destructor too*/
@ -98,7 +95,7 @@ bool lv_obj_is_editable(struct _lv_obj_t * obj)
* 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;
@ -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;
/*Construct the base first*/
lv_obj_construct(obj, parent, copy);
lv_obj_construct(obj, copy);
}
/*Restore the original class*/
obj->class_p = original_class_p;
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)
{
/*Find a base in which instance size is set*/

View File

@ -1,5 +1,5 @@
/**
* @file struct _lv_obj_tree.h
* @file lv_obj_class.h
*
*/
@ -13,7 +13,7 @@ extern "C" {
/*********************
* INCLUDES
*********************/
#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>
/*********************
@ -28,7 +28,7 @@ extern "C" {
struct _lv_obj_t;
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_FALSE,
}lv_obj_class_editable_t;
@ -37,13 +37,13 @@ typedef enum {
* Describe the common methods of every object.
* 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;
void (*constructor_cb)(struct _lv_obj_t * obj, const struct _lv_obj_t * copy);
void (*destructor_cb)(struct _lv_obj_t * obj);
lv_event_cb_t event_cb; /**< Object type specific event function*/
uint32_t editable :2; /**< Value from ::lv_obj_class_editable_t*/
uint32_t instance_size :20;
uint32_t editable : 2; /**< Value from ::lv_obj_class_editable_t*/
uint32_t instance_size : 20;
}lv_obj_class_t;
/**********************
@ -52,7 +52,7 @@ typedef struct _lv_obj_class_t{
/**
* 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 copy pointer to an other object with the same type to copy (DEPRECATED will be removed in v9)
* @return pointer to the created object