-
Notifications
You must be signed in to change notification settings - Fork 625
add example widget #348
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
fbiego
wants to merge
3
commits into
lvgl:master
Choose a base branch
from
fbiego:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
add example widget #348
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| preview-build |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| # This basic file is used to compile the runtime for the Editor preview. | ||
| # Generated file, do not edit. | ||
|
|
||
| # Only set project if this is the top-level CMakeLists.txt | ||
| if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) | ||
| cmake_minimum_required(VERSION 3.10) | ||
| # can be customized | ||
| project(LVGLProject) | ||
| set(IS_TOP_LEVEL TRUE) | ||
| else() | ||
| set(IS_TOP_LEVEL FALSE) | ||
| endif() | ||
|
|
||
| # Handles giving component libraries unique names when included as subprojects. | ||
| if (DEFINED LVGL_COMPONENT_LIB_NAME) | ||
| set(LIB_NAME ${LVGL_COMPONENT_LIB_NAME}) | ||
| else() | ||
| set(LIB_NAME lib-ui) | ||
| endif() | ||
|
|
||
| # This includes the generated list of .c files | ||
| include(${CMAKE_CURRENT_LIST_DIR}/file_list_gen.cmake) | ||
| # Include any component libraries | ||
| include(${CMAKE_CURRENT_LIST_DIR}/component_lib_list_gen.cmake) | ||
|
|
||
| # Create the UI sources as a library | ||
| add_library(${LIB_NAME} ${LV_EDITOR_PROJECT_SOURCES}) | ||
| if (DEFINED LV_EDITOR_COMPONENT_LIB_LIST) | ||
| target_link_libraries(${LIB_NAME} PUBLIC ${LV_EDITOR_COMPONENT_LIB_LIST}) | ||
| endif () | ||
|
|
||
| if(TARGET lvgl) | ||
| target_link_libraries(${LIB_NAME} PUBLIC lvgl) | ||
| endif() | ||
|
|
||
| # Add the project folder as include folder | ||
| target_include_directories(${LIB_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) | ||
|
|
||
| # Set include directories for the project | ||
| # This will include the LVGL includes | ||
| target_include_directories(${LIB_NAME} PRIVATE ${COMMON_INCLUDE_DIRS}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
|
|
||
|
|
||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Create XML files here that start with a `<component>` tag |
29 changes: 29 additions & 0 deletions
29
tutorials/9_new_widget/components/segment_item/segment_item.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| <component> | ||
| <previews> | ||
| <preview width="320" height="40" style_bg_color="0x383838" /> | ||
| </previews> | ||
|
|
||
| <api> | ||
| <prop name="text" type="string" default="Segment" /> | ||
| </api> | ||
|
|
||
| <styles> | ||
| <style | ||
| name="style_base" | ||
| width="100" | ||
| height="100%" | ||
| bg_color="0x545454" | ||
| border_width="0" | ||
| text_color="0xffffff" | ||
| radius="0" | ||
| /> | ||
| <style name="style_checked" bg_color="0xd3d3d3" text_color="0x000000" /> | ||
| </styles> | ||
|
|
||
| <view extends="lv_obj" scrollable="false"> | ||
| <!-- Add widgets/components here --> | ||
| <style name="style_base" /> | ||
| <style name="style_checked" selector="checked" /> | ||
| <lv_label text="$text" align="center" /> | ||
| </view> | ||
| </component> |
76 changes: 76 additions & 0 deletions
76
tutorials/9_new_widget/components/segment_item/segment_item_gen.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| /** | ||
| * @file segment_item_gen.c | ||
| * @brief Template source file for LVGL objects | ||
| */ | ||
|
|
||
| /********************* | ||
| * INCLUDES | ||
| *********************/ | ||
|
|
||
| #include "segment_item_gen.h" | ||
| #include "../../new_widget.h" | ||
|
|
||
| /********************* | ||
| * DEFINES | ||
| *********************/ | ||
|
|
||
| /********************** | ||
| * TYPEDEFS | ||
| **********************/ | ||
|
|
||
| /*********************** | ||
| * STATIC VARIABLES | ||
| **********************/ | ||
|
|
||
| /*********************** | ||
| * STATIC PROTOTYPES | ||
| **********************/ | ||
|
|
||
| /********************** | ||
| * GLOBAL FUNCTIONS | ||
| **********************/ | ||
|
|
||
| lv_obj_t * segment_item_create(lv_obj_t * parent, const char * text) | ||
| { | ||
| LV_TRACE_OBJ_CREATE("begin"); | ||
|
|
||
| static lv_style_t style_base; | ||
| static lv_style_t style_checked; | ||
|
|
||
| static bool style_inited = false; | ||
|
|
||
| if (!style_inited) { | ||
| lv_style_init(&style_base); | ||
| lv_style_set_width(&style_base, 100); | ||
| lv_style_set_height(&style_base, lv_pct(100)); | ||
| lv_style_set_bg_color(&style_base, lv_color_hex(0x545454)); | ||
| lv_style_set_border_width(&style_base, 0); | ||
| lv_style_set_text_color(&style_base, lv_color_hex(0xffffff)); | ||
| lv_style_set_radius(&style_base, 0); | ||
|
|
||
| lv_style_init(&style_checked); | ||
| lv_style_set_bg_color(&style_checked, lv_color_hex(0xd3d3d3)); | ||
| lv_style_set_text_color(&style_checked, lv_color_hex(0x000000)); | ||
|
|
||
| style_inited = true; | ||
| } | ||
|
|
||
| lv_obj_t * lv_obj_0 = lv_obj_create(parent); | ||
| lv_obj_set_name_static(lv_obj_0, "segment_item_#"); | ||
| lv_obj_set_flag(lv_obj_0, LV_OBJ_FLAG_SCROLLABLE, false); | ||
|
|
||
| lv_obj_add_style(lv_obj_0, &style_base, 0); | ||
| lv_obj_add_style(lv_obj_0, &style_checked, LV_STATE_CHECKED); | ||
| lv_obj_t * lv_label_0 = lv_label_create(lv_obj_0); | ||
| lv_label_set_text(lv_label_0, text); | ||
| lv_obj_set_align(lv_label_0, LV_ALIGN_CENTER); | ||
|
|
||
| LV_TRACE_OBJ_CREATE("finished"); | ||
|
|
||
| return lv_obj_0; | ||
| } | ||
|
|
||
| /********************** | ||
| * STATIC FUNCTIONS | ||
| **********************/ | ||
|
|
46 changes: 46 additions & 0 deletions
46
tutorials/9_new_widget/components/segment_item/segment_item_gen.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| /** | ||
| * @file segment_item_gen.h | ||
| */ | ||
|
|
||
| #ifndef SEGMENT_ITEM_H | ||
| #define SEGMENT_ITEM_H | ||
|
|
||
| #ifdef __cplusplus | ||
| extern "C" { | ||
| #endif | ||
|
|
||
| /********************* | ||
| * INCLUDES | ||
| *********************/ | ||
|
|
||
| #ifdef LV_LVGL_H_INCLUDE_SIMPLE | ||
| #include "lvgl.h" | ||
| #include "src/core/lv_obj_class_private.h" | ||
| #else | ||
| #include "lvgl/lvgl.h" | ||
| #include "lvgl/src/core/lv_obj_class_private.h" | ||
| #endif | ||
|
|
||
| /********************* | ||
| * DEFINES | ||
| *********************/ | ||
|
|
||
| /********************** | ||
| * TYPEDEFS | ||
| **********************/ | ||
|
|
||
| /********************** | ||
| * GLOBAL PROTOTYPES | ||
| **********************/ | ||
|
|
||
| lv_obj_t * segment_item_create(lv_obj_t * parent, const char * text); | ||
|
|
||
| /********************** | ||
| * MACROS | ||
| **********************/ | ||
|
|
||
| #ifdef __cplusplus | ||
| } /*extern "C"*/ | ||
| #endif | ||
|
|
||
| #endif /*SEGMENT_ITEM_H*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| list( | ||
| APPEND | ||
| LV_EDITOR_PROJECT_SOURCES | ||
| ${CMAKE_CURRENT_LIST_DIR}/components/segment_item/segment_item_gen.c | ||
| ${CMAKE_CURRENT_LIST_DIR}/new_widget_gen.c | ||
| ${CMAKE_CURRENT_LIST_DIR}/new_widget.c | ||
| ${CMAKE_CURRENT_LIST_DIR}/screens/screen_widgets/screen_widgets_gen.c | ||
| ${CMAKE_CURRENT_LIST_DIR}/widgets/wd_segment/wd_segment_gen.c | ||
| ${CMAKE_CURRENT_LIST_DIR}/widgets/wd_segment/wd_segment_xml_parser.c | ||
| ${CMAKE_CURRENT_LIST_DIR}/widgets/wd_segment/wd_segment.c) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Place ttf or woff files here |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| <globals> | ||
| <api> | ||
| <!-- Add <enumdefs> here --> | ||
| </api> | ||
|
|
||
| <consts> | ||
| <!-- Add <px>, <int>, <color> etc here --> | ||
| </consts> | ||
|
|
||
| <styles> | ||
| <!-- Add <style> tags here --> | ||
| </styles> | ||
|
|
||
| <subjects> | ||
| <!-- Add <int>, <string>, or <float> subjects here --> | ||
| <int name="subject_segment" value="0" /> | ||
| </subjects> | ||
|
|
||
| <images> | ||
| <!-- Add <file> or <data> tags here --> | ||
| </images> | ||
|
|
||
| <fonts> | ||
| <!-- Add <bin> , <tiny_ttf>, <freetype> tags here --> | ||
| </fonts> | ||
| </globals> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Place PNG images here |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| /** | ||
| * @file new_widget.c | ||
| */ | ||
|
|
||
| /********************* | ||
| * INCLUDES | ||
| *********************/ | ||
|
|
||
| #include "new_widget.h" | ||
|
|
||
| /********************* | ||
| * DEFINES | ||
| *********************/ | ||
|
|
||
| /********************** | ||
| * TYPEDEFS | ||
| **********************/ | ||
|
|
||
| /********************** | ||
| * STATIC PROTOTYPES | ||
| **********************/ | ||
|
|
||
| /********************** | ||
| * STATIC VARIABLES | ||
| **********************/ | ||
|
|
||
| /********************** | ||
| * MACROS | ||
| **********************/ | ||
|
|
||
| /********************** | ||
| * GLOBAL FUNCTIONS | ||
| **********************/ | ||
|
|
||
| void new_widget_init(const char * asset_path) | ||
| { | ||
| new_widget_init_gen(asset_path); | ||
|
|
||
| /* Add your own custom code here if needed */ | ||
| } | ||
|
|
||
| /********************** | ||
| * STATIC FUNCTIONS | ||
| **********************/ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| /** | ||
| * @file new_widget.h | ||
| */ | ||
|
|
||
| #ifndef NEW_WIDGET_H | ||
| #define NEW_WIDGET_H | ||
|
|
||
| #ifdef __cplusplus | ||
| extern "C" { | ||
| #endif | ||
|
|
||
| /********************* | ||
| * INCLUDES | ||
| *********************/ | ||
|
|
||
| #include "new_widget_gen.h" | ||
|
|
||
| /********************* | ||
| * DEFINES | ||
| *********************/ | ||
|
|
||
| /********************** | ||
| * TYPEDEFS | ||
| **********************/ | ||
|
|
||
| /********************** | ||
| * GLOBAL VARIABLES | ||
| **********************/ | ||
|
|
||
| /********************** | ||
| * GLOBAL PROTOTYPES | ||
| **********************/ | ||
|
|
||
| /** | ||
| * Initialize the component library | ||
| */ | ||
| void new_widget_init(const char * asset_path); | ||
|
|
||
| /********************** | ||
| * MACROS | ||
| **********************/ | ||
|
|
||
| #ifdef __cplusplus | ||
| } /*extern "C"*/ | ||
| #endif | ||
|
|
||
| #endif /*NEW_WIDGET_H*/ |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think these
new_widgetfiles are not needed.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just confirming, isn't this the main entry point of the project?
I might need to rename the project name to
ui_new_widgetto follow the same conventionlvgl_editor/tutorials/2_new_component/ui_new_component.c
Lines 32 to 40 in 5581868