mirror of
https://github.com/lvgl/lvgl.git
synced 2026-10-02 10:23:47 +08:00
feat: introduces LV_CHECK_ARG (#9986)
Co-authored-by: André Costa <andre_miguel_costa@hotmail.com>
This commit is contained in:
co-authored by
André Costa
parent
1e12358523
commit
78f2b5139d
@@ -745,6 +745,9 @@ menu "LVGL configuration"
|
||||
When enabled, LV_CHECK_ARG checks validate function arguments
|
||||
at runtime. Failed checks log a warning and execute the specified
|
||||
action. When disabled, all LV_CHECK_ARG checks compile to nothing.
|
||||
Disabling this is not recommended unless extreme care is taken and only
|
||||
in very resource constrained environments where it can be absolutely
|
||||
ensured that invariants are never violated.
|
||||
|
||||
config LV_CHECK_ARG_ASSERT_ON_FAIL
|
||||
bool "Call assert handler on LV_CHECK_ARG failure"
|
||||
@@ -753,6 +756,36 @@ menu "LVGL configuration"
|
||||
help
|
||||
When enabled, LV_ASSERT_HANDLER is also invoked when an
|
||||
LV_CHECK_ARG check fails, before the action is executed.
|
||||
|
||||
choice
|
||||
prompt "Log behavior on LV_CHECK_ARG failure"
|
||||
depends on LV_USE_CHECK_ARG
|
||||
default LV_CHECK_ARG_LOG_MODE_VERBOSE if LV_USE_LOG
|
||||
default LV_CHECK_ARG_LOG_MODE_NONE if !LV_USE_LOG
|
||||
help
|
||||
Controls what is logged when an LV_CHECK_ARG check fails.
|
||||
MINIMAL and VERBOSE modes require LV_USE_LOG to be enabled;
|
||||
selecting either when LV_USE_LOG is disabled will cause a
|
||||
compile-time error.
|
||||
|
||||
config LV_CHECK_ARG_LOG_MODE_NONE
|
||||
bool "None: no log output on failure"
|
||||
|
||||
config LV_CHECK_ARG_LOG_MODE_MINIMAL
|
||||
bool "Minimal: log 'Check failed' only (file/line from LV_LOG_WARN)"
|
||||
depends on LV_USE_LOG
|
||||
|
||||
config LV_CHECK_ARG_LOG_MODE_VERBOSE
|
||||
bool "Verbose: log 'Check failed: <cond>' plus caller-supplied message"
|
||||
depends on LV_USE_LOG
|
||||
endchoice
|
||||
|
||||
config LV_CHECK_ARG_LOG_MODE
|
||||
int
|
||||
depends on LV_USE_CHECK_ARG
|
||||
default 0 if LV_CHECK_ARG_LOG_MODE_NONE
|
||||
default 1 if LV_CHECK_ARG_LOG_MODE_MINIMAL
|
||||
default 2 if LV_CHECK_ARG_LOG_MODE_VERBOSE
|
||||
endmenu
|
||||
|
||||
menu "Debug"
|
||||
|
||||
@@ -45,6 +45,10 @@
|
||||
#define LV_NANOVG_BACKEND_GLES2 3
|
||||
#define LV_NANOVG_BACKEND_GLES3 4
|
||||
|
||||
#define LV_CHECK_ARG_LOG_MODE_NONE 0
|
||||
#define LV_CHECK_ARG_LOG_MODE_MINIMAL 1
|
||||
#define LV_CHECK_ARG_LOG_MODE_VERBOSE 2
|
||||
|
||||
/** Handle special Kconfig options. */
|
||||
#ifndef LV_KCONFIG_IGNORE
|
||||
#include "lv_conf_kconfig.h"
|
||||
@@ -424,7 +428,7 @@
|
||||
#define LV_USE_DRAW_SW 1
|
||||
#endif
|
||||
#endif
|
||||
#if LV_USE_DRAW_SW == 1
|
||||
#if LV_USE_DRAW_SW
|
||||
/*
|
||||
* Selectively disable color format support in order to reduce code size.
|
||||
* NOTE: some features use certain color formats internally, e.g.
|
||||
@@ -1500,8 +1504,13 @@
|
||||
* Check arg
|
||||
*-----------*/
|
||||
|
||||
/** Enable LV_CHECK_ARG macro to validate function arguments at runtime.
|
||||
* When enabled, failed checks log a warning and execute the specified action.
|
||||
/** When enabled, LV_CHECK_ARG checks validate function arguments
|
||||
* at runtime. Failed checks log a warning and execute the specified
|
||||
* action. When disabled, all LV_CHECK_ARG checks compile to nothing.
|
||||
* Disabling this is not recommended unless extreme care is taken and only
|
||||
* in very resource constrained environments where it can be absolutely
|
||||
* ensured that invariants are never violated.
|
||||
*
|
||||
* 0: Disable all LV_CHECK_ARG checks (checks compile to nothing)
|
||||
* 1: Enable LV_CHECK_ARG checks */
|
||||
#ifndef LV_USE_CHECK_ARG
|
||||
@@ -1516,13 +1525,32 @@
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/** If enabled, also call LV_ASSERT_HANDLER when an LV_CHECK_ARG check fails.
|
||||
* Requires LV_USE_CHECK_ARG to be enabled. */
|
||||
#ifndef LV_CHECK_ARG_ASSERT_ON_FAIL
|
||||
#ifdef CONFIG_LV_CHECK_ARG_ASSERT_ON_FAIL
|
||||
#define LV_CHECK_ARG_ASSERT_ON_FAIL CONFIG_LV_CHECK_ARG_ASSERT_ON_FAIL
|
||||
#else
|
||||
#define LV_CHECK_ARG_ASSERT_ON_FAIL 0
|
||||
#if LV_USE_CHECK_ARG
|
||||
/** If enabled, also call LV_ASSERT_HANDLER when an LV_CHECK_ARG check fails.
|
||||
* Requires LV_USE_CHECK_ARG to be enabled. */
|
||||
#ifndef LV_CHECK_ARG_ASSERT_ON_FAIL
|
||||
#ifdef CONFIG_LV_CHECK_ARG_ASSERT_ON_FAIL
|
||||
#define LV_CHECK_ARG_ASSERT_ON_FAIL CONFIG_LV_CHECK_ARG_ASSERT_ON_FAIL
|
||||
#else
|
||||
#define LV_CHECK_ARG_ASSERT_ON_FAIL 0
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if LV_USE_LOG
|
||||
/** Controls what is logged when an LV_CHECK_ARG check fails.
|
||||
* Any mode other than NONE also requires LV_USE_LOG; if LV_USE_LOG is 0
|
||||
* no output is produced regardless of this setting.
|
||||
*
|
||||
* LV_CHECK_ARG_LOG_MODE_NONE (0): No log output.
|
||||
* LV_CHECK_ARG_LOG_MODE_MINIMAL (1): Log "Check failed" only (file/line from LV_LOG_WARN).
|
||||
* LV_CHECK_ARG_LOG_MODE_VERBOSE (2): Log "Check failed: <cond>" plus caller-supplied message. */
|
||||
#ifndef LV_CHECK_ARG_LOG_MODE
|
||||
#ifdef CONFIG_LV_CHECK_ARG_LOG_MODE
|
||||
#define LV_CHECK_ARG_LOG_MODE CONFIG_LV_CHECK_ARG_LOG_MODE
|
||||
#else
|
||||
#define LV_CHECK_ARG_LOG_MODE LV_CHECK_ARG_LOG_MODE_VERBOSE
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -5026,4 +5054,8 @@ LV_EXPORT_CONST_INT(LV_DRAW_BUF_ALIGN);
|
||||
#endif
|
||||
#endif /*defined(LV_CONF_SKIP)*/
|
||||
|
||||
#ifndef LV_CHECK_ARG_LOG_MODE
|
||||
#define LV_CHECK_ARG_LOG_MODE 0
|
||||
#endif
|
||||
|
||||
#endif /*LV_CONF_INTERNAL_H*/
|
||||
|
||||
@@ -57,9 +57,9 @@ lv_obj_t * lv_obj_class_create_obj(const lv_obj_class_t * class_p, lv_obj_t * pa
|
||||
|
||||
void lv_obj_class_init_obj(lv_obj_t * obj);
|
||||
|
||||
bool lv_obj_is_editable(lv_obj_t * obj);
|
||||
bool lv_obj_is_editable(const lv_obj_t * obj);
|
||||
|
||||
bool lv_obj_is_group_def(lv_obj_t * obj);
|
||||
bool lv_obj_is_group_def(const lv_obj_t * obj);
|
||||
|
||||
#if LV_USE_EXT_DATA
|
||||
/**
|
||||
|
||||
@@ -151,20 +151,20 @@ lv_obj_t * lv_obj_get_child_by_type(const lv_obj_t * obj, int32_t idx,
|
||||
|
||||
/**
|
||||
* Return a sibling of an object
|
||||
* @param obj pointer to an object whose sibling should be get
|
||||
* @param obj pointer to an object whose sibling should be get. The object needs to be registered as a child of its parent.
|
||||
* @param idx 0: `obj` itself
|
||||
* -1: the first older sibling
|
||||
* -2: the next older sibling
|
||||
* 1: the first younger sibling
|
||||
* 2: the next younger sibling
|
||||
* etc
|
||||
* @return pointer to the requested sibling or NULL if there is no such sibling
|
||||
* @return pointer to the requested sibling or NULL if there is no such sibling - would navigate outside the array of children using the index (get the -3rd sibling of the second child of the parent)
|
||||
*/
|
||||
lv_obj_t * lv_obj_get_sibling(const lv_obj_t * obj, int32_t idx);
|
||||
|
||||
/**
|
||||
* Return a sibling of an object. Consider the siblings only with a given type.
|
||||
* @param obj pointer to an object whose sibling should be get
|
||||
* @param obj pointer to an object whose sibling should be get. The object needs to be registered as a child of its parent.
|
||||
* @param idx 0: `obj` itself
|
||||
* -1: the first older sibling
|
||||
* -2: the next older sibling
|
||||
@@ -172,7 +172,7 @@ lv_obj_t * lv_obj_get_sibling(const lv_obj_t * obj, int32_t idx);
|
||||
* 2: the next younger sibling
|
||||
* etc
|
||||
* @param class_p the type of the children to check
|
||||
* @return pointer to the requested sibling or NULL if there is no such sibling
|
||||
* @return pointer to the requested sibling or NULL if there is no such sibling or would navigate outside the array of children using the index (get the -3rd sibling of the second child of the parent)
|
||||
*/
|
||||
lv_obj_t * lv_obj_get_sibling_by_type(const lv_obj_t * obj, int32_t idx,
|
||||
const lv_obj_class_t * class_p);
|
||||
|
||||
@@ -231,7 +231,7 @@ const char * lv_subject_get_string(lv_subject_t * subject);
|
||||
* @param subject pointer to Subject
|
||||
* @return pointer to buffer containing previous value
|
||||
* @note NULL will be returned if NULL was passed in `lv_subject_init_string()`
|
||||
* as `prev_buf`.
|
||||
* as `prev_buf` or if `subject` is NULL or not of string type.
|
||||
*/
|
||||
const char * lv_subject_get_previous_string(lv_subject_t * subject);
|
||||
|
||||
|
||||
@@ -43,50 +43,60 @@ extern "C" {
|
||||
|
||||
#if LV_USE_CHECK_ARG
|
||||
|
||||
#if LV_CHECK_ARG_ASSERT_ON_FAIL
|
||||
/*----------------------------------------------------------------------
|
||||
* Internal helper: assert handler
|
||||
* Expands to LV_ASSERT_HANDLER when LV_CHECK_ARG_ASSERT_ON_FAIL is set,
|
||||
* otherwise to a no-op.
|
||||
*---------------------------------------------------------------------*/
|
||||
# if LV_CHECK_ARG_ASSERT_ON_FAIL
|
||||
# define LV_CHECK_ARG_ASSERT_HANDLER_ LV_ASSERT_HANDLER
|
||||
# else
|
||||
# define LV_CHECK_ARG_ASSERT_HANDLER_ do {} while(0)
|
||||
# endif
|
||||
|
||||
/**
|
||||
* Internal macro: checks a condition, logs a warning, calls the assert handler,
|
||||
* and then executes the specified action on failure.
|
||||
/*----------------------------------------------------------------------
|
||||
* Internal helper: log output
|
||||
* Controlled by LV_CHECK_ARG_LOG_MODE.
|
||||
* In all modes the macro accepts (cond_str, ...) so that
|
||||
* LV_CHECK_ARG_INTERNAL_ can call it uniformly.
|
||||
*---------------------------------------------------------------------*/
|
||||
# if LV_CHECK_ARG_LOG_MODE == LV_CHECK_ARG_LOG_MODE_VERBOSE
|
||||
# define LV_CHECK_ARG_LOG_(cond_str, ...) LV_LOG_WARN("Check failed: " cond_str " " __VA_ARGS__)
|
||||
# elif LV_CHECK_ARG_LOG_MODE == LV_CHECK_ARG_LOG_MODE_MINIMAL
|
||||
# define LV_CHECK_ARG_LOG_(cond_str, ...) LV_LOG_WARN("Check failed")
|
||||
# else /* LV_CHECK_ARG_LOG_MODE_NONE */
|
||||
# define LV_CHECK_ARG_LOG_(cond_str, ...) do {} while(0)
|
||||
# endif
|
||||
|
||||
/*----------------------------------------------------------------------
|
||||
* Internal macro: single definition, behaviour driven by the helpers above.
|
||||
* Do not use directly; use LV_CHECK_ARG instead.
|
||||
*/
|
||||
#define LV_CHECK_ARG_INTERNAL_(cond, cond_str, action_on_fail, ...) \
|
||||
if(LV_UNLIKELY(!(cond))) { \
|
||||
LV_LOG_WARN("Check failed: " cond_str " " __VA_ARGS__); \
|
||||
LV_ASSERT_HANDLER \
|
||||
action_on_fail; \
|
||||
*---------------------------------------------------------------------*/
|
||||
# define LV_CHECK_ARG_INTERNAL_(cond, cond_str, action_on_fail, ...) \
|
||||
if(LV_UNLIKELY(!(cond))) { \
|
||||
LV_CHECK_ARG_LOG_(cond_str, __VA_ARGS__); \
|
||||
LV_CHECK_ARG_ASSERT_HANDLER_; \
|
||||
action_on_fail; \
|
||||
} else {}
|
||||
|
||||
#else
|
||||
|
||||
/**
|
||||
* Internal macro: checks a condition, logs a warning, and executes the
|
||||
* specified action on failure.
|
||||
* Do not use directly; use LV_CHECK_ARG instead.
|
||||
*/
|
||||
#define LV_CHECK_ARG_INTERNAL_(cond, cond_str, action_on_fail, ...) \
|
||||
if(LV_UNLIKELY(!(cond))) { \
|
||||
LV_LOG_WARN("Check failed: " cond_str " " __VA_ARGS__); \
|
||||
action_on_fail; \
|
||||
} else {}
|
||||
|
||||
#endif /*LV_CHECK_ARG_ASSERT_ON_FAIL*/
|
||||
|
||||
#else
|
||||
|
||||
/** LV_CHECK_ARG is disabled; all checks compile to nothing. */
|
||||
#define LV_CHECK_ARG_INTERNAL_(cond, cond_str, action_on_fail, ...) ((void)0)
|
||||
# define LV_CHECK_ARG_INTERNAL_(cond, cond_str, action_on_fail, ...) ((void)0)
|
||||
|
||||
#endif /*LV_USE_CHECK_ARG*/
|
||||
|
||||
/**
|
||||
* Check that a condition is true. If the condition is false, log a warning
|
||||
* and execute `action_on_fail` (e.g. `return`, `return val`, `break`).
|
||||
* Additional printf-style arguments are appended to the log message.
|
||||
* Additional printf-style arguments are appended to the log message when
|
||||
* LV_CHECK_ARG_LOG_MODE is set to VERBOSE.
|
||||
*
|
||||
* Can be disabled entirely by setting LV_USE_CHECK_ARG to 0 in lv_conf.h.
|
||||
* If LV_CHECK_ARG_ASSERT_ON_FAIL is 1, LV_ASSERT_HANDLER is also invoked
|
||||
* before the action.
|
||||
* Log output requires LV_USE_LOG to be enabled; if LV_USE_LOG is 0 no
|
||||
* output is produced regardless of LV_CHECK_ARG_LOG_MODE.
|
||||
*
|
||||
* Example:
|
||||
* @code
|
||||
@@ -97,6 +107,7 @@ extern "C" {
|
||||
* @param cond condition to check
|
||||
* @param action_on_fail statement to execute on failure (e.g. `return`, `return 0`, `break`)
|
||||
* @param ... optional printf-style format string and arguments appended to the log
|
||||
* (only used when LV_CHECK_ARG_LOG_MODE == LV_CHECK_ARG_LOG_MODE_VERBOSE)
|
||||
*/
|
||||
#define LV_CHECK_ARG(cond, action_on_fail, ...) \
|
||||
LV_CHECK_ARG_INTERNAL_(cond, #cond, action_on_fail, __VA_ARGS__)
|
||||
|
||||
@@ -144,7 +144,9 @@ void lv_log_add(lv_log_level_t level, const char * file, int line,
|
||||
|
||||
#else /*LV_USE_LOG*/
|
||||
|
||||
/*Do nothing if `LV_USE_LOG 0`*/
|
||||
/* When LV_USE_LOG is 0 all logging macros expand to no-ops.
|
||||
* This also suppresses any log output from LV_CHECK_ARG (and similar check
|
||||
* macros such as LV_CHECK_OBJ) regardless of LV_CHECK_ARG_LOG_MODE. */
|
||||
#define lv_log_add(level, file, line, ...)
|
||||
#define LV_LOG_TRACE(...) do {}while(0)
|
||||
#define LV_LOG_INFO(...) do {}while(0)
|
||||
|
||||
+24
-6
@@ -169,7 +169,7 @@
|
||||
#define LV_DRAW_THREAD_PRIO LV_THREAD_PRIO_HIGH
|
||||
|
||||
#define LV_USE_DRAW_SW 1
|
||||
#if LV_USE_DRAW_SW == 1
|
||||
#if LV_USE_DRAW_SW
|
||||
/*
|
||||
* Selectively disable color format support in order to reduce code size.
|
||||
* NOTE: some features use certain color formats internally, e.g.
|
||||
@@ -517,15 +517,33 @@
|
||||
* Check arg
|
||||
*-----------*/
|
||||
|
||||
/** Enable LV_CHECK_ARG macro to validate function arguments at runtime.
|
||||
* When enabled, failed checks log a warning and execute the specified action.
|
||||
/** When enabled, LV_CHECK_ARG checks validate function arguments
|
||||
* at runtime. Failed checks log a warning and execute the specified
|
||||
* action. When disabled, all LV_CHECK_ARG checks compile to nothing.
|
||||
* Disabling this is not recommended unless extreme care is taken and only
|
||||
* in very resource constrained environments where it can be absolutely
|
||||
* ensured that invariants are never violated.
|
||||
*
|
||||
* 0: Disable all LV_CHECK_ARG checks (checks compile to nothing)
|
||||
* 1: Enable LV_CHECK_ARG checks */
|
||||
#define LV_USE_CHECK_ARG 1
|
||||
|
||||
/** If enabled, also call LV_ASSERT_HANDLER when an LV_CHECK_ARG check fails.
|
||||
* Requires LV_USE_CHECK_ARG to be enabled. */
|
||||
#define LV_CHECK_ARG_ASSERT_ON_FAIL 0
|
||||
#if LV_USE_CHECK_ARG
|
||||
/** If enabled, also call LV_ASSERT_HANDLER when an LV_CHECK_ARG check fails.
|
||||
* Requires LV_USE_CHECK_ARG to be enabled. */
|
||||
#define LV_CHECK_ARG_ASSERT_ON_FAIL 0
|
||||
|
||||
#if LV_USE_LOG
|
||||
/** Controls what is logged when an LV_CHECK_ARG check fails.
|
||||
* Any mode other than NONE also requires LV_USE_LOG; if LV_USE_LOG is 0
|
||||
* no output is produced regardless of this setting.
|
||||
*
|
||||
* LV_CHECK_ARG_LOG_MODE_NONE (0): No log output.
|
||||
* LV_CHECK_ARG_LOG_MODE_MINIMAL (1): Log "Check failed" only (file/line from LV_LOG_WARN).
|
||||
* LV_CHECK_ARG_LOG_MODE_VERBOSE (2): Log "Check failed: <cond>" plus caller-supplied message. */
|
||||
#define LV_CHECK_ARG_LOG_MODE LV_CHECK_ARG_LOG_MODE_VERBOSE
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/*-------------
|
||||
* Debug
|
||||
|
||||
@@ -59,7 +59,12 @@ def create_argument_parser() -> argparse.ArgumentParser:
|
||||
def run_git_command(args: List[str], cwd: str = ".") -> str:
|
||||
"""Run git command and return output"""
|
||||
result = subprocess.run(
|
||||
["git"] + args, capture_output=True, text=True, cwd=cwd, check=True
|
||||
["git"] + args,
|
||||
capture_output=True,
|
||||
cwd=cwd,
|
||||
check=True,
|
||||
encoding="utf-8",
|
||||
errors="replace",
|
||||
)
|
||||
return result.stdout
|
||||
|
||||
|
||||
@@ -83,6 +83,10 @@ fout.write(
|
||||
#define LV_NANOVG_BACKEND_GLES2 3
|
||||
#define LV_NANOVG_BACKEND_GLES3 4
|
||||
|
||||
#define LV_CHECK_ARG_LOG_MODE_NONE 0
|
||||
#define LV_CHECK_ARG_LOG_MODE_MINIMAL 1
|
||||
#define LV_CHECK_ARG_LOG_MODE_VERBOSE 2
|
||||
|
||||
/** Handle special Kconfig options. */
|
||||
#ifndef LV_KCONFIG_IGNORE
|
||||
#include "lv_conf_kconfig.h"
|
||||
@@ -339,6 +343,10 @@ LV_EXPORT_CONST_INT(LV_DRAW_BUF_ALIGN);
|
||||
#endif
|
||||
#endif /*defined(LV_CONF_SKIP)*/
|
||||
|
||||
#ifndef LV_CHECK_ARG_LOG_MODE
|
||||
#define LV_CHECK_ARG_LOG_MODE 0
|
||||
#endif
|
||||
|
||||
#endif /*LV_CONF_INTERNAL_H*/
|
||||
'''
|
||||
)
|
||||
|
||||
+46
-37
File diff suppressed because it is too large
Load Diff
+41
-12
@@ -7,6 +7,7 @@
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#include "lv_obj_private.h"
|
||||
#include "../lv_public_api.h"
|
||||
#include "../misc/lv_event_private.h"
|
||||
#include "../misc/lv_area_private.h"
|
||||
#include "lv_obj_style_private.h"
|
||||
@@ -223,10 +224,15 @@ const lv_obj_class_t lv_obj_class = {
|
||||
lv_obj_t * lv_obj_create(lv_obj_t * parent)
|
||||
{
|
||||
LV_LOG_INFO("begin");
|
||||
|
||||
lv_obj_t * obj = lv_obj_class_create_obj(MY_CLASS, parent);
|
||||
LV_ASSERT_NULL(obj);
|
||||
|
||||
if(obj == NULL) return NULL;
|
||||
|
||||
lv_obj_class_init_obj(obj);
|
||||
|
||||
LV_LOG_TRACE("finished");
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
@@ -241,6 +247,7 @@ lv_obj_t * lv_obj_create(lv_obj_t * parent)
|
||||
void lv_obj_add_flag(lv_obj_t * obj, lv_obj_flag_t f)
|
||||
{
|
||||
LV_ASSERT_OBJ(obj, MY_CLASS);
|
||||
|
||||
if(lv_obj_has_flag(obj, f)) /*Check if all flags are set*/
|
||||
return;
|
||||
|
||||
@@ -280,6 +287,7 @@ void lv_obj_add_flag(lv_obj_t * obj, lv_obj_flag_t f)
|
||||
void lv_obj_remove_flag(lv_obj_t * obj, lv_obj_flag_t f)
|
||||
{
|
||||
LV_ASSERT_OBJ(obj, MY_CLASS);
|
||||
|
||||
if(!lv_obj_has_flag_any(obj, f))
|
||||
return;
|
||||
|
||||
@@ -402,6 +410,7 @@ lv_group_t * lv_obj_get_group(const lv_obj_t * obj)
|
||||
lv_result_t lv_obj_add_child(lv_obj_t * parent, lv_obj_t * child)
|
||||
{
|
||||
LV_ASSERT_OBJ(parent, MY_CLASS);
|
||||
LV_CHECK_ARG(child != NULL, return LV_RESULT_INVALID);
|
||||
|
||||
uint16_t new_child_cnt = parent->spec_attr->child_cnt + 1;
|
||||
|
||||
@@ -421,6 +430,7 @@ void lv_obj_remove_child(lv_obj_t * parent, lv_obj_t * child)
|
||||
{
|
||||
LV_ASSERT_OBJ(parent, MY_CLASS);
|
||||
LV_ASSERT_OBJ(child, MY_CLASS);
|
||||
|
||||
for(int32_t i = lv_obj_get_index(child); i < (int32_t)parent->spec_attr->child_cnt - 1; i++) {
|
||||
parent->spec_attr->children[i] = parent->spec_attr->children[i + 1];
|
||||
}
|
||||
@@ -443,6 +453,7 @@ void lv_obj_remove_child(lv_obj_t * parent, lv_obj_t * child)
|
||||
lv_obj_spec_attr_t * lv_obj_allocate_spec_attr(lv_obj_t * obj)
|
||||
{
|
||||
LV_ASSERT_OBJ(obj, MY_CLASS);
|
||||
|
||||
if(obj->spec_attr) {
|
||||
return obj->spec_attr;
|
||||
}
|
||||
@@ -462,12 +473,14 @@ lv_obj_spec_attr_t * lv_obj_allocate_spec_attr(lv_obj_t * obj)
|
||||
|
||||
bool lv_obj_check_type(const lv_obj_t * obj, const lv_obj_class_t * class_p)
|
||||
{
|
||||
if(obj == NULL) return false;
|
||||
LV_CHECK_ARG(obj != NULL, return false);
|
||||
return obj->class_p == class_p;
|
||||
}
|
||||
|
||||
bool lv_obj_has_class(const lv_obj_t * obj, const lv_obj_class_t * class_p)
|
||||
{
|
||||
LV_CHECK_ARG(obj != NULL, return false);
|
||||
|
||||
const lv_obj_class_t * obj_class = obj->class_p;
|
||||
while(obj_class) {
|
||||
if(obj_class == class_p) return true;
|
||||
@@ -479,11 +492,14 @@ bool lv_obj_has_class(const lv_obj_t * obj, const lv_obj_class_t * class_p)
|
||||
|
||||
const lv_obj_class_t * lv_obj_get_class(const lv_obj_t * obj)
|
||||
{
|
||||
LV_CHECK_ARG(obj != NULL, return NULL);
|
||||
return obj->class_p;
|
||||
}
|
||||
|
||||
bool lv_obj_is_valid(const lv_obj_t * obj)
|
||||
{
|
||||
LV_CHECK_ARG(obj != NULL, return false);
|
||||
|
||||
lv_display_t * disp = lv_display_get_next(NULL);
|
||||
while(disp) {
|
||||
uint32_t i;
|
||||
@@ -501,18 +517,23 @@ bool lv_obj_is_valid(const lv_obj_t * obj)
|
||||
|
||||
void lv_obj_null_on_delete(lv_obj_t ** obj_ptr)
|
||||
{
|
||||
LV_CHECK_ARG(obj_ptr != NULL, return);
|
||||
LV_CHECK_ARG(*obj_ptr != NULL, return);
|
||||
|
||||
lv_obj_add_event_cb(*obj_ptr, null_on_delete_cb, LV_EVENT_DELETE, obj_ptr);
|
||||
}
|
||||
|
||||
#if LV_USE_OBJ_ID
|
||||
void * lv_obj_get_id(const lv_obj_t * obj)
|
||||
{
|
||||
LV_ASSERT_NULL(obj);
|
||||
LV_CHECK_ARG(obj != NULL, return NULL);
|
||||
return obj->id;
|
||||
}
|
||||
|
||||
lv_obj_t * lv_obj_find_by_id(const lv_obj_t * obj, const void * id)
|
||||
{
|
||||
LV_CHECK_ARG(id != NULL, return NULL);
|
||||
|
||||
LV_LOG_WARN("DEPRECATED: IDs are used only to print the widget trees. To find a widget use obj_name");
|
||||
|
||||
if(obj == NULL) obj = lv_display_get_screen_active(NULL);
|
||||
@@ -520,15 +541,13 @@ lv_obj_t * lv_obj_find_by_id(const lv_obj_t * obj, const void * id)
|
||||
|
||||
uint32_t i;
|
||||
uint32_t child_cnt = lv_obj_get_child_count(obj);
|
||||
for(i = 0; i < child_cnt; i++) {
|
||||
lv_obj_t * child = obj->spec_attr->children[i];
|
||||
if(lv_obj_id_compare(child->id, id) == 0) return child;
|
||||
}
|
||||
|
||||
/*Search children*/
|
||||
for(i = 0; i < child_cnt; i++) {
|
||||
lv_obj_t * child = obj->spec_attr->children[i];
|
||||
|
||||
if(lv_obj_id_compare(child->id, id) == 0) return child;
|
||||
lv_obj_t * found = lv_obj_find_by_id(child, id);
|
||||
|
||||
if(found != NULL) return found;
|
||||
}
|
||||
|
||||
@@ -539,10 +558,8 @@ lv_obj_t * lv_obj_find_by_id(const lv_obj_t * obj, const void * id)
|
||||
void lv_obj_add_screen_load_event(lv_obj_t * obj, lv_event_code_t trigger, lv_obj_t * screen,
|
||||
lv_screen_load_anim_t anim_type, uint32_t duration, uint32_t delay)
|
||||
{
|
||||
if(screen == NULL) {
|
||||
LV_LOG_WARN("`screen` is NULL, can't load a non existing screens");
|
||||
return;
|
||||
}
|
||||
LV_CHECK_ARG(screen != NULL, return, "can't load a non-existing screen");
|
||||
LV_CHECK_ARG(duration > 0 || anim_type == LV_SCREEN_LOAD_ANIM_NONE, return);
|
||||
|
||||
screen_load_anim_dsc_t * dsc = lv_malloc(sizeof(screen_load_anim_dsc_t));
|
||||
LV_ASSERT_MALLOC(dsc);
|
||||
@@ -559,6 +576,8 @@ void lv_obj_add_screen_load_event(lv_obj_t * obj, lv_event_code_t trigger, lv_ob
|
||||
void lv_obj_add_screen_create_event(lv_obj_t * obj, lv_event_code_t trigger, lv_screen_create_cb_t screen_create_cb,
|
||||
lv_screen_load_anim_t anim_type, uint32_t duration, uint32_t delay)
|
||||
{
|
||||
LV_CHECK_ARG(duration > 0 || anim_type == LV_SCREEN_LOAD_ANIM_NONE, return);
|
||||
|
||||
screen_load_anim_dsc_t * dsc = lv_malloc(sizeof(screen_load_anim_dsc_t));
|
||||
LV_ASSERT_MALLOC(dsc);
|
||||
lv_memzero(dsc, sizeof(screen_load_anim_dsc_t));
|
||||
@@ -574,6 +593,9 @@ void lv_obj_add_screen_create_event(lv_obj_t * obj, lv_event_code_t trigger, lv_
|
||||
void lv_obj_add_play_timeline_event(lv_obj_t * obj, lv_event_code_t trigger, lv_anim_timeline_t * at, uint32_t delay,
|
||||
bool reverse)
|
||||
{
|
||||
LV_CHECK_ARG(obj != NULL, return);
|
||||
LV_CHECK_ARG(at != NULL, return);
|
||||
|
||||
timeline_play_dsc_t * dsc = lv_malloc(sizeof(timeline_play_dsc_t));
|
||||
LV_ASSERT_MALLOC(dsc);
|
||||
lv_memzero(dsc, sizeof(timeline_play_dsc_t));
|
||||
@@ -587,11 +609,14 @@ void lv_obj_add_play_timeline_event(lv_obj_t * obj, lv_event_code_t trigger, lv_
|
||||
|
||||
void lv_obj_set_user_data(lv_obj_t * obj, void * user_data)
|
||||
{
|
||||
LV_CHECK_ARG(obj != NULL, return);
|
||||
obj->user_data = user_data;
|
||||
}
|
||||
|
||||
void * lv_obj_get_user_data(lv_obj_t * obj)
|
||||
{
|
||||
LV_CHECK_ARG(obj != NULL, return NULL);
|
||||
|
||||
return obj->user_data;
|
||||
}
|
||||
|
||||
@@ -601,6 +626,8 @@ void * lv_obj_get_user_data(lv_obj_t * obj)
|
||||
|
||||
static void lv_obj_constructor(const lv_obj_class_t * class_p, lv_obj_t * obj)
|
||||
{
|
||||
LV_CHECK_ARG(obj != NULL, return);
|
||||
|
||||
LV_UNUSED(class_p);
|
||||
LV_TRACE_OBJ_CREATE("begin");
|
||||
|
||||
@@ -636,6 +663,8 @@ static void lv_obj_constructor(const lv_obj_class_t * class_p, lv_obj_t * obj)
|
||||
|
||||
static void lv_obj_destructor(const lv_obj_class_t * class_p, lv_obj_t * obj)
|
||||
{
|
||||
LV_CHECK_ARG(obj != NULL, return);
|
||||
|
||||
LV_UNUSED(class_p);
|
||||
|
||||
lv_event_mark_deleted(obj);
|
||||
|
||||
+26
-14
@@ -9,6 +9,7 @@
|
||||
#include "lv_obj_class_private.h"
|
||||
#include "lv_obj_private.h"
|
||||
#include "../display/lv_display_private.h"
|
||||
#include "../lv_public_api.h"
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
@@ -43,9 +44,12 @@ static uint32_t get_instance_size(const lv_obj_class_t * class_p);
|
||||
|
||||
lv_obj_t * lv_obj_class_create_obj(const lv_obj_class_t * class_p, lv_obj_t * parent)
|
||||
{
|
||||
LV_CHECK_ARG(class_p != NULL, return NULL);
|
||||
|
||||
LV_TRACE_OBJ_CREATE("Creating object with %p class on %p parent", (void *)class_p, (void *)parent);
|
||||
uint32_t s = get_instance_size(class_p);
|
||||
lv_obj_t * obj = lv_malloc_zeroed(s);
|
||||
LV_ASSERT_MALLOC(obj);
|
||||
if(obj == NULL) return NULL;
|
||||
obj->class_p = class_p;
|
||||
obj->parent = parent;
|
||||
@@ -67,6 +71,7 @@ lv_obj_t * lv_obj_class_create_obj(const lv_obj_class_t * class_p, lv_obj_t * pa
|
||||
lv_obj_t ** screens = lv_realloc(disp->screens, sizeof(lv_obj_t *) * (disp->screen_cnt + 1));
|
||||
LV_ASSERT_MALLOC(screens);
|
||||
if(screens == NULL) {
|
||||
LV_LOG_WARN("Failed to expand memory for screen array");
|
||||
lv_free(obj);
|
||||
return NULL;
|
||||
}
|
||||
@@ -101,7 +106,7 @@ lv_obj_t * lv_obj_class_create_obj(const lv_obj_class_t * class_p, lv_obj_t * pa
|
||||
|
||||
void lv_obj_class_init_obj(lv_obj_t * obj)
|
||||
{
|
||||
if(obj == NULL) return;
|
||||
LV_CHECK_ARG(obj != NULL, return);
|
||||
|
||||
lv_obj_mark_layout_as_dirty(obj);
|
||||
lv_obj_enable_style_refresh(false);
|
||||
@@ -133,6 +138,9 @@ void lv_obj_class_init_obj(lv_obj_t * obj)
|
||||
|
||||
void lv_obj_destruct(lv_obj_t * obj)
|
||||
{
|
||||
LV_CHECK_ARG(obj != NULL, return);
|
||||
LV_CHECK_ARG(obj->class_p != NULL, return);
|
||||
|
||||
#if LV_USE_EXT_DATA
|
||||
if(obj->ext_data.free_cb) {
|
||||
obj->ext_data.free_cb(obj->ext_data.data);
|
||||
@@ -151,8 +159,10 @@ void lv_obj_destruct(lv_obj_t * obj)
|
||||
}
|
||||
}
|
||||
|
||||
bool lv_obj_is_editable(lv_obj_t * obj)
|
||||
bool lv_obj_is_editable(const lv_obj_t * obj)
|
||||
{
|
||||
LV_CHECK_ARG(obj != NULL, return false);
|
||||
|
||||
const lv_obj_class_t * class_p = obj->class_p;
|
||||
|
||||
/*Find a base in which editable is set*/
|
||||
@@ -163,8 +173,10 @@ bool lv_obj_is_editable(lv_obj_t * obj)
|
||||
return class_p->editable == LV_OBJ_CLASS_EDITABLE_TRUE;
|
||||
}
|
||||
|
||||
bool lv_obj_is_group_def(lv_obj_t * obj)
|
||||
bool lv_obj_is_group_def(const lv_obj_t * obj)
|
||||
{
|
||||
LV_CHECK_ARG(obj != NULL, return false);
|
||||
|
||||
const lv_obj_class_t * class_p = obj->class_p;
|
||||
|
||||
/*Find a base in which group_def is set*/
|
||||
@@ -178,10 +190,7 @@ bool lv_obj_is_group_def(lv_obj_t * obj)
|
||||
#if LV_USE_EXT_DATA
|
||||
void lv_obj_set_external_data(lv_obj_t * obj, void * data, void (* free_cb)(void * data))
|
||||
{
|
||||
if(!obj) {
|
||||
LV_LOG_WARN("Can't attach external user data and destructor callback to a NULL object");
|
||||
return;
|
||||
}
|
||||
LV_CHECK_ARG(obj != NULL, return, "Can't attach external user data and destructor callback to a NULL object");
|
||||
|
||||
obj->ext_data.data = data;
|
||||
obj->ext_data.free_cb = free_cb;
|
||||
@@ -194,9 +203,13 @@ void lv_obj_set_external_data(lv_obj_t * obj, void * data, void (* free_cb)(void
|
||||
|
||||
static void lv_obj_construct(const lv_obj_class_t * class_p, lv_obj_t * obj)
|
||||
{
|
||||
if(LV_USE_OBJ_NAME) {
|
||||
LV_ASSERT_NULL(class_p->name);
|
||||
}
|
||||
LV_ASSERT_NULL(class_p);
|
||||
LV_ASSERT_NULL(obj);
|
||||
LV_ASSERT_NULL(obj->class_p);
|
||||
|
||||
#if LV_USE_OBJ_NAME
|
||||
LV_ASSERT_NULL(class_p->name);
|
||||
#endif
|
||||
|
||||
#if LV_USE_EXT_DATA
|
||||
obj->ext_data.free_cb = NULL;
|
||||
@@ -222,10 +235,9 @@ static void lv_obj_construct(const lv_obj_class_t * class_p, lv_obj_t * obj)
|
||||
static uint32_t get_instance_size(const lv_obj_class_t * class_p)
|
||||
{
|
||||
/*Find a base in which instance size is set*/
|
||||
const lv_obj_class_t * base = class_p;
|
||||
while(base && base->instance_size == 0) base = base->base_class;
|
||||
while(class_p && class_p->instance_size == 0) class_p = class_p->base_class;
|
||||
|
||||
if(base == NULL) return 0; /*Never happens: set at least in `lv_obj` class*/
|
||||
LV_ASSERT(class_p != NULL); /*Never happens: set at least in `lv_obj` class*/
|
||||
|
||||
return base->instance_size;
|
||||
return class_p->instance_size;
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
*********************/
|
||||
#include "lv_obj_draw_private.h"
|
||||
#include "lv_obj_private.h"
|
||||
#include "../lv_public_api.h"
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
@@ -44,6 +45,8 @@ static void drop_shadow_init(const lv_obj_t * obj, lv_part_t part, lv_draw_dsc_b
|
||||
|
||||
void lv_obj_init_draw_rect_dsc(lv_obj_t * obj, lv_part_t part, lv_draw_rect_dsc_t * draw_dsc)
|
||||
{
|
||||
LV_CHECK_ARG(draw_dsc != NULL, return);
|
||||
|
||||
LV_PROFILER_DRAW_BEGIN;
|
||||
draw_dsc->base.obj = obj;
|
||||
draw_dsc->base.part = part;
|
||||
@@ -166,6 +169,8 @@ void lv_obj_init_draw_rect_dsc(lv_obj_t * obj, lv_part_t part, lv_draw_rect_dsc_
|
||||
|
||||
void lv_obj_init_draw_label_dsc(lv_obj_t * obj, lv_part_t part, lv_draw_label_dsc_t * draw_dsc)
|
||||
{
|
||||
LV_CHECK_ARG(draw_dsc != NULL, return);
|
||||
|
||||
LV_PROFILER_DRAW_BEGIN;
|
||||
draw_dsc->base.obj = obj;
|
||||
draw_dsc->base.part = part;
|
||||
@@ -207,6 +212,8 @@ void lv_obj_init_draw_label_dsc(lv_obj_t * obj, lv_part_t part, lv_draw_label_ds
|
||||
|
||||
void lv_obj_init_draw_image_dsc(lv_obj_t * obj, lv_part_t part, lv_draw_image_dsc_t * draw_dsc)
|
||||
{
|
||||
LV_CHECK_ARG(draw_dsc != NULL, return);
|
||||
|
||||
LV_PROFILER_DRAW_BEGIN;
|
||||
draw_dsc->base.obj = obj;
|
||||
draw_dsc->base.part = part;
|
||||
@@ -249,6 +256,8 @@ void lv_obj_init_draw_image_dsc(lv_obj_t * obj, lv_part_t part, lv_draw_image_ds
|
||||
|
||||
void lv_obj_init_draw_line_dsc(lv_obj_t * obj, lv_part_t part, lv_draw_line_dsc_t * draw_dsc)
|
||||
{
|
||||
LV_CHECK_ARG(draw_dsc != NULL, return);
|
||||
|
||||
LV_PROFILER_DRAW_BEGIN;
|
||||
draw_dsc->base.obj = obj;
|
||||
draw_dsc->base.part = part;
|
||||
@@ -292,6 +301,8 @@ void lv_obj_init_draw_line_dsc(lv_obj_t * obj, lv_part_t part, lv_draw_line_dsc_
|
||||
|
||||
void lv_obj_init_draw_arc_dsc(lv_obj_t * obj, lv_part_t part, lv_draw_arc_dsc_t * draw_dsc)
|
||||
{
|
||||
LV_CHECK_ARG(draw_dsc != NULL, return);
|
||||
|
||||
LV_PROFILER_DRAW_BEGIN;
|
||||
draw_dsc->base.obj = obj;
|
||||
draw_dsc->base.part = part;
|
||||
@@ -330,6 +341,8 @@ void lv_obj_init_draw_arc_dsc(lv_obj_t * obj, lv_part_t part, lv_draw_arc_dsc_t
|
||||
|
||||
void lv_obj_init_draw_blur_dsc(lv_obj_t * obj, lv_part_t part, lv_draw_blur_dsc_t * draw_dsc)
|
||||
{
|
||||
LV_CHECK_ARG(draw_dsc != NULL, return);
|
||||
|
||||
LV_PROFILER_DRAW_BEGIN;
|
||||
draw_dsc->base.obj = obj;
|
||||
draw_dsc->base.part = part;
|
||||
@@ -420,12 +433,15 @@ void lv_obj_refresh_ext_draw_size(lv_obj_t * obj)
|
||||
|
||||
int32_t lv_obj_get_ext_draw_size(const lv_obj_t * obj)
|
||||
{
|
||||
LV_CHECK_ARG(obj != NULL, return 0);
|
||||
|
||||
if(obj->spec_attr) return obj->spec_attr->ext_draw_size;
|
||||
else return 0;
|
||||
}
|
||||
|
||||
lv_layer_type_t lv_obj_get_layer_type(const lv_obj_t * obj)
|
||||
{
|
||||
LV_CHECK_ARG(obj != NULL, return LV_LAYER_TYPE_NONE);
|
||||
|
||||
if(obj->spec_attr) return (lv_layer_type_t)obj->spec_attr->layer_type;
|
||||
else return LV_LAYER_TYPE_NONE;
|
||||
|
||||
+85
-128
File diff suppressed because it is too large
Load Diff
@@ -9,6 +9,7 @@
|
||||
#include "lv_obj_class_private.h"
|
||||
#include "lv_obj_private.h"
|
||||
#include "lv_global.h"
|
||||
#include "../lv_public_api.h"
|
||||
#include "../osal/lv_os_private.h"
|
||||
|
||||
/*********************
|
||||
@@ -44,15 +45,15 @@ typedef struct _class_info_t {
|
||||
|
||||
void lv_obj_assign_id(const lv_obj_class_t * class_p, lv_obj_t * obj)
|
||||
{
|
||||
LV_ASSERT(obj && class_p);
|
||||
LV_CHECK_ARG(obj != NULL, return);
|
||||
LV_CHECK_ARG(class_p != NULL, return);
|
||||
|
||||
uint32_t i;
|
||||
uint32_t id = 0;
|
||||
lv_global_t * global = LV_GLOBAL_DEFAULT();
|
||||
class_info_t * info = NULL;
|
||||
|
||||
if(obj == NULL || class_p == NULL) return;
|
||||
if(global == NULL) return;
|
||||
LV_ASSERT_NULL(global);
|
||||
|
||||
obj->id = NULL;
|
||||
|
||||
@@ -80,20 +81,22 @@ void lv_obj_assign_id(const lv_obj_class_t * class_p, lv_obj_t * obj)
|
||||
|
||||
void lv_obj_set_id(lv_obj_t * obj, void * id)
|
||||
{
|
||||
LV_ASSERT_NULL(obj);
|
||||
LV_CHECK_ARG(obj != NULL, return);
|
||||
if(obj->id) lv_obj_free_id(obj);
|
||||
obj->id = id;
|
||||
}
|
||||
|
||||
void lv_obj_free_id(lv_obj_t * obj)
|
||||
{
|
||||
LV_CHECK_ARG(obj != NULL, return);
|
||||
obj->id = NULL;
|
||||
}
|
||||
|
||||
const char * lv_obj_stringify_id(lv_obj_t * obj, char * buf, uint32_t len)
|
||||
{
|
||||
if(obj == NULL || obj->class_p == NULL) return NULL;
|
||||
if(buf == NULL) return NULL;
|
||||
LV_CHECK_ARG(obj != NULL, return NULL);
|
||||
LV_CHECK_ARG(obj->class_p != NULL, return NULL);
|
||||
LV_CHECK_ARG(buf != NULL, return NULL);
|
||||
|
||||
const char * name = obj->class_p->name;
|
||||
if(name == NULL) name = "nameless";
|
||||
|
||||
+64
-13
File diff suppressed because it is too large
Load Diff
@@ -9,6 +9,7 @@
|
||||
#include "lv_obj_private.h"
|
||||
#include "../misc/lv_utils.h"
|
||||
#include "lv_obj_class_private.h"
|
||||
#include "../lv_public_api.h"
|
||||
|
||||
#if LV_USE_OBJ_PROPERTY
|
||||
|
||||
@@ -105,7 +106,8 @@ static int property_name_compare(const void * ref, const void * element);
|
||||
|
||||
lv_result_t lv_obj_set_property(lv_obj_t * obj, const lv_property_t * value)
|
||||
{
|
||||
LV_ASSERT(obj && value);
|
||||
LV_CHECK_ARG(obj != NULL, return LV_RESULT_INVALID);
|
||||
LV_CHECK_ARG(value != NULL, return LV_RESULT_INVALID);
|
||||
|
||||
uint32_t index = LV_PROPERTY_ID_INDEX(value->id);
|
||||
if(value->id == LV_PROPERTY_ID_INVALID || index > LV_PROPERTY_ID_ANY) {
|
||||
@@ -123,6 +125,9 @@ lv_result_t lv_obj_set_property(lv_obj_t * obj, const lv_property_t * value)
|
||||
|
||||
lv_result_t lv_obj_set_properties(lv_obj_t * obj, const lv_property_t * value, uint32_t count)
|
||||
{
|
||||
LV_CHECK_ARG(obj != NULL, return LV_RESULT_INVALID);
|
||||
LV_CHECK_ARG(value != NULL, return LV_RESULT_INVALID);
|
||||
|
||||
for(uint32_t i = 0; i < count; i++) {
|
||||
lv_result_t result = lv_obj_set_property(obj, &value[i]);
|
||||
if(result != LV_RESULT_OK) {
|
||||
@@ -135,6 +140,10 @@ lv_result_t lv_obj_set_properties(lv_obj_t * obj, const lv_property_t * value, u
|
||||
|
||||
lv_property_t lv_obj_get_property(lv_obj_t * obj, lv_prop_id_t id)
|
||||
{
|
||||
LV_CHECK_ARG(obj != NULL, return (lv_property_t) {
|
||||
.id = LV_PROPERTY_ID_INVALID
|
||||
});
|
||||
|
||||
lv_result_t result;
|
||||
lv_property_t value = { 0 };
|
||||
|
||||
@@ -162,6 +171,10 @@ lv_property_t lv_obj_get_property(lv_obj_t * obj, lv_prop_id_t id)
|
||||
|
||||
lv_property_t lv_obj_get_style_property(lv_obj_t * obj, lv_prop_id_t id, lv_part_t part)
|
||||
{
|
||||
LV_CHECK_ARG(obj != NULL, return (lv_property_t) {
|
||||
.id = LV_PROPERTY_ID_INVALID
|
||||
});
|
||||
|
||||
lv_property_t value;
|
||||
uint32_t index = LV_PROPERTY_ID_INDEX(id);
|
||||
|
||||
@@ -217,6 +230,8 @@ lv_prop_id_t lv_obj_class_property_get_id(const lv_obj_class_t * clz, const char
|
||||
lv_prop_id_t lv_obj_property_get_id(const lv_obj_t * obj, const char * name)
|
||||
{
|
||||
#if LV_USE_OBJ_PROPERTY_NAME
|
||||
LV_CHECK_ARG(obj != NULL, return LV_PROPERTY_ID_INVALID);
|
||||
|
||||
const lv_obj_class_t * clz;
|
||||
lv_prop_id_t id;
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
+59
-14
File diff suppressed because it is too large
Load Diff
+22
-5
@@ -12,6 +12,7 @@
|
||||
#include "../display/lv_display_private.h"
|
||||
#include "../misc/lv_anim_private.h"
|
||||
#include "../core/lv_global.h"
|
||||
#include "../lv_public_api.h"
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
@@ -52,11 +53,10 @@ static lv_obj_t * lv_obj_get_first_not_deleting_child(lv_obj_t * obj);
|
||||
|
||||
void lv_obj_delete(lv_obj_t * obj)
|
||||
{
|
||||
if(obj->is_deleting)
|
||||
return;
|
||||
if(!obj) return;
|
||||
if(obj->is_deleting) return;
|
||||
|
||||
LV_LOG_TRACE("begin (delete %p)", (void *)obj);
|
||||
LV_ASSERT_OBJ(obj, MY_CLASS);
|
||||
lv_obj_invalidate(obj);
|
||||
|
||||
lv_obj_t * par = lv_obj_get_parent(obj);
|
||||
@@ -120,6 +120,8 @@ void lv_obj_clean(lv_obj_t * obj)
|
||||
|
||||
void lv_obj_delete_delayed(lv_obj_t * obj, uint32_t delay_ms)
|
||||
{
|
||||
LV_ASSERT_OBJ(obj, MY_CLASS);
|
||||
|
||||
lv_anim_t a;
|
||||
lv_anim_init(&a);
|
||||
lv_anim_set_var(&a, obj);
|
||||
@@ -132,6 +134,8 @@ void lv_obj_delete_delayed(lv_obj_t * obj, uint32_t delay_ms)
|
||||
|
||||
void lv_obj_delete_anim_completed_cb(lv_anim_t * a)
|
||||
{
|
||||
LV_CHECK_ARG(a != NULL, return);
|
||||
|
||||
lv_obj_delete(a->var);
|
||||
}
|
||||
|
||||
@@ -339,6 +343,7 @@ lv_obj_t * lv_obj_get_child(const lv_obj_t * obj, int32_t idx)
|
||||
lv_obj_t * lv_obj_get_child_by_type(const lv_obj_t * obj, int32_t idx, const lv_obj_class_t * class_p)
|
||||
{
|
||||
LV_ASSERT_OBJ(obj, MY_CLASS);
|
||||
LV_CHECK_ARG(class_p != NULL, return NULL);
|
||||
|
||||
if(obj->spec_attr == NULL) return NULL;
|
||||
|
||||
@@ -366,6 +371,9 @@ lv_obj_t * lv_obj_get_child_by_type(const lv_obj_t * obj, int32_t idx, const lv_
|
||||
|
||||
lv_obj_t * lv_obj_get_sibling(const lv_obj_t * obj, int32_t idx)
|
||||
{
|
||||
LV_ASSERT_OBJ(obj, MY_CLASS);
|
||||
LV_CHECK_ARG(obj->parent != NULL, return NULL);
|
||||
|
||||
lv_obj_t * parent = lv_obj_get_parent(obj);
|
||||
int32_t sibling_idx = (int32_t)lv_obj_get_index(obj) + idx;
|
||||
if(sibling_idx < 0) return NULL;
|
||||
@@ -376,6 +384,8 @@ lv_obj_t * lv_obj_get_sibling(const lv_obj_t * obj, int32_t idx)
|
||||
lv_obj_t * lv_obj_get_sibling_by_type(const lv_obj_t * obj, int32_t idx, const lv_obj_class_t * class_p)
|
||||
{
|
||||
LV_ASSERT_OBJ(obj, MY_CLASS);
|
||||
LV_CHECK_ARG(obj->parent != NULL, return NULL);
|
||||
LV_CHECK_ARG(class_p != NULL, return NULL);
|
||||
|
||||
lv_obj_t * parent = lv_obj_get_parent(obj);
|
||||
int32_t sibling_idx = (int32_t)lv_obj_get_index_by_type(obj, class_p) + idx;
|
||||
@@ -394,6 +404,8 @@ uint32_t lv_obj_get_child_count(const lv_obj_t * obj)
|
||||
uint32_t lv_obj_get_child_count_by_type(const lv_obj_t * obj, const lv_obj_class_t * class_p)
|
||||
{
|
||||
LV_ASSERT_OBJ(obj, MY_CLASS);
|
||||
LV_CHECK_ARG(class_p != NULL, return 0);
|
||||
|
||||
if(obj->spec_attr == NULL) return 0;
|
||||
|
||||
uint32_t i;
|
||||
@@ -429,6 +441,7 @@ void lv_obj_set_name(lv_obj_t * obj, const char * name)
|
||||
void lv_obj_set_name_static(lv_obj_t * obj, const char * name)
|
||||
{
|
||||
LV_ASSERT_OBJ(obj, MY_CLASS);
|
||||
LV_CHECK_ARG(name != NULL, return);
|
||||
|
||||
if(!lv_obj_allocate_spec_attr(obj)) {
|
||||
return;
|
||||
@@ -450,6 +463,7 @@ const char * lv_obj_get_name(const lv_obj_t * obj)
|
||||
void lv_obj_get_name_resolved(const lv_obj_t * obj, char buf[], size_t buf_size)
|
||||
{
|
||||
LV_ASSERT_OBJ(obj, MY_CLASS);
|
||||
LV_CHECK_ARG(buf != NULL && buf_size > 0, return);
|
||||
|
||||
const char * name = lv_obj_get_name(obj);
|
||||
/*Use a default name which auto-indexing*/
|
||||
@@ -516,8 +530,8 @@ void lv_obj_get_name_resolved(const lv_obj_t * obj, char buf[], size_t buf_size)
|
||||
lv_obj_t * lv_obj_get_child_by_name(const lv_obj_t * parent, const char * path)
|
||||
{
|
||||
LV_ASSERT_OBJ(parent, MY_CLASS);
|
||||
|
||||
if(parent == NULL || parent->spec_attr == NULL || path == NULL) return NULL;
|
||||
LV_CHECK_ARG(path != NULL, return NULL);
|
||||
LV_CHECK_ARG(parent->spec_attr != NULL, return NULL);
|
||||
|
||||
while(*path) {
|
||||
const char * segment = path;
|
||||
@@ -547,6 +561,8 @@ lv_obj_t * lv_obj_get_child_by_name(const lv_obj_t * parent, const char * path)
|
||||
|
||||
lv_obj_t * lv_obj_find_by_name(const lv_obj_t * parent, const char * name)
|
||||
{
|
||||
LV_CHECK_ARG(name != NULL, return NULL);
|
||||
|
||||
if(parent == NULL) parent = lv_display_get_screen_active(NULL);
|
||||
if(parent == NULL) return NULL;
|
||||
|
||||
@@ -587,6 +603,7 @@ int32_t lv_obj_get_index(const lv_obj_t * obj)
|
||||
int32_t lv_obj_get_index_by_type(const lv_obj_t * obj, const lv_obj_class_t * class_p)
|
||||
{
|
||||
LV_ASSERT_OBJ(obj, MY_CLASS);
|
||||
LV_CHECK_ARG(class_p != NULL, return 0);
|
||||
|
||||
lv_obj_t * parent = lv_obj_get_parent(obj);
|
||||
if(parent == NULL) return 0xFFFFFFFF;
|
||||
|
||||
+145
-151
File diff suppressed because it is too large
Load Diff
+10
-2
@@ -17,6 +17,7 @@
|
||||
#include "../draw/lv_draw_private.h"
|
||||
#include "../draw/opengles/lv_draw_opengles.h"
|
||||
#include "lv_global.h"
|
||||
#include "../lv_public_api.h"
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
@@ -99,6 +100,9 @@ void lv_refr_now(lv_display_t * disp)
|
||||
|
||||
void lv_obj_redraw(lv_layer_t * layer, lv_obj_t * obj)
|
||||
{
|
||||
LV_CHECK_ARG(layer != NULL, return);
|
||||
LV_CHECK_ARG(obj != NULL, return);
|
||||
|
||||
LV_PROFILER_REFR_BEGIN;
|
||||
lv_area_t clip_area_ori = layer->_clip_area;
|
||||
lv_area_t clip_coords_for_obj;
|
||||
@@ -453,6 +457,9 @@ refr_finish:
|
||||
*/
|
||||
lv_obj_t * lv_refr_get_top_obj(const lv_area_t * area_p, lv_obj_t * obj)
|
||||
{
|
||||
LV_CHECK_ARG(area_p != NULL, return NULL);
|
||||
LV_CHECK_ARG(obj != NULL, return NULL);
|
||||
|
||||
lv_obj_t * found_p = NULL;
|
||||
|
||||
if(lv_area_is_in(area_p, &obj->coords, 0) == false) return NULL;
|
||||
@@ -490,8 +497,9 @@ lv_obj_t * lv_refr_get_top_obj(const lv_area_t * area_p, lv_obj_t * obj)
|
||||
|
||||
void lv_obj_refr(lv_layer_t * layer, lv_obj_t * obj)
|
||||
{
|
||||
LV_ASSERT_NULL(layer);
|
||||
LV_ASSERT_NULL(obj);
|
||||
LV_CHECK_ARG(layer != NULL, return);
|
||||
LV_CHECK_ARG(obj != NULL, return);
|
||||
|
||||
if(lv_obj_has_flag(obj, LV_OBJ_FLAG_HIDDEN)) return;
|
||||
|
||||
/*If `opa_layered != LV_OPA_COVER` draw the widget on a new layer and blend that layer with the given opacity.*/
|
||||
|
||||
@@ -89,7 +89,7 @@ static void make_small_magenta_texture(uint32_t new_magenta_tex);
|
||||
template <typename T, typename Func>
|
||||
static size_t injest_vec_attribute(uint8_t vec_size, int32_t current_attrib_index, lv_gltf_model_t * data,
|
||||
const fastgltf::Primitive * prim, const char * attrib_id, GLuint primitive_vertex_buffer,
|
||||
size_t offset, Func &&functor);
|
||||
size_t offset, Func && functor);
|
||||
|
||||
static int32_t injest_get_any_image_index(fastgltf::Optional<fastgltf::Texture> tex);
|
||||
static bool injest_check_any_image_index_valid(fastgltf::Optional<fastgltf::Texture> tex);
|
||||
@@ -829,7 +829,7 @@ static bool injest_mesh(lv_gltf_model_t * data, fastgltf::Mesh & mesh)
|
||||
template <typename T, typename Func>
|
||||
static size_t injest_vec_attribute(uint8_t vec_size, int32_t current_attrib_index, lv_gltf_model_t * data,
|
||||
const fastgltf::Primitive * prim, const char * attrib_id, GLuint primitive_vertex_buffer,
|
||||
size_t offset, Func &&functor
|
||||
size_t offset, Func && functor
|
||||
|
||||
)
|
||||
{
|
||||
|
||||
@@ -484,3 +484,4 @@ static lv_event_dsc_t ** event_array_at(lv_event_list_t * list, uint32_t index)
|
||||
{
|
||||
return lv_array_at(&list->array, index);
|
||||
}
|
||||
|
||||
|
||||
@@ -41,6 +41,8 @@ static void node_set_next(lv_ll_t * ll_p, lv_ll_node_t * act, lv_ll_node_t * nex
|
||||
|
||||
void lv_ll_init(lv_ll_t * ll_p, uint32_t node_size)
|
||||
{
|
||||
LV_CHECK_ARG(ll_p != NULL, return);
|
||||
LV_CHECK_ARG(node_size > 0, return, "cannot initialize a linked list with empty nodes");
|
||||
ll_p->head = NULL;
|
||||
ll_p->tail = NULL;
|
||||
#ifdef LV_ARCH_64
|
||||
|
||||
@@ -63,12 +63,14 @@ static void log_cb(lv_log_level_t level, const char * buf)
|
||||
static int helper_return_val_on_null(void * ptr)
|
||||
{
|
||||
LV_CHECK_ARG(ptr != NULL, return -1, "ptr is NULL");
|
||||
LV_UNUSED(ptr);
|
||||
return 42;
|
||||
}
|
||||
|
||||
static void helper_return_void_on_null(void * ptr, bool * was_reached)
|
||||
{
|
||||
LV_CHECK_ARG(ptr != NULL, return, "ptr is NULL");
|
||||
LV_UNUSED(ptr);
|
||||
*was_reached = true;
|
||||
}
|
||||
|
||||
@@ -108,6 +110,7 @@ void test_check_arg_printf_args(void)
|
||||
{
|
||||
int x = 0;
|
||||
int val = 7;
|
||||
LV_UNUSED(val);
|
||||
LV_CHECK_ARG(val > 10, x = -1, ": val=%d", val);
|
||||
TEST_ASSERT_EQUAL_INT(-1, x);
|
||||
TEST_ASSERT_TRUE(log_warned);
|
||||
@@ -195,6 +198,7 @@ void test_check_arg_multiple_in_sequence(void)
|
||||
static int helper_return_val_complex_expr(void * ptr)
|
||||
{
|
||||
LV_CHECK_ARG(ptr != NULL, return (1 > 0 ? -100 : -200), "complex expr");
|
||||
LV_UNUSED(ptr);
|
||||
return 42;
|
||||
}
|
||||
|
||||
@@ -210,6 +214,7 @@ void test_check_arg_return_val_complex_expr(void)
|
||||
static int helper_return_val_zero(void * ptr)
|
||||
{
|
||||
LV_CHECK_ARG(ptr != NULL, return 0, "returns zero");
|
||||
LV_UNUSED(ptr);
|
||||
return 42;
|
||||
}
|
||||
|
||||
|
||||
@@ -34,11 +34,11 @@ void test_obj_id_get_child(void)
|
||||
lv_obj_t * child = lv_label_create(parent);
|
||||
lv_obj_t * grandchild = lv_label_create(child);
|
||||
|
||||
lv_obj_set_id(child, (void *)(lv_uintptr_t)1);
|
||||
lv_obj_set_id(grandchild, (void *)(lv_uintptr_t)2);
|
||||
lv_obj_set_id(child, (void *)(lv_uintptr_t)42);
|
||||
lv_obj_set_id(grandchild, (void *)(lv_uintptr_t)43);
|
||||
|
||||
TEST_ASSERT_EQUAL_PTR(child, lv_obj_find_by_id(NULL, (void *)(lv_uintptr_t)1));
|
||||
TEST_ASSERT_EQUAL_PTR(grandchild, lv_obj_find_by_id(NULL, (void *)(lv_uintptr_t)2));
|
||||
TEST_ASSERT_EQUAL_PTR(child, lv_obj_find_by_id(NULL, (void *)(lv_uintptr_t)42));
|
||||
TEST_ASSERT_EQUAL_PTR(grandchild, lv_obj_find_by_id(NULL, (void *)(lv_uintptr_t)43));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user