From 387500dce7a937e94fea8ec388f20cbb0b81cb61 Mon Sep 17 00:00:00 2001 From: fourleaf Date: Fri, 22 Nov 2024 16:18:39 +0800 Subject: [PATCH 1/2] Add flag variable and state variable support for [create_screen_...] functions --- packages/project-editor/lvgl/widgets/Base.tsx | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/packages/project-editor/lvgl/widgets/Base.tsx b/packages/project-editor/lvgl/widgets/Base.tsx index d19d5011..37d94856 100644 --- a/packages/project-editor/lvgl/widgets/Base.tsx +++ b/packages/project-editor/lvgl/widgets/Base.tsx @@ -1989,6 +1989,39 @@ export class LVGLWidget extends Widget { ); } } + if (this.hiddenFlagType == "expression") { + build.line(`{`); + build.indent(); + + build.line( + `bool val = ${build.getVariableGetterFunctionName( + this.hiddenFlag as string + )}();` + ); + + build.line(`if (val) lv_obj_add_flag(obj, LV_OBJ_FLAG_HIDDEN);`); + build.line(`else lv_obj_clear_flag(obj, LV_OBJ_FLAG_HIDDEN);`); + + build.unindent(); + build.line(`}`); + } + + if (this.clickableFlagType == "expression") { + build.line(`{`); + build.indent(); + + build.line( + `bool val = ${build.getVariableGetterFunctionName( + this.clickableFlag as string + )}();` + ); + + build.line(`if (val) lv_obj_add_flag(obj, LV_OBJ_FLAG_CLICKABLE);`); + build.line(`else lv_obj_clear_flag(obj, LV_OBJ_FLAG_CLICKABLE);`); + + build.unindent(); + build.line(`}`); + } if (this.flagScrollbarMode) { build.line( @@ -2031,6 +2064,39 @@ export class LVGLWidget extends Widget { ); } } + if (this.checkedStateType == "expression") { + build.line(`{`); + build.indent(); + + build.line( + `bool val = ${build.getVariableGetterFunctionName( + this.checkedState as string + )}();` + ); + + build.line(`if (val) lv_obj_add_state(obj, LV_STATE_CHECKED);`); + build.line(`else lv_obj_clear_state(obj, LV_STATE_CHECKED);`); + + build.unindent(); + build.line(`}`); + } + + if (this.disabledStateType == "expression") { + build.line(`{`); + build.indent(); + + build.line( + `bool val = ${build.getVariableGetterFunctionName( + this.disabledState as string + )}();` + ); + + build.line(`if (val) lv_obj_add_state(obj, LV_STATE_DISABLED);`); + build.line(`else lv_obj_clear_state(obj, LV_STATE_DISABLED);`); + + build.unindent(); + build.line(`}`); + } const useStyle = this.styleTemplate; if (useStyle) { From 6bf77c3ed275ec1ca9b9ec752e91d4180087ad28 Mon Sep 17 00:00:00 2001 From: fourleaf Date: Mon, 25 Nov 2024 14:20:25 +0800 Subject: [PATCH 2/2] add flow support for flag and state variable use in [create_screen_xxx] function. --- packages/project-editor/lvgl/widgets/Base.tsx | 88 ++++++++++++++----- 1 file changed, 68 insertions(+), 20 deletions(-) diff --git a/packages/project-editor/lvgl/widgets/Base.tsx b/packages/project-editor/lvgl/widgets/Base.tsx index 37d94856..b6a1e9ff 100644 --- a/packages/project-editor/lvgl/widgets/Base.tsx +++ b/packages/project-editor/lvgl/widgets/Base.tsx @@ -1993,11 +1993,23 @@ export class LVGLWidget extends Widget { build.line(`{`); build.indent(); - build.line( - `bool val = ${build.getVariableGetterFunctionName( - this.hiddenFlag as string - )}();` - ); + if (build.assets.projectStore.projectTypeTraits.hasFlowSupport) { + let componentIndex = build.assets.getComponentIndex(this); + const propertyIndex = build.assets.getComponentPropertyIndex( + this, + "hiddenFlag" + ); + + build.line( + `bool val = evalBooleanProperty(flowState, ${componentIndex}, ${propertyIndex}, "Failed to evaluate Hidden flag");` + ); + } else { + build.line( + `bool val = ${build.getVariableGetterFunctionName( + this.hiddenFlag as string + )}();` + ); + } build.line(`if (val) lv_obj_add_flag(obj, LV_OBJ_FLAG_HIDDEN);`); build.line(`else lv_obj_clear_flag(obj, LV_OBJ_FLAG_HIDDEN);`); @@ -2010,11 +2022,23 @@ export class LVGLWidget extends Widget { build.line(`{`); build.indent(); - build.line( - `bool val = ${build.getVariableGetterFunctionName( - this.clickableFlag as string - )}();` - ); + if (build.assets.projectStore.projectTypeTraits.hasFlowSupport) { + let componentIndex = build.assets.getComponentIndex(this); + const propertyIndex = build.assets.getComponentPropertyIndex( + this, + "clickableFlag" + ); + + build.line( + `bool val = evalBooleanProperty(flowState, ${componentIndex}, ${propertyIndex}, "Failed to evaluate Hidden flag");` + ); + } else { + build.line( + `bool val = ${build.getVariableGetterFunctionName( + this.clickableFlag as string + )}();` + ); + } build.line(`if (val) lv_obj_add_flag(obj, LV_OBJ_FLAG_CLICKABLE);`); build.line(`else lv_obj_clear_flag(obj, LV_OBJ_FLAG_CLICKABLE);`); @@ -2068,11 +2092,23 @@ export class LVGLWidget extends Widget { build.line(`{`); build.indent(); - build.line( - `bool val = ${build.getVariableGetterFunctionName( - this.checkedState as string - )}();` - ); + if (build.assets.projectStore.projectTypeTraits.hasFlowSupport) { + let componentIndex = build.assets.getComponentIndex(this); + const propertyIndex = build.assets.getComponentPropertyIndex( + this, + "checkedState" + ); + + build.line( + `bool val = evalBooleanProperty(flowState, ${componentIndex}, ${propertyIndex}, "Failed to evaluate Checked state");` + ); + } else { + build.line( + `bool val = ${build.getVariableGetterFunctionName( + this.checkedState as string + )}();` + ); + } build.line(`if (val) lv_obj_add_state(obj, LV_STATE_CHECKED);`); build.line(`else lv_obj_clear_state(obj, LV_STATE_CHECKED);`); @@ -2085,11 +2121,23 @@ export class LVGLWidget extends Widget { build.line(`{`); build.indent(); - build.line( - `bool val = ${build.getVariableGetterFunctionName( - this.disabledState as string - )}();` - ); + if (build.assets.projectStore.projectTypeTraits.hasFlowSupport) { + let componentIndex = build.assets.getComponentIndex(this); + const propertyIndex = build.assets.getComponentPropertyIndex( + this, + "disabledState" + ); + + build.line( + `bool val = evalBooleanProperty(flowState, ${componentIndex}, ${propertyIndex}, "Failed to evaluate Disabled state");` + ); + } else { + build.line( + `bool val = ${build.getVariableGetterFunctionName( + this.disabledState as string + )}();` + ); + } build.line(`if (val) lv_obj_add_state(obj, LV_STATE_DISABLED);`); build.line(`else lv_obj_clear_state(obj, LV_STATE_DISABLED);`);