mirror of
https://github.com/lvgl/lvgl.git
synced 2026-05-10 04:37:55 +08:00
feat(style): add lv_style_merge and appropriate tests (#8680)
Arduino Lint / lint (push) Has been cancelled
Build Examples with C++ Compiler / build-examples (push) Has been cancelled
MicroPython CI / Build esp32 port (push) Has been cancelled
MicroPython CI / Build rp2 port (push) Has been cancelled
MicroPython CI / Build stm32 port (push) Has been cancelled
MicroPython CI / Build unix port (push) Has been cancelled
C/C++ CI / Build OPTIONS_16BIT - Ubuntu (push) Has been cancelled
C/C++ CI / Build OPTIONS_24BIT - Ubuntu (push) Has been cancelled
C/C++ CI / Build OPTIONS_FULL_32BIT - Ubuntu (push) Has been cancelled
C/C++ CI / Build OPTIONS_NORMAL_8BIT - Ubuntu (push) Has been cancelled
C/C++ CI / Build OPTIONS_SDL - Ubuntu (push) Has been cancelled
C/C++ CI / Build OPTIONS_16BIT - cl - Windows (push) Has been cancelled
C/C++ CI / Build OPTIONS_16BIT - gcc - Windows (push) Has been cancelled
C/C++ CI / Build OPTIONS_24BIT - cl - Windows (push) Has been cancelled
C/C++ CI / Build OPTIONS_24BIT - gcc - Windows (push) Has been cancelled
C/C++ CI / Build OPTIONS_FULL_32BIT - cl - Windows (push) Has been cancelled
C/C++ CI / Build OPTIONS_FULL_32BIT - gcc - Windows (push) Has been cancelled
C/C++ CI / Build ESP IDF ESP32S3 (push) Has been cancelled
C/C++ CI / Run tests with 32bit build (push) Has been cancelled
C/C++ CI / Run tests with 64bit build (push) Has been cancelled
BOM Check / bom-check (push) Has been cancelled
Verify that lv_conf_internal.h matches repository state / verify-conf-internal (push) Has been cancelled
Verify the widget property name / verify-property-name (push) Has been cancelled
Verify code formatting / verify-formatting (push) Has been cancelled
Compare file templates with file names / template-check (push) Has been cancelled
Build docs / build-and-deploy (push) Has been cancelled
Test API JSON generator / Test API JSON (push) Has been cancelled
Install LVGL using CMake / build-examples (push) Has been cancelled
Check Makefile / Build using Makefile (push) Has been cancelled
Check Makefile for UEFI / Build using Makefile for UEFI (push) Has been cancelled
Emulated Performance Test / ARM Emulated Benchmark - Script Check (scripts/perf/tests/benchmark_results_comment/test.sh) (push) Has been cancelled
Emulated Performance Test / ARM Emulated Benchmark - Script Check (scripts/perf/tests/filter_docker_logs/test.sh) (push) Has been cancelled
Emulated Performance Test / ARM Emulated Benchmark - Script Check (scripts/perf/tests/serialize_results/test.sh) (push) Has been cancelled
Hardware Performance Test / Hardware Performance Benchmark (push) Has been cancelled
Hardware Performance Test / HW Benchmark - Save PR Number (push) Has been cancelled
Performance Tests CI / Perf Tests OPTIONS_TEST_PERF_32B - Ubuntu (push) Has been cancelled
Performance Tests CI / Perf Tests OPTIONS_TEST_PERF_64B - Ubuntu (push) Has been cancelled
Port repo release update / run-release-branch-updater (push) Has been cancelled
Verify Font License / verify-font-license (push) Has been cancelled
Verify Kconfig / verify-kconfig (push) Has been cancelled
Emulated Performance Test / ARM Emulated Benchmark 32b - lv_conf_perf32b (push) Has been cancelled
Emulated Performance Test / ARM Emulated Benchmark 64b - lv_conf_perf64b (push) Has been cancelled
Emulated Performance Test / ARM Emulated Benchmark - Save PR Number (push) Has been cancelled
Close stale issues and PRs / stale (push) Has been cancelled
Arduino Lint / lint (push) Has been cancelled
Build Examples with C++ Compiler / build-examples (push) Has been cancelled
MicroPython CI / Build esp32 port (push) Has been cancelled
MicroPython CI / Build rp2 port (push) Has been cancelled
MicroPython CI / Build stm32 port (push) Has been cancelled
MicroPython CI / Build unix port (push) Has been cancelled
C/C++ CI / Build OPTIONS_16BIT - Ubuntu (push) Has been cancelled
C/C++ CI / Build OPTIONS_24BIT - Ubuntu (push) Has been cancelled
C/C++ CI / Build OPTIONS_FULL_32BIT - Ubuntu (push) Has been cancelled
C/C++ CI / Build OPTIONS_NORMAL_8BIT - Ubuntu (push) Has been cancelled
C/C++ CI / Build OPTIONS_SDL - Ubuntu (push) Has been cancelled
C/C++ CI / Build OPTIONS_16BIT - cl - Windows (push) Has been cancelled
C/C++ CI / Build OPTIONS_16BIT - gcc - Windows (push) Has been cancelled
C/C++ CI / Build OPTIONS_24BIT - cl - Windows (push) Has been cancelled
C/C++ CI / Build OPTIONS_24BIT - gcc - Windows (push) Has been cancelled
C/C++ CI / Build OPTIONS_FULL_32BIT - cl - Windows (push) Has been cancelled
C/C++ CI / Build OPTIONS_FULL_32BIT - gcc - Windows (push) Has been cancelled
C/C++ CI / Build ESP IDF ESP32S3 (push) Has been cancelled
C/C++ CI / Run tests with 32bit build (push) Has been cancelled
C/C++ CI / Run tests with 64bit build (push) Has been cancelled
BOM Check / bom-check (push) Has been cancelled
Verify that lv_conf_internal.h matches repository state / verify-conf-internal (push) Has been cancelled
Verify the widget property name / verify-property-name (push) Has been cancelled
Verify code formatting / verify-formatting (push) Has been cancelled
Compare file templates with file names / template-check (push) Has been cancelled
Build docs / build-and-deploy (push) Has been cancelled
Test API JSON generator / Test API JSON (push) Has been cancelled
Install LVGL using CMake / build-examples (push) Has been cancelled
Check Makefile / Build using Makefile (push) Has been cancelled
Check Makefile for UEFI / Build using Makefile for UEFI (push) Has been cancelled
Emulated Performance Test / ARM Emulated Benchmark - Script Check (scripts/perf/tests/benchmark_results_comment/test.sh) (push) Has been cancelled
Emulated Performance Test / ARM Emulated Benchmark - Script Check (scripts/perf/tests/filter_docker_logs/test.sh) (push) Has been cancelled
Emulated Performance Test / ARM Emulated Benchmark - Script Check (scripts/perf/tests/serialize_results/test.sh) (push) Has been cancelled
Hardware Performance Test / Hardware Performance Benchmark (push) Has been cancelled
Hardware Performance Test / HW Benchmark - Save PR Number (push) Has been cancelled
Performance Tests CI / Perf Tests OPTIONS_TEST_PERF_32B - Ubuntu (push) Has been cancelled
Performance Tests CI / Perf Tests OPTIONS_TEST_PERF_64B - Ubuntu (push) Has been cancelled
Port repo release update / run-release-branch-updater (push) Has been cancelled
Verify Font License / verify-font-license (push) Has been cancelled
Verify Kconfig / verify-kconfig (push) Has been cancelled
Emulated Performance Test / ARM Emulated Benchmark 32b - lv_conf_perf32b (push) Has been cancelled
Emulated Performance Test / ARM Emulated Benchmark 64b - lv_conf_perf64b (push) Has been cancelled
Emulated Performance Test / ARM Emulated Benchmark - Save PR Number (push) Has been cancelled
Close stale issues and PRs / stale (push) Has been cancelled
This commit is contained in:
+20
-3
@@ -210,10 +210,27 @@ void lv_style_copy(lv_style_t * dst, const lv_style_t * src)
|
||||
|
||||
lv_style_reset(dst);
|
||||
|
||||
/*Source is empty*/
|
||||
if(src->values_and_props == NULL) return;
|
||||
if(src->prop_cnt == 0) return;
|
||||
lv_style_merge(dst, src);
|
||||
}
|
||||
|
||||
void lv_style_merge(lv_style_t * dst, const lv_style_t * src)
|
||||
{
|
||||
if(lv_style_is_const(dst)) {
|
||||
LV_LOG_WARN("The destination can not be a constant style");
|
||||
return;
|
||||
}
|
||||
|
||||
/*Source is empty*/
|
||||
if(src->values_and_props == NULL) {
|
||||
LV_LOG_TRACE("Source style is empty");
|
||||
return;
|
||||
}
|
||||
if(src->prop_cnt == 0) {
|
||||
LV_LOG_TRACE("Source style has no properties");
|
||||
return;
|
||||
}
|
||||
|
||||
/* Merge the styles */
|
||||
int32_t i;
|
||||
if(lv_style_is_const(src)) {
|
||||
lv_style_const_prop_t * props_and_values = (lv_style_const_prop_t *)src->values_and_props;
|
||||
|
||||
@@ -363,6 +363,19 @@ void lv_style_reset(lv_style_t * style);
|
||||
*/
|
||||
void lv_style_copy(lv_style_t * dst, const lv_style_t * src);
|
||||
|
||||
/**
|
||||
* Copy all properties of a style to an other without resetting the dst style.
|
||||
* It has the same effect as calling the same `lv_set_style_...`
|
||||
* functions on both styles.
|
||||
* It means new memory will be allocated to store the properties in
|
||||
* the destination style.
|
||||
* After the copy the destination style is fully independent of the source
|
||||
* and source can removed without affecting the destination style.
|
||||
* @param dst the destination to copy into (cannot be a constant style)
|
||||
* @param src the source style to copy from.
|
||||
*/
|
||||
void lv_style_merge(lv_style_t * dst, const lv_style_t * src);
|
||||
|
||||
|
||||
/**
|
||||
* Check if a style is constant
|
||||
|
||||
@@ -118,6 +118,87 @@ void test_style_replacement(void)
|
||||
lv_style_reset(&style_blue);
|
||||
}
|
||||
|
||||
void test_style_copy(void)
|
||||
{
|
||||
lv_style_t style1;
|
||||
lv_style_t style2;
|
||||
lv_style_t copied_style;
|
||||
|
||||
const lv_color_t copied_bg_color = lv_color_hex(0x0000ff);
|
||||
const lv_color_t copied_border_color = lv_color_hex(0x00ff00);
|
||||
const lv_color_t copied_outline_color = lv_color_hex(0xffff00);
|
||||
|
||||
lv_style_init(&style1);
|
||||
lv_style_set_bg_color(&style1, lv_color_hex(0xff0000)); // this should get overwritten
|
||||
lv_style_set_outline_color(&style1, copied_outline_color);
|
||||
|
||||
lv_style_init(&style2);
|
||||
lv_style_set_bg_color(&style2, copied_bg_color);
|
||||
lv_style_set_border_color(&style2, copied_border_color);
|
||||
|
||||
lv_style_init(&copied_style);
|
||||
lv_style_copy(&copied_style, &style1);
|
||||
lv_style_copy(&copied_style, &style2); // This should reset `copied_style` then duplicate the properties of `style2`
|
||||
|
||||
lv_style_value_t value;
|
||||
|
||||
TEST_ASSERT_TRUE(lv_style_get_prop(&copied_style, LV_STYLE_BG_COLOR, &value) == LV_STYLE_RES_FOUND);
|
||||
TEST_ASSERT_EQUAL_COLOR(copied_bg_color, value.color);
|
||||
TEST_ASSERT_TRUE(lv_style_get_prop(&copied_style, LV_STYLE_BORDER_COLOR, &value) == LV_STYLE_RES_FOUND);
|
||||
TEST_ASSERT_EQUAL_COLOR(copied_border_color, value.color);
|
||||
TEST_ASSERT_TRUE(lv_style_get_prop(&copied_style, LV_STYLE_OUTLINE_COLOR, &value) == LV_STYLE_RES_NOT_FOUND);
|
||||
|
||||
/* Changing the original style should not impact the style that copied it */
|
||||
lv_style_set_bg_color(&style2, lv_color_hex(0x00ff00));
|
||||
TEST_ASSERT_TRUE(lv_style_get_prop(&copied_style, LV_STYLE_BG_COLOR, &value) == LV_STYLE_RES_FOUND);
|
||||
TEST_ASSERT_EQUAL_COLOR(copied_bg_color, value.color);
|
||||
|
||||
lv_style_reset(&style1);
|
||||
lv_style_reset(&style2);
|
||||
lv_style_reset(&copied_style);
|
||||
}
|
||||
|
||||
void test_style_merge(void)
|
||||
{
|
||||
lv_style_t style1;
|
||||
lv_style_t style2;
|
||||
lv_style_t merged_style;
|
||||
|
||||
const lv_color_t merged_bg_color = lv_color_hex(0x0000ff);
|
||||
const lv_color_t merged_border_color = lv_color_hex(0x00ff00);
|
||||
const lv_color_t merged_outline_color = lv_color_hex(0xffff00);
|
||||
|
||||
lv_style_init(&style1);
|
||||
lv_style_set_bg_color(&style1, lv_color_hex(0xff0000)); // this should get overwritten
|
||||
lv_style_set_outline_color(&style1, merged_outline_color);
|
||||
|
||||
lv_style_init(&style2);
|
||||
lv_style_set_bg_color(&style2, merged_bg_color);
|
||||
lv_style_set_border_color(&style2, merged_border_color);
|
||||
|
||||
lv_style_init(&merged_style);
|
||||
lv_style_merge(&merged_style, &style1);
|
||||
lv_style_merge(&merged_style, &style2);
|
||||
|
||||
lv_style_value_t value;
|
||||
|
||||
TEST_ASSERT_TRUE(lv_style_get_prop(&merged_style, LV_STYLE_BG_COLOR, &value) == LV_STYLE_RES_FOUND);
|
||||
TEST_ASSERT_EQUAL_COLOR(merged_bg_color, value.color);
|
||||
TEST_ASSERT_TRUE(lv_style_get_prop(&merged_style, LV_STYLE_BORDER_COLOR, &value) == LV_STYLE_RES_FOUND);
|
||||
TEST_ASSERT_EQUAL_COLOR(merged_border_color, value.color);
|
||||
TEST_ASSERT_TRUE(lv_style_get_prop(&merged_style, LV_STYLE_OUTLINE_COLOR, &value) == LV_STYLE_RES_FOUND);
|
||||
TEST_ASSERT_EQUAL_COLOR(merged_outline_color, value.color);
|
||||
|
||||
/* Changing the original style should not impact the style that copied it */
|
||||
lv_style_set_bg_color(&style2, lv_color_hex(0x00ff00));
|
||||
TEST_ASSERT_TRUE(lv_style_get_prop(&merged_style, LV_STYLE_BG_COLOR, &value) == LV_STYLE_RES_FOUND);
|
||||
TEST_ASSERT_EQUAL_COLOR(merged_bg_color, value.color);
|
||||
|
||||
lv_style_reset(&style1);
|
||||
lv_style_reset(&style2);
|
||||
lv_style_reset(&merged_style);
|
||||
}
|
||||
|
||||
void test_style_has_prop(void)
|
||||
{
|
||||
lv_style_t style;
|
||||
|
||||
Reference in New Issue
Block a user