feat: Add the UI management function
This commit is contained in:
21
LVGL.Simulator/.vscode/c_cpp_properties.json
vendored
Normal file
21
LVGL.Simulator/.vscode/c_cpp_properties.json
vendored
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
{
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"name": "Win32",
|
||||||
|
"includePath": [
|
||||||
|
"${workspaceFolder}/**"
|
||||||
|
],
|
||||||
|
"defines": [
|
||||||
|
"_DEBUG",
|
||||||
|
"UNICODE",
|
||||||
|
"_UNICODE"
|
||||||
|
],
|
||||||
|
"windowsSdkVersion": "10.0.19041.0",
|
||||||
|
"compilerPath": "D:/APP1/Visual Studio/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe",
|
||||||
|
"cStandard": "c17",
|
||||||
|
"cppStandard": "c++17",
|
||||||
|
"intelliSenseMode": "windows-msvc-x64"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"version": 4
|
||||||
|
}
|
||||||
7
LVGL.Simulator/.vscode/settings.json
vendored
Normal file
7
LVGL.Simulator/.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"files.associations": {
|
||||||
|
"scr_mgr.h": "c",
|
||||||
|
"gui_main_scr.h": "c"
|
||||||
|
},
|
||||||
|
"C_Cpp.errorSquiggles": "Disabled"
|
||||||
|
}
|
||||||
@@ -1,4 +1,13 @@
|
|||||||
/*
|
/************************************************************************
|
||||||
|
* FilePath : LVGL.Simulator.cpp
|
||||||
|
* Author : GX.Duan
|
||||||
|
* Date : 2022-08-07 15:20:34
|
||||||
|
* LastEditTime : 2022-09-10 16:05:20
|
||||||
|
* LastEditors : ShallowGreen123 2608653986@qq.com
|
||||||
|
* Copyright (c): 2022 by GX.Duan, All Rights Reserved.
|
||||||
|
* Github : https://github.com/ShallowGreen123/lvgl_mydemo
|
||||||
|
************************************************************************/
|
||||||
|
/*
|
||||||
* PROJECT: LVGL PC Simulator using Visual Studio
|
* PROJECT: LVGL PC Simulator using Visual Studio
|
||||||
* FILE: LVGL.Simulator.cpp
|
* FILE: LVGL.Simulator.cpp
|
||||||
* PURPOSE: Implementation for LVGL ported to Windows Desktop
|
* PURPOSE: Implementation for LVGL ported to Windows Desktop
|
||||||
@@ -40,7 +49,7 @@ int main() {
|
|||||||
if (!lv_win32_init(
|
if (!lv_win32_init(
|
||||||
GetModuleHandleW(NULL),
|
GetModuleHandleW(NULL),
|
||||||
SW_SHOW,
|
SW_SHOW,
|
||||||
800,
|
480,
|
||||||
480,
|
480,
|
||||||
LoadIconW(GetModuleHandleW(NULL), MAKEINTRESOURCE(IDI_LVGL)))) {
|
LoadIconW(GetModuleHandleW(NULL), MAKEINTRESOURCE(IDI_LVGL)))) {
|
||||||
return -1;
|
return -1;
|
||||||
|
|||||||
@@ -36,6 +36,9 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="lvgl_mydemo\data\dataModel.h" />
|
<ClInclude Include="lvgl_mydemo\data\dataModel.h" />
|
||||||
<ClInclude Include="lvgl_mydemo\data\scr_mgr.h" />
|
<ClInclude Include="lvgl_mydemo\data\scr_mgr.h" />
|
||||||
|
<ClInclude Include="lvgl_mydemo\screen\gui_main_scr.h" />
|
||||||
|
<ClInclude Include="lvgl_mydemo\screen\gui_scr_mgr.h" />
|
||||||
|
<ClInclude Include="lvgl_mydemo\screen\gui_test1_scr.h" />
|
||||||
<ClInclude Include="lv_conf.h" />
|
<ClInclude Include="lv_conf.h" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
@@ -53,6 +56,9 @@
|
|||||||
<ClCompile Include="lvgl_mydemo\data\dataModel.c" />
|
<ClCompile Include="lvgl_mydemo\data\dataModel.c" />
|
||||||
<ClCompile Include="lvgl_mydemo\data\scr_mgr.c" />
|
<ClCompile Include="lvgl_mydemo\data\scr_mgr.c" />
|
||||||
<ClCompile Include="lvgl_mydemo\lvgl_app.c" />
|
<ClCompile Include="lvgl_mydemo\lvgl_app.c" />
|
||||||
|
<ClCompile Include="lvgl_mydemo\screen\gui_main_scr.c" />
|
||||||
|
<ClCompile Include="lvgl_mydemo\screen\gui_scr_mgr.c" />
|
||||||
|
<ClCompile Include="lvgl_mydemo\screen\gui_test1_scr.c" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ResourceCompile Include="LVGL.Simulator.rc" />
|
<ResourceCompile Include="LVGL.Simulator.rc" />
|
||||||
|
|||||||
@@ -11,6 +11,15 @@
|
|||||||
<ClInclude Include="lvgl_mydemo\data\scr_mgr.h">
|
<ClInclude Include="lvgl_mydemo\data\scr_mgr.h">
|
||||||
<Filter>lvgl_mydemo\data</Filter>
|
<Filter>lvgl_mydemo\data</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="lvgl_mydemo\screen\gui_scr_mgr.h">
|
||||||
|
<Filter>lvgl_mydemo\srceen</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="lvgl_mydemo\screen\gui_main_scr.h">
|
||||||
|
<Filter>lvgl_mydemo\srceen</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="lvgl_mydemo\screen\gui_test1_scr.h">
|
||||||
|
<Filter>lvgl_mydemo\srceen</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Manifest Include="LVGL.Simulator.manifest" />
|
<Manifest Include="LVGL.Simulator.manifest" />
|
||||||
@@ -30,6 +39,15 @@
|
|||||||
<ClCompile Include="lvgl_mydemo\data\scr_mgr.c">
|
<ClCompile Include="lvgl_mydemo\data\scr_mgr.c">
|
||||||
<Filter>lvgl_mydemo\data</Filter>
|
<Filter>lvgl_mydemo\data</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="lvgl_mydemo\screen\gui_main_scr.c">
|
||||||
|
<Filter>lvgl_mydemo\srceen</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="lvgl_mydemo\screen\gui_scr_mgr.c">
|
||||||
|
<Filter>lvgl_mydemo\srceen</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="lvgl_mydemo\screen\gui_test1_scr.c">
|
||||||
|
<Filter>lvgl_mydemo\srceen</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ResourceCompile Include="LVGL.Simulator.rc" />
|
<ResourceCompile Include="LVGL.Simulator.rc" />
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
* INCLUDES
|
* INCLUDES
|
||||||
* *******************************************************************************/
|
* *******************************************************************************/
|
||||||
#include "lvgl_app.h"
|
#include "lvgl_app.h"
|
||||||
|
#include "screen/gui_scr_mgr.h"
|
||||||
|
|
||||||
/*********************************************************************************
|
/*********************************************************************************
|
||||||
* DEFINES
|
* DEFINES
|
||||||
@@ -33,37 +34,9 @@
|
|||||||
* GLOBAL FUNCTION
|
* GLOBAL FUNCTION
|
||||||
* *******************************************************************************/
|
* *******************************************************************************/
|
||||||
|
|
||||||
void DataModel(DATA_MODEL_ID_E id) {
|
|
||||||
if (id == DATA_MODEL_ID_0) {
|
|
||||||
uint8_t val;
|
|
||||||
DataModelGetU8(id, &val);
|
|
||||||
printf("val = %d\n", val);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void lv_btn1_event_halder(lv_event_t *e) {
|
|
||||||
static uint8_t val = 0;
|
|
||||||
lv_event_code_t code = lv_event_get_code(e);
|
|
||||||
|
|
||||||
if (code == LV_EVENT_CLICKED) {
|
|
||||||
LV_LOG_USER("Clicked");
|
|
||||||
DataModelSetU8(DATA_MODEL_ID_0, ++val);
|
|
||||||
} else if (code == LV_EVENT_VALUE_CHANGED) {
|
|
||||||
LV_LOG_USER("Toggled");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void lvgl_app_init(void) {
|
void lvgl_app_init(void) {
|
||||||
DataModelInit();
|
DataModelInit();
|
||||||
DataModelRegister(DataModel);
|
|
||||||
|
|
||||||
lv_obj_t *btn1 = lv_btn_create(lv_scr_act());
|
ScrMgrInit();
|
||||||
lv_obj_set_size(btn1, 100, 50);
|
ScrMgrSwitchScr(GUI_MIAN_SCR_ID, true);
|
||||||
lv_obj_set_align(btn1, LV_ALIGN_CENTER);
|
|
||||||
|
|
||||||
lv_obj_t *label1 = lv_label_create(btn1);
|
|
||||||
lv_label_set_text(label1, "Buttom");
|
|
||||||
lv_obj_set_align(label1, LV_ALIGN_CENTER);
|
|
||||||
|
|
||||||
lv_obj_add_event_cb(btn1, lv_btn1_event_halder, LV_EVENT_ALL, NULL);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,12 @@
|
|||||||
|
/************************************************************************
|
||||||
|
* FilePath : lvgl_app.h
|
||||||
|
* Author : GX.Duan
|
||||||
|
* Date : 2022-08-07 15:20:41
|
||||||
|
* LastEditTime : 2022-09-10 15:58:18
|
||||||
|
* LastEditors : ShallowGreen123 2608653986@qq.com
|
||||||
|
* Copyright (c): 2022 by GX.Duan, All Rights Reserved.
|
||||||
|
* Github : https://github.com/ShallowGreen123/lvgl_mydemo
|
||||||
|
************************************************************************/
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* FilePath : lvgl_app.h
|
* FilePath : lvgl_app.h
|
||||||
* Author : GX.Duan
|
* Author : GX.Duan
|
||||||
@@ -16,6 +25,7 @@
|
|||||||
#include "../lvgl/lvgl.h"
|
#include "../lvgl/lvgl.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "data/dataModel.h"
|
#include "data/dataModel.h"
|
||||||
|
#include "screen/gui_scr_mgr.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
@@ -36,6 +46,10 @@ extern "C" {
|
|||||||
/*********************************************************************************
|
/*********************************************************************************
|
||||||
* TYPEDEFS
|
* TYPEDEFS
|
||||||
* *******************************************************************************/
|
* *******************************************************************************/
|
||||||
|
enum {
|
||||||
|
GUI_MIAN_SCR_ID = 0,
|
||||||
|
GUI_TEST1_SCR_ID,
|
||||||
|
};
|
||||||
|
|
||||||
/*********************************************************************************
|
/*********************************************************************************
|
||||||
* GLOBAL PROTOTYPES
|
* GLOBAL PROTOTYPES
|
||||||
|
|||||||
241
LVGL.Simulator/lvgl_mydemo/screen/.clang-format
Normal file
241
LVGL.Simulator/lvgl_mydemo/screen/.clang-format
Normal file
@@ -0,0 +1,241 @@
|
|||||||
|
# 语言: None, Cpp, Java, JavaScript, ObjC, Proto, TableGen, TextProto
|
||||||
|
Language: Cpp
|
||||||
|
# BasedOnStyle: LLVM
|
||||||
|
|
||||||
|
# 访问说明符(public、private等)的偏移
|
||||||
|
AccessModifierOffset: -4
|
||||||
|
|
||||||
|
# 开括号(开圆括号、开尖括号、开方括号)后的对齐: Align, DontAlign, AlwaysBreak(总是在开括号后换行)
|
||||||
|
AlignAfterOpenBracket: Align
|
||||||
|
|
||||||
|
# 连续赋值时,对齐所有等号
|
||||||
|
AlignConsecutiveAssignments: false
|
||||||
|
|
||||||
|
# 连续声明时,对齐所有声明的变量名仅跨越空格
|
||||||
|
AlignConsecutiveDeclarations: AcrossEmptyLines
|
||||||
|
|
||||||
|
# 右对齐逃脱换行(使用反斜杠换行)的反斜杠
|
||||||
|
AlignEscapedNewlines: Right
|
||||||
|
|
||||||
|
# 水平对齐二元和三元表达式的操作数
|
||||||
|
AlignOperands: true
|
||||||
|
|
||||||
|
# 对齐连续的尾随的注释
|
||||||
|
AlignTrailingComments: true
|
||||||
|
|
||||||
|
# 不允许函数声明的所有参数在放在下一行
|
||||||
|
AllowAllParametersOfDeclarationOnNextLine: false
|
||||||
|
|
||||||
|
# 不允许短的块放在同一行
|
||||||
|
AllowShortBlocksOnASingleLine: true
|
||||||
|
|
||||||
|
# 允许短的case标签放在同一行
|
||||||
|
AllowShortCaseLabelsOnASingleLine: true
|
||||||
|
|
||||||
|
# 允许短的函数放在同一行: None, InlineOnly(定义在类中), Empty(空函数), Inline(定义在类中,空函数), All
|
||||||
|
AllowShortFunctionsOnASingleLine: None
|
||||||
|
|
||||||
|
# 允许短的if语句保持在同一行
|
||||||
|
AllowShortIfStatementsOnASingleLine: true
|
||||||
|
|
||||||
|
# 允许短的循环保持在同一行
|
||||||
|
AllowShortLoopsOnASingleLine: true
|
||||||
|
|
||||||
|
# 总是在返回类型后换行: None, All, TopLevel(顶级函数,不包括在类中的函数),
|
||||||
|
# AllDefinitions(所有的定义,不包括声明), TopLevelDefinitions(所有的顶级函数的定义)
|
||||||
|
AlwaysBreakAfterReturnType: None
|
||||||
|
|
||||||
|
# 总是在多行string字面量前换行
|
||||||
|
AlwaysBreakBeforeMultilineStrings: false
|
||||||
|
|
||||||
|
# 总是在template声明后换行
|
||||||
|
AlwaysBreakTemplateDeclarations: true
|
||||||
|
|
||||||
|
# false表示函数实参要么都在同一行,要么都各自一行
|
||||||
|
BinPackArguments: true
|
||||||
|
|
||||||
|
# false表示所有形参要么都在同一行,要么都各自一行
|
||||||
|
BinPackParameters: true
|
||||||
|
|
||||||
|
|
||||||
|
BraceWrapping:
|
||||||
|
# class定义后面
|
||||||
|
AfterClass: false
|
||||||
|
# 控制语句后面
|
||||||
|
AfterControlStatement: MultiLine
|
||||||
|
# enum定义后面
|
||||||
|
AfterEnum: false
|
||||||
|
# 函数定义后面
|
||||||
|
AfterFunction: true
|
||||||
|
# 命名空间定义后面
|
||||||
|
AfterNamespace: false
|
||||||
|
# struct定义后面
|
||||||
|
AfterStruct: false
|
||||||
|
# union定义后面
|
||||||
|
AfterUnion: false
|
||||||
|
# extern之后
|
||||||
|
AfterExternBlock: false
|
||||||
|
# catch之前
|
||||||
|
BeforeCatch: false
|
||||||
|
# else之前
|
||||||
|
BeforeElse: false
|
||||||
|
# 缩进大括号
|
||||||
|
IndentBraces: false
|
||||||
|
# 分离空函数
|
||||||
|
SplitEmptyFunction: false
|
||||||
|
# 分离空语句
|
||||||
|
SplitEmptyRecord: false
|
||||||
|
# 分离空命名空间
|
||||||
|
SplitEmptyNamespace: false
|
||||||
|
# 在二元运算符前换行: None(在操作符后换行), NonAssignment(在非赋值的操作符前换行), All(在操作符前换行)
|
||||||
|
BreakBeforeBinaryOperators: NonAssignment
|
||||||
|
|
||||||
|
|
||||||
|
# 在大括号前换行: Attach(始终将大括号附加到周围的上下文), Linux(除函数、命名空间和类定义,与Attach类似),
|
||||||
|
# Mozilla(除枚举、函数、记录定义,与Attach类似), Stroustrup(除函数定义、catch、else,与Attach类似),
|
||||||
|
# Allman(总是在大括号前换行), GNU(总是在大括号前换行,并对于控制语句的大括号增加额外的缩进), WebKit(在函数前换行), Custom
|
||||||
|
# 注:这里认为语句块也属于函数
|
||||||
|
BreakBeforeBraces: Custom
|
||||||
|
|
||||||
|
# 在三元运算符前换行
|
||||||
|
BreakBeforeTernaryOperators: false
|
||||||
|
|
||||||
|
# 在构造函数的初始化列表的冒号后换行
|
||||||
|
BreakConstructorInitializers: AfterColon
|
||||||
|
|
||||||
|
#BreakInheritanceList: AfterColon
|
||||||
|
|
||||||
|
BreakStringLiterals: false
|
||||||
|
|
||||||
|
# 每行字符的限制,0表示没有限制
|
||||||
|
ColumnLimit: 0
|
||||||
|
|
||||||
|
CompactNamespaces: true
|
||||||
|
|
||||||
|
# 构造函数的初始化列表要么都在同一行,要么都各自一行
|
||||||
|
ConstructorInitializerAllOnOneLineOrOnePerLine: false
|
||||||
|
|
||||||
|
# 构造函数的初始化列表的缩进宽度
|
||||||
|
ConstructorInitializerIndentWidth: 4
|
||||||
|
|
||||||
|
# 延续的行的缩进宽度
|
||||||
|
ContinuationIndentWidth: 4
|
||||||
|
|
||||||
|
# 去除C++11的列表初始化的大括号{后和}前的空格
|
||||||
|
Cpp11BracedListStyle: true
|
||||||
|
|
||||||
|
# 继承最常用的指针和引用的对齐方式
|
||||||
|
DerivePointerAlignment: false
|
||||||
|
|
||||||
|
# 固定命名空间注释
|
||||||
|
FixNamespaceComments: true
|
||||||
|
|
||||||
|
# 缩进case标签
|
||||||
|
IndentCaseLabels: false
|
||||||
|
|
||||||
|
IndentPPDirectives: None
|
||||||
|
|
||||||
|
# 缩进宽度
|
||||||
|
IndentWidth: 4
|
||||||
|
|
||||||
|
# 函数返回类型换行时,缩进函数声明或函数定义的函数名
|
||||||
|
IndentWrappedFunctionNames: false
|
||||||
|
|
||||||
|
# 保留在块开始处的空行
|
||||||
|
KeepEmptyLinesAtTheStartOfBlocks: false
|
||||||
|
|
||||||
|
# 连续空行的最大数量
|
||||||
|
MaxEmptyLinesToKeep: 1
|
||||||
|
|
||||||
|
# 命名空间的缩进: None, Inner(缩进嵌套的命名空间中的内容), All
|
||||||
|
NamespaceIndentation: None
|
||||||
|
|
||||||
|
# 指针和引用的对齐: Left, Right, Middle
|
||||||
|
PointerAlignment: Right
|
||||||
|
|
||||||
|
# 允许重新排版注释
|
||||||
|
ReflowComments: true
|
||||||
|
|
||||||
|
# 允许排序#include
|
||||||
|
SortIncludes: false
|
||||||
|
|
||||||
|
# 允许排序 using 声明
|
||||||
|
SortUsingDeclarations: false
|
||||||
|
|
||||||
|
# 在C风格类型转换后添加空格
|
||||||
|
SpaceAfterCStyleCast: false
|
||||||
|
|
||||||
|
# 在Template 关键字后面添加空格
|
||||||
|
SpaceAfterTemplateKeyword: true
|
||||||
|
|
||||||
|
# 在赋值运算符之前添加空格
|
||||||
|
SpaceBeforeAssignmentOperators: true
|
||||||
|
|
||||||
|
# SpaceBeforeCpp11BracedList: true
|
||||||
|
|
||||||
|
# SpaceBeforeCtorInitializerColon: true
|
||||||
|
|
||||||
|
# SpaceBeforeInheritanceColon: true
|
||||||
|
|
||||||
|
# 开圆括号之前添加一个空格: Never, ControlStatements, Always
|
||||||
|
SpaceBeforeParens: ControlStatements
|
||||||
|
|
||||||
|
# SpaceBeforeRangeBasedForLoopColon: true
|
||||||
|
|
||||||
|
# 在空的圆括号中添加空格
|
||||||
|
SpaceInEmptyParentheses: false
|
||||||
|
|
||||||
|
# 在尾随的评论前添加的空格数(只适用于//)
|
||||||
|
SpacesBeforeTrailingComments: 1
|
||||||
|
|
||||||
|
# 在尖括号的<后和>前添加空格
|
||||||
|
SpacesInAngles: false
|
||||||
|
|
||||||
|
# 在C风格类型转换的括号中添加空格
|
||||||
|
SpacesInCStyleCastParentheses: false
|
||||||
|
|
||||||
|
# 在容器(ObjC和JavaScript的数组和字典等)字面量中添加空格
|
||||||
|
SpacesInContainerLiterals: true
|
||||||
|
|
||||||
|
# 在圆括号的(后和)前添加空格
|
||||||
|
SpacesInParentheses: false
|
||||||
|
|
||||||
|
# 在方括号的[后和]前添加空格,lamda表达式和未指明大小的数组的声明不受影响
|
||||||
|
SpacesInSquareBrackets: false
|
||||||
|
|
||||||
|
# 标准: Cpp03, Cpp11, Auto
|
||||||
|
Standard: Cpp11
|
||||||
|
|
||||||
|
# tab宽度
|
||||||
|
TabWidth: 4
|
||||||
|
|
||||||
|
# 使用tab字符: Never, ForIndentation, ForContinuationAndIndentation, Always
|
||||||
|
UseTab: Never
|
||||||
|
|
||||||
|
|
||||||
|
# case的缩进比switch多一级
|
||||||
|
IndentCaseLabels: true
|
||||||
|
|
||||||
|
#三元运算符将放置在换行符之后
|
||||||
|
BreakBeforeTernaryOperators: true
|
||||||
|
|
||||||
|
BreakBeforeBraces: Attach
|
||||||
|
|
||||||
|
AllowShortCaseLabelsOnASingleLine: false
|
||||||
|
|
||||||
|
#对齐注释
|
||||||
|
AlignTrailingComments: true
|
||||||
|
|
||||||
|
#水平对齐二元和三元表达式的操作数
|
||||||
|
AlignOperands: AlignAfterOperator
|
||||||
|
|
||||||
|
#对齐宏
|
||||||
|
AlignConsecutiveMacros: AcrossEmptyLinesAndComments
|
||||||
|
#对齐连续等号
|
||||||
|
AlignConsecutiveAssignments: AcrossEmptyLines
|
||||||
|
#对齐连续字段且跨越空行
|
||||||
|
AlignConsecutiveBitFields: AcrossEmptyLines
|
||||||
|
#对齐数组列并右对齐列
|
||||||
|
AlignArrayOfStructures: Right
|
||||||
|
#注释后的空格数
|
||||||
|
SpacesBeforeTrailingComments: 10
|
||||||
@@ -1,15 +1,18 @@
|
|||||||
/************************************************************************
|
/************************************************************************
|
||||||
* FilePath : gui_main_scr.c
|
* FilePath : gui_main_scr.c
|
||||||
* Author : GX.Duan
|
* Author : GX.Duan
|
||||||
* Date : 2022-08-19
|
* Date : 2022-08-19 00:25:00
|
||||||
* LastEditTime : 2022-08-19
|
* LastEditTime : 2022-09-10 16:01:12
|
||||||
* LastEditors : ShallowGreen123 2608653986@qq.com
|
* LastEditors : ShallowGreen123 2608653986@qq.com
|
||||||
* Copyright (c): by GX.Duan, All Rights Reserved.
|
* Copyright (c): 2022 by GX.Duan, All Rights Reserved.
|
||||||
* Github : https://github.com/ShallowGreen123/lvgl_mydemo
|
* Github : https://github.com/ShallowGreen123/lvgl_mydemo
|
||||||
************************************************************************/
|
************************************************************************/
|
||||||
|
#define __MAIN_SCR_C_
|
||||||
|
|
||||||
/*********************************************************************************
|
/*********************************************************************************
|
||||||
* INCLUDES
|
* INCLUDES
|
||||||
* *******************************************************************************/
|
* *******************************************************************************/
|
||||||
|
#include "gui_main_scr.h"
|
||||||
|
|
||||||
/*********************************************************************************
|
/*********************************************************************************
|
||||||
* DEFINES
|
* DEFINES
|
||||||
@@ -22,11 +25,70 @@
|
|||||||
/*********************************************************************************
|
/*********************************************************************************
|
||||||
* TYPEDEFS
|
* TYPEDEFS
|
||||||
* *******************************************************************************/
|
* *******************************************************************************/
|
||||||
|
static lv_obj_t *MainScrRoot = NULL;
|
||||||
|
static lv_obj_t *label = NULL;
|
||||||
|
|
||||||
|
static lv_obj_t *switch_btn = NULL;
|
||||||
|
static lv_obj_t *label2 = NULL;
|
||||||
|
|
||||||
/*********************************************************************************
|
/*********************************************************************************
|
||||||
* STATIC FUNCTION
|
* STATIC FUNCTION
|
||||||
* *******************************************************************************/
|
* *******************************************************************************/
|
||||||
|
void swithc_btn_event_cb(lv_event_t *e) {
|
||||||
|
lv_obj_t *obj = lv_event_get_target(e);
|
||||||
|
|
||||||
|
if (obj == switch_btn) {
|
||||||
|
printf("Screen 1 switch_btn is pressed!\n");
|
||||||
|
ScrMgrPushScr(GUI_TEST1_SCR_ID, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*********************************************************************************
|
/*********************************************************************************
|
||||||
* GLOBAL FUNCTION
|
* GLOBAL FUNCTION
|
||||||
* *******************************************************************************/
|
* *******************************************************************************/
|
||||||
|
static lv_obj_t *Gui_MainScrCreate(lv_obj_t *parent) {
|
||||||
|
MainScrRoot = lv_obj_create(parent);
|
||||||
|
lv_obj_set_size(MainScrRoot, lv_pct(100), lv_pct(100));
|
||||||
|
lv_obj_set_style_bg_color(MainScrRoot, lv_color_black(), LV_PART_MAIN);
|
||||||
|
|
||||||
|
label = lv_label_create(MainScrRoot);
|
||||||
|
lv_obj_set_style_text_color(label, lv_color_white(), LV_PART_MAIN);
|
||||||
|
lv_label_set_text(label, "Screen 1");
|
||||||
|
|
||||||
|
switch_btn = lv_btn_create(MainScrRoot);
|
||||||
|
lv_obj_set_size(switch_btn, 100, 40);
|
||||||
|
label2 = lv_label_create(switch_btn);
|
||||||
|
lv_label_set_text(label2, "switch");
|
||||||
|
|
||||||
|
return MainScrRoot;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void Gui_MainScrLayout(void) {
|
||||||
|
lv_obj_align_to(label, MainScrRoot, LV_ALIGN_CENTER, 0, -30);
|
||||||
|
|
||||||
|
lv_obj_center(label2);
|
||||||
|
lv_obj_align_to(switch_btn, MainScrRoot, LV_ALIGN_CENTER, 0, 30);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void Gui_MainScrEnter(void) {
|
||||||
|
Gui_MainScrLayout();
|
||||||
|
|
||||||
|
lv_obj_add_event_cb(switch_btn, swithc_btn_event_cb, LV_EVENT_CLICKED, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void Gui_MainScrExit(void) {
|
||||||
|
lv_obj_remove_event_cb(switch_btn, swithc_btn_event_cb);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void Gui_MainScrDestory(void) {
|
||||||
|
}
|
||||||
|
|
||||||
|
const SCR_MGR_SCR_HANDLE_T Gui_MainScrHandle = {
|
||||||
|
.ScrId = GUI_MIAN_SCR_ID,
|
||||||
|
.ScrCreate = Gui_MainScrCreate,
|
||||||
|
.ScrEnter = Gui_MainScrEnter,
|
||||||
|
.ScrExit = Gui_MainScrExit,
|
||||||
|
.ScrDestroy = Gui_MainScrDestory,
|
||||||
|
};
|
||||||
|
|
||||||
|
SCR_MGR_REG(Gui_MainScrHandle);
|
||||||
|
|||||||
@@ -1,6 +1,19 @@
|
|||||||
|
/************************************************************************
|
||||||
|
* FilePath : gui_main_scr.h
|
||||||
|
* Author : GX.Duan
|
||||||
|
* Date : 2022-08-19 00:25:14
|
||||||
|
* LastEditTime : 2022-09-10 15:49:50
|
||||||
|
* LastEditors : ShallowGreen123 2608653986@qq.com
|
||||||
|
* Copyright (c): 2022 by GX.Duan, All Rights Reserved.
|
||||||
|
* Github : https://github.com/ShallowGreen123/lvgl_mydemo
|
||||||
|
************************************************************************/
|
||||||
|
#ifndef __MAIN_SCR_H__
|
||||||
|
#define __MAIN_SCR_H__
|
||||||
|
|
||||||
/*********************************************************************************
|
/*********************************************************************************
|
||||||
* INCLUDES
|
* INCLUDES
|
||||||
* *******************************************************************************/
|
* *******************************************************************************/
|
||||||
|
#include "../lvgl_app.h"
|
||||||
|
|
||||||
/*********************************************************************************
|
/*********************************************************************************
|
||||||
* DEFINES
|
* DEFINES
|
||||||
@@ -9,6 +22,11 @@
|
|||||||
/*********************************************************************************
|
/*********************************************************************************
|
||||||
* MACROS
|
* MACROS
|
||||||
* *******************************************************************************/
|
* *******************************************************************************/
|
||||||
|
#ifdef __MAIN_SCR_C_
|
||||||
|
#define DEF_MAIN_SCR_EXT
|
||||||
|
#else
|
||||||
|
#define DEF_MAIN_SCR_EXT extern
|
||||||
|
#endif
|
||||||
|
|
||||||
/*********************************************************************************
|
/*********************************************************************************
|
||||||
* TYPEDEFS
|
* TYPEDEFS
|
||||||
@@ -16,4 +34,6 @@
|
|||||||
|
|
||||||
/*********************************************************************************
|
/*********************************************************************************
|
||||||
* GLOBAL PROTOTYPES
|
* GLOBAL PROTOTYPES
|
||||||
* *******************************************************************************/
|
* *******************************************************************************/
|
||||||
|
|
||||||
|
#endif /* __MAIN_SCR_H__ */
|
||||||
351
LVGL.Simulator/lvgl_mydemo/screen/gui_scr_mgr.c
Normal file
351
LVGL.Simulator/lvgl_mydemo/screen/gui_scr_mgr.c
Normal file
@@ -0,0 +1,351 @@
|
|||||||
|
/************************************************************************
|
||||||
|
* FilePath : gui_scr_mgr.c
|
||||||
|
* Author : GX.Duan
|
||||||
|
* Date : 2022-09-10 14:17:29
|
||||||
|
* LastEditTime : 2022-09-10 15:43:26
|
||||||
|
* LastEditors : ShallowGreen123 2608653986@qq.com
|
||||||
|
* Copyright (c): 2022 by GX.Duan, All Rights Reserved.
|
||||||
|
* Github : https://github.com/ShallowGreen123/lvgl_mydemo
|
||||||
|
************************************************************************/
|
||||||
|
#define __SCR_MGR_C__
|
||||||
|
|
||||||
|
/*********************************************************************************
|
||||||
|
* INCLUDES
|
||||||
|
* *******************************************************************************/
|
||||||
|
#include "gui_scr_mgr.h"
|
||||||
|
|
||||||
|
/*********************************************************************************
|
||||||
|
* DEFINES
|
||||||
|
* *******************************************************************************/
|
||||||
|
|
||||||
|
/*********************************************************************************
|
||||||
|
* MACROS
|
||||||
|
* *******************************************************************************/
|
||||||
|
|
||||||
|
/*********************************************************************************
|
||||||
|
* TYPEDEFS
|
||||||
|
* *******************************************************************************/
|
||||||
|
|
||||||
|
typedef struct scr_mgr_reg_scr_list_handle_t {
|
||||||
|
uint32_t ScrCnt;
|
||||||
|
SCR_MGR_SCR_HANDLE_T *ScrHandles[0];
|
||||||
|
} SCR_MGR_REG_SCR_LIST_HANDLE_T;
|
||||||
|
|
||||||
|
static SCR_MGR_REG_SCR_LIST_HANDLE_T *ScrMgrRegScrList;
|
||||||
|
static SCR_MGR_SCR_STACK_HANDLE_T *ScrMgrScrStackTop;
|
||||||
|
static SCR_MGR_SCR_STACK_HANDLE_T *ScrMgrScrStackRoot;
|
||||||
|
|
||||||
|
static const SCR_MGR_SCR_HANDLE_T *ScrMgrScrHandles[] = {
|
||||||
|
&Gui_MainScrHandle,
|
||||||
|
&Gui_Test1ScrHandle,
|
||||||
|
};
|
||||||
|
|
||||||
|
/*********************************************************************************
|
||||||
|
* STATIC FUNCTION
|
||||||
|
*********************************************************************************/
|
||||||
|
|
||||||
|
static SCR_MGR_SCR_HANDLE_T *ScrMgrFindScrById(uint32_t id) {
|
||||||
|
uint32_t i;
|
||||||
|
|
||||||
|
for (i = 0; i < ScrMgrRegScrList->ScrCnt; i++) {
|
||||||
|
if (ScrMgrRegScrList->ScrHandles[i]->ScrId == id) {
|
||||||
|
return ScrMgrRegScrList->ScrHandles[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ScrMgrStackScrActive(SCR_MGR_SCR_STACK_HANDLE_T *stack_item) {
|
||||||
|
if (stack_item->State == SCR_MGR_SCR_STATE_DESTROYED) {
|
||||||
|
stack_item->ScrObj = stack_item->ScrHandle->ScrCreate(NULL);
|
||||||
|
stack_item->ScrHandle->ScrEnter();
|
||||||
|
stack_item->State = SCR_MGR_SCR_STATE_ACTIVE;
|
||||||
|
} else if ((stack_item->State == SCR_MGR_SCR_STATE_CREATED) || (stack_item->State == SCR_MGR_SCR_STATE_INACTIVE)) {
|
||||||
|
stack_item->ScrHandle->ScrEnter();
|
||||||
|
stack_item->State = SCR_MGR_SCR_STATE_ACTIVE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ScrMgrStackScrInactive(SCR_MGR_SCR_STACK_HANDLE_T *stack_item) {
|
||||||
|
if (stack_item->State > SCR_MGR_SCR_STATE_INACTIVE) {
|
||||||
|
stack_item->ScrHandle->ScrExit();
|
||||||
|
stack_item->State = SCR_MGR_SCR_STATE_INACTIVE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ScrMgrStackScrDestroy(SCR_MGR_SCR_STACK_HANDLE_T *stack_item) {
|
||||||
|
if (stack_item->State > SCR_MGR_SCR_STATE_INACTIVE) {
|
||||||
|
stack_item->ScrHandle->ScrExit();
|
||||||
|
stack_item->ScrHandle->ScrDestroy();
|
||||||
|
stack_item->State = SCR_MGR_SCR_STATE_DESTROYED;
|
||||||
|
} else if (stack_item->State > SCR_MGR_SCR_STATE_DESTROYED) {
|
||||||
|
stack_item->ScrHandle->ScrDestroy();
|
||||||
|
stack_item->State = SCR_MGR_SCR_STATE_DESTROYED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ScrMgrStackScrRemove(SCR_MGR_SCR_STACK_HANDLE_T *stack_item) {
|
||||||
|
if (stack_item->State > SCR_MGR_SCR_STATE_INACTIVE) {
|
||||||
|
stack_item->ScrHandle->ScrExit();
|
||||||
|
stack_item->ScrHandle->ScrDestroy();
|
||||||
|
stack_item->State = SCR_MGR_SCR_STATE_IDLE;
|
||||||
|
} else if (stack_item->State > SCR_MGR_SCR_STATE_DESTROYED) {
|
||||||
|
stack_item->ScrHandle->ScrDestroy();
|
||||||
|
stack_item->State = SCR_MGR_SCR_STATE_IDLE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*********************************************************************************
|
||||||
|
* GLOBAL FUNCTION
|
||||||
|
*********************************************************************************/
|
||||||
|
|
||||||
|
void ScrMgrInit(void) {
|
||||||
|
uint32_t cnt = sizeof(ScrMgrScrHandles) / sizeof(ScrMgrScrHandles[0]);
|
||||||
|
uint32_t i;
|
||||||
|
|
||||||
|
LV_ASSERT(cnt);
|
||||||
|
ScrMgrScrStackRoot = NULL;
|
||||||
|
ScrMgrScrStackTop = NULL;
|
||||||
|
ScrMgrRegScrList = lv_mem_alloc(sizeof(SCR_MGR_REG_SCR_LIST_HANDLE_T) + cnt * sizeof(SCR_MGR_SCR_HANDLE_T *));
|
||||||
|
LV_ASSERT(ScrMgrRegScrList);
|
||||||
|
|
||||||
|
ScrMgrRegScrList->ScrCnt = cnt;
|
||||||
|
for (i = 0; i < cnt; i++) {
|
||||||
|
ScrMgrRegScrList->ScrHandles[i] = (SCR_MGR_SCR_HANDLE_T *)ScrMgrScrHandles[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ScrMgrSwitchScr(uint32_t scr_id, bool anim) {
|
||||||
|
SCR_MGR_SCR_HANDLE_T *tgt_scr = ScrMgrFindScrById(scr_id);
|
||||||
|
SCR_MGR_SCR_HANDLE_T *cur_scr = NULL;
|
||||||
|
lv_obj_t *cur_scr_obj = NULL;
|
||||||
|
SCR_MGR_SCR_STACK_HANDLE_T *stack_item = NULL;
|
||||||
|
|
||||||
|
if (tgt_scr == NULL) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ScrMgrScrStackTop != NULL) {
|
||||||
|
cur_scr = ScrMgrScrStackTop->ScrHandle;
|
||||||
|
cur_scr_obj = ScrMgrScrStackTop->ScrObj;
|
||||||
|
stack_item = ScrMgrScrStackTop->Prev;
|
||||||
|
ScrMgrStackScrRemove(ScrMgrScrStackTop);
|
||||||
|
lv_mem_free((void *)ScrMgrScrStackTop);
|
||||||
|
ScrMgrScrStackTop = stack_item;
|
||||||
|
}
|
||||||
|
while (ScrMgrScrStackTop != NULL) {
|
||||||
|
stack_item = ScrMgrScrStackTop->Prev;
|
||||||
|
ScrMgrStackScrRemove(ScrMgrScrStackTop);
|
||||||
|
lv_mem_free((void *)ScrMgrScrStackTop);
|
||||||
|
ScrMgrScrStackTop = stack_item;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((cur_scr != NULL) && (cur_scr->ScrId == tgt_scr->ScrId)) {
|
||||||
|
/* same scr, need destroy immediately, not support anim */
|
||||||
|
anim = false;
|
||||||
|
}
|
||||||
|
stack_item = lv_mem_alloc(sizeof(SCR_MGR_SCR_STACK_HANDLE_T));
|
||||||
|
stack_item->ScrHandle = tgt_scr;
|
||||||
|
stack_item->Next = NULL;
|
||||||
|
stack_item->Prev = NULL;
|
||||||
|
stack_item->ScrObj = tgt_scr->ScrCreate(NULL);
|
||||||
|
stack_item->State = SCR_MGR_SCR_STATE_CREATED;
|
||||||
|
ScrMgrScrStackRoot = stack_item;
|
||||||
|
ScrMgrScrStackTop = stack_item;
|
||||||
|
#if DEF_SCR_MGR_LITTLE_MEM
|
||||||
|
anim = false;
|
||||||
|
if (cur_scr_obj) {
|
||||||
|
lv_obj_del(cur_scr_obj);
|
||||||
|
cur_scr_obj = NULL;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
ScrMgrStackScrActive(stack_item);
|
||||||
|
if ((SCR_MSG_SCR_SWITCH_ANIM != LV_SCR_LOAD_ANIM_NONE) && anim) {
|
||||||
|
lv_scr_load_anim(stack_item->ScrObj, SCR_MSG_SCR_SWITCH_ANIM, SCR_MGR_SCR_TRANS_ANIM_INT, 0, true);
|
||||||
|
} else {
|
||||||
|
lv_scr_load(stack_item->ScrObj);
|
||||||
|
if (cur_scr_obj) {
|
||||||
|
lv_obj_del(cur_scr_obj);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ScrMgrPushScr(uint32_t scr_id, bool anim) {
|
||||||
|
SCR_MGR_SCR_HANDLE_T *tgt_scr = ScrMgrFindScrById(scr_id);
|
||||||
|
SCR_MGR_SCR_STACK_HANDLE_T *stack_item;
|
||||||
|
|
||||||
|
if (tgt_scr == NULL) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((ScrMgrScrStackTop != NULL) && (ScrMgrScrStackTop->ScrHandle->ScrId == tgt_scr->ScrId)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
#if DEF_SCR_MGR_LITTLE_MEM
|
||||||
|
anim = false;
|
||||||
|
if (ScrMgrScrStackTop != NULL) {
|
||||||
|
ScrMgrStackScrDestroy(ScrMgrScrStackTop);
|
||||||
|
lv_obj_del(ScrMgrScrStackTop->ScrObj);
|
||||||
|
ScrMgrScrStackTop->ScrObj = NULL;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
stack_item = lv_mem_alloc(sizeof(SCR_MGR_SCR_STACK_HANDLE_T));
|
||||||
|
stack_item->ScrHandle = tgt_scr;
|
||||||
|
stack_item->ScrObj = tgt_scr->ScrCreate(NULL);
|
||||||
|
stack_item->State = SCR_MGR_SCR_STATE_CREATED;
|
||||||
|
if (ScrMgrScrStackTop == NULL) {
|
||||||
|
ScrMgrScrStackRoot = stack_item;
|
||||||
|
ScrMgrScrStackTop = stack_item;
|
||||||
|
stack_item->Prev = NULL;
|
||||||
|
stack_item->Next = NULL;
|
||||||
|
} else {
|
||||||
|
ScrMgrStackScrInactive(ScrMgrScrStackTop);
|
||||||
|
ScrMgrScrStackTop->Next = stack_item;
|
||||||
|
stack_item->Prev = ScrMgrScrStackTop;
|
||||||
|
stack_item->Next = NULL;
|
||||||
|
ScrMgrScrStackTop = stack_item;
|
||||||
|
}
|
||||||
|
ScrMgrStackScrActive(stack_item);
|
||||||
|
if ((SCR_MSG_SCR_PUSH_ANIM != LV_SCR_LOAD_ANIM_NONE) && anim) {
|
||||||
|
lv_scr_load_anim(stack_item->ScrObj, SCR_MSG_SCR_PUSH_ANIM, SCR_MGR_SCR_TRANS_ANIM_INT, 0, false);
|
||||||
|
} else {
|
||||||
|
lv_scr_load(stack_item->ScrObj);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ScrMgrPopScr(bool anim) {
|
||||||
|
SCR_MGR_SCR_STACK_HANDLE_T *dst_item = NULL;
|
||||||
|
lv_obj_t *cur_scr_obj;
|
||||||
|
lv_obj_t *dst_scr_obj;
|
||||||
|
|
||||||
|
if ((ScrMgrScrStackTop == NULL) || (ScrMgrScrStackTop == ScrMgrScrStackRoot)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
cur_scr_obj = ScrMgrScrStackTop->ScrObj;
|
||||||
|
dst_item = ScrMgrScrStackTop->Prev;
|
||||||
|
ScrMgrStackScrRemove(ScrMgrScrStackTop);
|
||||||
|
lv_mem_free((void *)ScrMgrScrStackTop);
|
||||||
|
ScrMgrScrStackTop = dst_item;
|
||||||
|
|
||||||
|
#if DEF_SCR_MGR_LITTLE_MEM
|
||||||
|
anim = false;
|
||||||
|
if (cur_scr_obj) {
|
||||||
|
lv_obj_del(cur_scr_obj);
|
||||||
|
cur_scr_obj = NULL;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
ScrMgrStackScrActive(dst_item);
|
||||||
|
dst_scr_obj = dst_item->ScrObj;
|
||||||
|
if ((SCR_MSG_SCR_POP_ANIM != LV_SCR_LOAD_ANIM_NONE) && anim) {
|
||||||
|
lv_scr_load_anim(dst_scr_obj, SCR_MSG_SCR_POP_ANIM, SCR_MGR_SCR_TRANS_ANIM_INT, 0, true);
|
||||||
|
} else {
|
||||||
|
lv_scr_load(dst_scr_obj);
|
||||||
|
if (cur_scr_obj) {
|
||||||
|
lv_obj_del(cur_scr_obj);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ScrMgrPopNScr(uint32_t cnt, bool anim) {
|
||||||
|
SCR_MGR_SCR_STACK_HANDLE_T *dst_item = NULL;
|
||||||
|
lv_obj_t *cur_scr_obj;
|
||||||
|
lv_obj_t *dst_scr_obj;
|
||||||
|
uint32_t pop_cnt = 0;
|
||||||
|
|
||||||
|
if ((ScrMgrScrStackTop == NULL) || (ScrMgrScrStackTop == ScrMgrScrStackRoot)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
cur_scr_obj = ScrMgrScrStackTop->ScrObj;
|
||||||
|
dst_item = ScrMgrScrStackTop->Prev;
|
||||||
|
ScrMgrStackScrRemove(ScrMgrScrStackTop);
|
||||||
|
lv_mem_free((void *)ScrMgrScrStackTop);
|
||||||
|
ScrMgrScrStackTop = dst_item;
|
||||||
|
|
||||||
|
while ((++pop_cnt < cnt) && (ScrMgrScrStackTop != NULL) && (ScrMgrScrStackTop != ScrMgrScrStackRoot)) {
|
||||||
|
dst_item = ScrMgrScrStackTop->Prev;
|
||||||
|
ScrMgrStackScrRemove(ScrMgrScrStackTop);
|
||||||
|
lv_obj_del(ScrMgrScrStackTop->ScrObj);
|
||||||
|
lv_mem_free((void *)ScrMgrScrStackTop);
|
||||||
|
ScrMgrScrStackTop = dst_item;
|
||||||
|
}
|
||||||
|
#if DEF_SCR_MGR_LITTLE_MEM
|
||||||
|
anim = false;
|
||||||
|
if (cur_scr_obj) {
|
||||||
|
lv_obj_del(cur_scr_obj);
|
||||||
|
cur_scr_obj = NULL;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
ScrMgrStackScrActive(dst_item);
|
||||||
|
dst_scr_obj = dst_item->ScrObj;
|
||||||
|
if ((SCR_MSG_SCR_POP_ANIM != LV_SCR_LOAD_ANIM_NONE) && anim) {
|
||||||
|
lv_scr_load_anim(dst_scr_obj, SCR_MSG_SCR_POP_ANIM, SCR_MGR_SCR_TRANS_ANIM_INT, 0, true);
|
||||||
|
} else {
|
||||||
|
lv_scr_load(dst_scr_obj);
|
||||||
|
if (cur_scr_obj) {
|
||||||
|
lv_obj_del(cur_scr_obj);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ScrMgrPopToRoot(bool anim) {
|
||||||
|
SCR_MGR_SCR_STACK_HANDLE_T *dst_item = NULL;
|
||||||
|
lv_obj_t *cur_scr_obj;
|
||||||
|
|
||||||
|
if ((ScrMgrScrStackTop == NULL) || (ScrMgrScrStackTop == ScrMgrScrStackRoot)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
cur_scr_obj = ScrMgrScrStackTop->ScrObj;
|
||||||
|
dst_item = ScrMgrScrStackTop->Prev;
|
||||||
|
ScrMgrStackScrRemove(ScrMgrScrStackTop);
|
||||||
|
lv_mem_free((void *)ScrMgrScrStackTop);
|
||||||
|
ScrMgrScrStackTop = dst_item;
|
||||||
|
while ((ScrMgrScrStackTop != NULL) && (ScrMgrScrStackTop != ScrMgrScrStackRoot)) {
|
||||||
|
dst_item = ScrMgrScrStackTop->Prev;
|
||||||
|
ScrMgrStackScrRemove(ScrMgrScrStackTop);
|
||||||
|
lv_obj_del(ScrMgrScrStackTop->ScrObj);
|
||||||
|
lv_mem_free((void *)ScrMgrScrStackTop);
|
||||||
|
ScrMgrScrStackTop = dst_item;
|
||||||
|
}
|
||||||
|
ScrMgrScrStackTop = ScrMgrScrStackRoot;
|
||||||
|
#if DEF_SCR_MGR_LITTLE_MEM
|
||||||
|
anim = false;
|
||||||
|
if (cur_scr_obj) {
|
||||||
|
lv_obj_del(cur_scr_obj);
|
||||||
|
cur_scr_obj = NULL;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
ScrMgrStackScrActive(ScrMgrScrStackRoot);
|
||||||
|
if ((SCR_MSG_SCR_POP_ANIM != LV_SCR_LOAD_ANIM_NONE) && anim) {
|
||||||
|
lv_scr_load_anim(ScrMgrScrStackRoot->ScrObj, SCR_MSG_SCR_POP_ANIM, SCR_MGR_SCR_TRANS_ANIM_INT, 0, true);
|
||||||
|
} else {
|
||||||
|
lv_scr_load(ScrMgrScrStackRoot->ScrObj);
|
||||||
|
if (cur_scr_obj) {
|
||||||
|
lv_obj_del(cur_scr_obj);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ScrMgrTrimMem(void) {
|
||||||
|
SCR_MGR_SCR_STACK_HANDLE_T *stack_item = ScrMgrScrStackRoot;
|
||||||
|
|
||||||
|
while ((stack_item != NULL) && (stack_item != ScrMgrScrStackTop)) {
|
||||||
|
if (stack_item->State > SCR_MGR_SCR_STATE_DESTROYED) {
|
||||||
|
ScrMgrStackScrDestroy(stack_item);
|
||||||
|
lv_obj_del(stack_item->ScrObj);
|
||||||
|
stack_item->ScrObj = NULL;
|
||||||
|
}
|
||||||
|
stack_item = stack_item->Next;
|
||||||
|
}
|
||||||
|
}
|
||||||
94
LVGL.Simulator/lvgl_mydemo/screen/gui_scr_mgr.h
Normal file
94
LVGL.Simulator/lvgl_mydemo/screen/gui_scr_mgr.h
Normal file
@@ -0,0 +1,94 @@
|
|||||||
|
/************************************************************************
|
||||||
|
* Date: 2022-09-10 14:17:40
|
||||||
|
* LastEditors: ShallowGreen123 2608653986@qq.com
|
||||||
|
* LastEditTime: 2022-09-10 15:17:28
|
||||||
|
* FilePath: \LVGL.Simulator\lvgl_mydemo\screen\gui_scr_mgr.h
|
||||||
|
************************************************************************/
|
||||||
|
#ifndef __SCR_MGR_H__
|
||||||
|
#define __SCR_MGR_H__
|
||||||
|
|
||||||
|
/*********************************************************************************
|
||||||
|
* INCLUDES
|
||||||
|
* *******************************************************************************/
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include "../lvgl_app.h"
|
||||||
|
|
||||||
|
/*********************************************************************************
|
||||||
|
* DEFINES
|
||||||
|
* *******************************************************************************/
|
||||||
|
#define DEF_SCR_MGR_LITTLE_MEM 0
|
||||||
|
|
||||||
|
// #define SCR_MGR_REG(handle) \
|
||||||
|
// __attribute__((used, section("APP_SCREEN"))) const typeof(handle) *ScrMgrScrHandleList_##handle = &(handle)
|
||||||
|
|
||||||
|
#define SCR_MGR_REG(handle)
|
||||||
|
|
||||||
|
#define SCR_MGR_SCR_TRANS_ANIM_INT 300
|
||||||
|
#define SCR_MSG_SCR_SWITCH_ANIM LV_SCR_LOAD_ANIM_NONE
|
||||||
|
#define SCR_MSG_SCR_PUSH_ANIM LV_SCR_LOAD_ANIM_MOVE_LEFT
|
||||||
|
#define SCR_MSG_SCR_POP_ANIM LV_SCR_LOAD_ANIM_MOVE_RIGHT
|
||||||
|
|
||||||
|
/*********************************************************************************
|
||||||
|
* MACROS
|
||||||
|
* *******************************************************************************/
|
||||||
|
#ifdef __SCR_MGR_C__
|
||||||
|
#define DEF_SCR_MGR_EXT
|
||||||
|
#else
|
||||||
|
#define DEF_SCR_MGR_EXT extern
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*********************************************************************************
|
||||||
|
* TYPEDEFS
|
||||||
|
* *******************************************************************************/
|
||||||
|
typedef struct scr_mgr_scr_handle_t {
|
||||||
|
uint32_t ScrId;
|
||||||
|
lv_obj_t *(*ScrCreate)(lv_obj_t *parent);
|
||||||
|
void (*ScrEnter)(void);
|
||||||
|
void (*ScrExit)(void);
|
||||||
|
void (*ScrDestroy)(void);
|
||||||
|
} SCR_MGR_SCR_HANDLE_T;
|
||||||
|
|
||||||
|
typedef enum scr_mgr_scr_state_e {
|
||||||
|
SCR_MGR_SCR_STATE_IDLE = 0, /* Not in use */
|
||||||
|
SCR_MGR_SCR_STATE_DESTROYED, /* Not active and having been destroyed */
|
||||||
|
SCR_MGR_SCR_STATE_CREATED, /* Created */
|
||||||
|
SCR_MGR_SCR_STATE_INACTIVE, /* Not active */
|
||||||
|
SCR_MGR_SCR_STATE_ACTIVE_BG, /* Active but at the background */
|
||||||
|
SCR_MGR_SCR_STATE_ACTIVE, /* Active and at the foreground */
|
||||||
|
} SCR_MGR_SCR_STATE_E;
|
||||||
|
|
||||||
|
typedef struct scr_mgr_scr_stack_handle_t {
|
||||||
|
struct scr_mgr_scr_handle_t *ScrHandle;
|
||||||
|
lv_obj_t *ScrObj;
|
||||||
|
SCR_MGR_SCR_STATE_E State;
|
||||||
|
struct scr_mgr_scr_stack_handle_t *Prev;
|
||||||
|
struct scr_mgr_scr_stack_handle_t *Next;
|
||||||
|
} SCR_MGR_SCR_STACK_HANDLE_T;
|
||||||
|
|
||||||
|
/*********************************************************************************
|
||||||
|
* GLOBAL PROTOTYPES
|
||||||
|
* *******************************************************************************/
|
||||||
|
|
||||||
|
extern const SCR_MGR_SCR_HANDLE_T Gui_MainScrHandle;
|
||||||
|
extern const SCR_MGR_SCR_HANDLE_T Gui_Test1ScrHandle;
|
||||||
|
|
||||||
|
//
|
||||||
|
DEF_SCR_MGR_EXT void
|
||||||
|
ScrMgrInit(void);
|
||||||
|
|
||||||
|
/* Clear current stack and switch to new screen */
|
||||||
|
DEF_SCR_MGR_EXT bool ScrMgrSwitchScr(uint32_t scr_id, bool anim);
|
||||||
|
|
||||||
|
DEF_SCR_MGR_EXT bool ScrMgrPushScr(uint32_t scr_id, bool anim);
|
||||||
|
|
||||||
|
DEF_SCR_MGR_EXT bool ScrMgrPopScr(bool anim);
|
||||||
|
|
||||||
|
/* Pop n screen */
|
||||||
|
DEF_SCR_MGR_EXT bool ScrMgrPopNScr(uint32_t cnt, bool anim);
|
||||||
|
|
||||||
|
DEF_SCR_MGR_EXT bool ScrMgrPopToRoot(bool anim);
|
||||||
|
|
||||||
|
DEF_SCR_MGR_EXT void ScrMgrTrimMem(void);
|
||||||
|
|
||||||
|
#endif /* __SCR_MGR_H__ */
|
||||||
95
LVGL.Simulator/lvgl_mydemo/screen/gui_test1_scr.c
Normal file
95
LVGL.Simulator/lvgl_mydemo/screen/gui_test1_scr.c
Normal file
@@ -0,0 +1,95 @@
|
|||||||
|
/************************************************************************
|
||||||
|
* FilePath : gui_test1_scr.c
|
||||||
|
* Author : GX.Duan
|
||||||
|
* Date : 2022-09-10 17:10:59
|
||||||
|
* LastEditTime : 2022-09-10 17:13:08
|
||||||
|
* LastEditors : ShallowGreen123 2608653986@qq.com
|
||||||
|
* Copyright (c): 2022 by GX.Duan, All Rights Reserved.
|
||||||
|
* Github : https://github.com/ShallowGreen123/lvgl_mydemo
|
||||||
|
************************************************************************/
|
||||||
|
|
||||||
|
#define __MAIN_SCR_C_
|
||||||
|
|
||||||
|
/*********************************************************************************
|
||||||
|
* INCLUDES
|
||||||
|
* *******************************************************************************/
|
||||||
|
#include "gui_test1_scr.h"
|
||||||
|
|
||||||
|
/*********************************************************************************
|
||||||
|
* DEFINES
|
||||||
|
* *******************************************************************************/
|
||||||
|
|
||||||
|
/*********************************************************************************
|
||||||
|
* MACROS
|
||||||
|
* *******************************************************************************/
|
||||||
|
|
||||||
|
/*********************************************************************************
|
||||||
|
* TYPEDEFS
|
||||||
|
* *******************************************************************************/
|
||||||
|
static lv_obj_t *Test1ScrRoot = NULL;
|
||||||
|
static lv_obj_t *Test1Label = NULL;
|
||||||
|
|
||||||
|
static lv_obj_t *test1_btn = NULL;
|
||||||
|
static lv_obj_t *BtnLabel = NULL;
|
||||||
|
|
||||||
|
/*********************************************************************************
|
||||||
|
* STATIC FUNCTION
|
||||||
|
* *******************************************************************************/
|
||||||
|
void test1_btn_event_cb(lv_event_t *e) {
|
||||||
|
lv_obj_t *obj = lv_event_get_target(e);
|
||||||
|
|
||||||
|
if (obj == test1_btn) {
|
||||||
|
printf("Screen 2 test1_btn is pressed!\n");
|
||||||
|
ScrMgrPopScr(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*********************************************************************************
|
||||||
|
* GLOBAL FUNCTION
|
||||||
|
* *******************************************************************************/
|
||||||
|
static lv_obj_t *Gui_Test1ScrCreate(lv_obj_t *parent) {
|
||||||
|
Test1ScrRoot = lv_obj_create(parent);
|
||||||
|
lv_obj_set_size(Test1ScrRoot, lv_pct(100), lv_pct(100));
|
||||||
|
lv_obj_set_style_bg_color(Test1ScrRoot, lv_color_black(), LV_PART_MAIN);
|
||||||
|
|
||||||
|
Test1Label = lv_label_create(Test1ScrRoot);
|
||||||
|
lv_obj_set_style_text_color(Test1Label, lv_color_white(), LV_PART_MAIN);
|
||||||
|
lv_label_set_text(Test1Label, "Screen 2");
|
||||||
|
|
||||||
|
test1_btn = lv_btn_create(Test1ScrRoot);
|
||||||
|
lv_obj_set_size(test1_btn, 100, 40);
|
||||||
|
BtnLabel = lv_label_create(test1_btn);
|
||||||
|
lv_label_set_text(BtnLabel, "switch");
|
||||||
|
|
||||||
|
return Test1ScrRoot;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void Gui_Test1ScrLayout(void) {
|
||||||
|
lv_obj_align_to(Test1Label, Test1ScrRoot, LV_ALIGN_CENTER, 0, -30);
|
||||||
|
|
||||||
|
lv_obj_center(BtnLabel);
|
||||||
|
lv_obj_align_to(test1_btn, Test1ScrRoot, LV_ALIGN_CENTER, 0, 30);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void Gui_Test1ScrEnter(void) {
|
||||||
|
Gui_Test1ScrLayout();
|
||||||
|
|
||||||
|
lv_obj_add_event_cb(test1_btn, test1_btn_event_cb, LV_EVENT_CLICKED, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void Gui_Test1ScrExit(void) {
|
||||||
|
lv_obj_remove_event_cb(test1_btn, test1_btn_event_cb);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void Gui_Test1ScrDestory(void) {
|
||||||
|
}
|
||||||
|
|
||||||
|
const SCR_MGR_SCR_HANDLE_T Gui_Test1ScrHandle = {
|
||||||
|
.ScrId = GUI_TEST1_SCR_ID,
|
||||||
|
.ScrCreate = Gui_Test1ScrCreate,
|
||||||
|
.ScrEnter = Gui_Test1ScrEnter,
|
||||||
|
.ScrExit = Gui_Test1ScrExit,
|
||||||
|
.ScrDestroy = Gui_Test1ScrDestory,
|
||||||
|
};
|
||||||
|
|
||||||
|
SCR_MGR_REG(Gui_Test1ScrHandle);
|
||||||
39
LVGL.Simulator/lvgl_mydemo/screen/gui_test1_scr.h
Normal file
39
LVGL.Simulator/lvgl_mydemo/screen/gui_test1_scr.h
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
/************************************************************************
|
||||||
|
* FilePath : gui_test1_scr.h
|
||||||
|
* Author : GX.Duan
|
||||||
|
* Date : 2022-09-10 17:11:06
|
||||||
|
* LastEditTime : 2022-09-10 17:11:25
|
||||||
|
* LastEditors : ShallowGreen123 2608653986@qq.com
|
||||||
|
* Copyright (c): 2022 by GX.Duan, All Rights Reserved.
|
||||||
|
* Github : https://github.com/ShallowGreen123/lvgl_mydemo
|
||||||
|
************************************************************************/
|
||||||
|
#ifndef __TEST1_SCR_H__
|
||||||
|
#define __TEST1_SCR_H__
|
||||||
|
|
||||||
|
/*********************************************************************************
|
||||||
|
* INCLUDES
|
||||||
|
* *******************************************************************************/
|
||||||
|
#include "../lvgl_app.h"
|
||||||
|
|
||||||
|
/*********************************************************************************
|
||||||
|
* DEFINES
|
||||||
|
* *******************************************************************************/
|
||||||
|
|
||||||
|
/*********************************************************************************
|
||||||
|
* MACROS
|
||||||
|
* *******************************************************************************/
|
||||||
|
#ifdef __TEST1_SCR_C_
|
||||||
|
#define DEF_TEST1_SCR_EXT
|
||||||
|
#else
|
||||||
|
#define DEF_TEST1_SCR_EXT extern
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*********************************************************************************
|
||||||
|
* TYPEDEFS
|
||||||
|
* *******************************************************************************/
|
||||||
|
|
||||||
|
/*********************************************************************************
|
||||||
|
* GLOBAL PROTOTYPES
|
||||||
|
* *******************************************************************************/
|
||||||
|
|
||||||
|
#endif /* __TEST1_SCR_H__ */
|
||||||
Reference in New Issue
Block a user