mirror of
https://github.com/lvgl/lvgl.git
synced 2026-05-24 00:07:03 +08:00
feat(xml): add lv_switch
This commit is contained in:
committed by
Felipe Neves
parent
7aaeb6694c
commit
250bc8b039
@@ -1,25 +1,6 @@
|
||||
<component>
|
||||
<consts>
|
||||
<color name="light_blue" value="0xbbbbff"/>
|
||||
<color name="dark_blue" value="0x000080"/>
|
||||
</consts>
|
||||
<view extends="lv_obj">
|
||||
<lv_switch/>
|
||||
|
||||
<styles>
|
||||
<style name="btn_style" bg_color="#dark_blue" bg_opa="150"/>
|
||||
<style name="btn_pr_style" bg_opa="255"/>
|
||||
</styles>
|
||||
|
||||
<view extends="lv_obj" name="main" width="280" height="content" style_bg_color="#light_blue">
|
||||
<lv_label text-translated="tiger"/>
|
||||
<my_card title="Card 1" name="card1"
|
||||
y="30"
|
||||
btn_rel_style="btn_style"
|
||||
btn_pr_style="btn_pr_style"/>
|
||||
|
||||
<my_card y="125"
|
||||
bg_color="0xffaaaa"
|
||||
action="Apply"
|
||||
btn_rel_style="btn_style"
|
||||
btn_pr_style="btn_pr_style"/>
|
||||
</view>
|
||||
</component>
|
||||
@@ -37,6 +37,7 @@
|
||||
#include "parsers/lv_xml_textarea_parser.h"
|
||||
#include "parsers/lv_xml_keyboard_parser.h"
|
||||
#include "parsers/lv_xml_arc_parser.h"
|
||||
#include "parsers/lv_xml_switch_parser.h"
|
||||
#include "parsers/lv_xml_checkbox_parser.h"
|
||||
#include "parsers/lv_xml_canvas_parser.h"
|
||||
#include "parsers/lv_xml_calendar_parser.h"
|
||||
@@ -113,6 +114,7 @@ void lv_xml_init(void)
|
||||
lv_xml_widget_register("lv_textarea", lv_xml_textarea_create, lv_xml_textarea_apply);
|
||||
lv_xml_widget_register("lv_keyboard", lv_xml_keyboard_create, lv_xml_keyboard_apply);
|
||||
lv_xml_widget_register("lv_arc", lv_xml_arc_create, lv_xml_arc_apply);
|
||||
lv_xml_widget_register("lv_switch", lv_xml_switch_create, lv_xml_switch_apply);
|
||||
lv_xml_widget_register("lv_checkbox", lv_xml_checkbox_create, lv_xml_checkbox_apply);
|
||||
lv_xml_widget_register("lv_canvas", lv_xml_canvas_create, lv_xml_canvas_apply);
|
||||
lv_xml_widget_register("lv_calendar", lv_xml_calendar_create, lv_xml_calendar_apply);
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
/**
|
||||
* @file lv_xml_switch_parser.c
|
||||
*
|
||||
*/
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#include "lv_xml_switch_parser.h"
|
||||
#if LV_USE_XML
|
||||
|
||||
#include "../../../lvgl.h"
|
||||
#include "../../../lvgl_private.h"
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* STATIC PROTOTYPES
|
||||
**********************/
|
||||
static lv_switch_orientation_t orientation_text_to_enum_value(const char * txt);
|
||||
|
||||
/**********************
|
||||
* STATIC VARIABLES
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL FUNCTIONS
|
||||
**********************/
|
||||
|
||||
void * lv_xml_switch_create(lv_xml_parser_state_t * state, const char ** attrs)
|
||||
{
|
||||
LV_UNUSED(attrs);
|
||||
|
||||
void * item = lv_switch_create(lv_xml_state_get_parent(state));
|
||||
return item;
|
||||
}
|
||||
|
||||
void lv_xml_switch_apply(lv_xml_parser_state_t * state, const char ** attrs)
|
||||
{
|
||||
void * item = lv_xml_state_get_item(state);
|
||||
lv_xml_obj_apply(state, attrs); /*Apply the common properties, e.g. width, height, styles flags etc*/
|
||||
|
||||
for(int i = 0; attrs[i]; i += 2) {
|
||||
const char * name = attrs[i];
|
||||
const char * value = attrs[i + 1];
|
||||
|
||||
if(lv_streq("orientation", name)) lv_switch_set_orientation(item, orientation_text_to_enum_value(value));
|
||||
}
|
||||
}
|
||||
|
||||
/**********************
|
||||
* STATIC FUNCTIONS
|
||||
**********************/
|
||||
|
||||
static lv_switch_orientation_t orientation_text_to_enum_value(const char * txt)
|
||||
{
|
||||
if(lv_streq("auto", txt)) return LV_SWITCH_ORIENTATION_AUTO;
|
||||
if(lv_streq("horizontal", txt)) return LV_SWITCH_ORIENTATION_HORIZONTAL;
|
||||
if(lv_streq("vertical", txt)) return LV_SWITCH_ORIENTATION_VERTICAL;
|
||||
|
||||
LV_LOG_WARN("%s is an unknown value for switch's orientation", txt);
|
||||
|
||||
return 0; /*Return 0 in lack of a better option. */
|
||||
}
|
||||
|
||||
#endif /* LV_USE_XML */
|
||||
@@ -0,0 +1,40 @@
|
||||
/**
|
||||
* @file lv_xml_switch_parser.h
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef LV_XML_SWITCH_PARSER_H
|
||||
#define LV_XML_SWITCH_PARSER_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#include "../lv_xml.h"
|
||||
#if LV_USE_XML
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
|
||||
void * lv_xml_switch_create(lv_xml_parser_state_t * state, const char ** attrs);
|
||||
void lv_xml_switch_apply(lv_xml_parser_state_t * state, const char ** attrs);
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
#endif /* LV_USE_XML */
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /*extern "C"*/
|
||||
#endif
|
||||
|
||||
#endif /*LV_XML_SWITCH_PARSER_H*/
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 2.4 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 2.4 KiB |
@@ -0,0 +1,40 @@
|
||||
#if LV_BUILD_TEST
|
||||
#include "../lvgl.h"
|
||||
|
||||
#include "unity/unity.h"
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
/* Function run before every test */
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
/* Function run after every test */
|
||||
lv_obj_clean(lv_screen_active());
|
||||
}
|
||||
|
||||
|
||||
void test_xml_switch_widget(void)
|
||||
{
|
||||
lv_obj_t * scr = lv_screen_active();
|
||||
|
||||
lv_obj_set_flex_flow(scr, LV_FLEX_FLOW_COLUMN);
|
||||
lv_obj_set_flex_align(scr, LV_FLEX_ALIGN_SPACE_EVENLY, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER);
|
||||
|
||||
lv_xml_create(scr, "lv_switch", NULL);
|
||||
|
||||
const char * attrs_1[] = {
|
||||
"width", "100",
|
||||
"height", "40",
|
||||
"checked", "true",
|
||||
NULL, NULL,
|
||||
};
|
||||
|
||||
lv_xml_create(scr, "lv_switch", attrs_1);
|
||||
|
||||
|
||||
TEST_ASSERT_EQUAL_SCREENSHOT("xml/lv_switch.png");
|
||||
}
|
||||
|
||||
#endif
|
||||
+1
-1
@@ -11,7 +11,7 @@ Example
|
||||
<enum name="range" help="range"/>
|
||||
</enumdef>
|
||||
|
||||
<enumdef name="bar_orientation" help="">
|
||||
<enumdef name="lv_bar_orientation" help="">
|
||||
<enum name="auto" help=""/>
|
||||
<enum name="horizontal" help=""/>
|
||||
<enum name="vertical" help=""/>
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
<!--
|
||||
Example
|
||||
<lv_switch width="100" height="40"/>
|
||||
-->
|
||||
|
||||
<widget>
|
||||
<api>
|
||||
<enumdef name="lv_switch_orientation" help="">
|
||||
<enum name="auto" help=""/>
|
||||
<enum name="horizontal" help=""/>
|
||||
<enum name="vertical" help=""/>
|
||||
</enumdef>
|
||||
|
||||
<prop name="orientation" type="enum:lv_switch_orientation"/>
|
||||
</api>
|
||||
</widget>
|
||||
Reference in New Issue
Block a user