diff --git a/packages/project-editor/flow/runtime/cpp/eez-framework b/packages/project-editor/flow/runtime/cpp/eez-framework index ca74f143..1f54d734 160000 --- a/packages/project-editor/flow/runtime/cpp/eez-framework +++ b/packages/project-editor/flow/runtime/cpp/eez-framework @@ -1 +1 @@ -Subproject commit ca74f143c589ae87fb5617d7799d5cc418c825b0 +Subproject commit 1f54d7345540e8962cd3b52f3a7d48b1fc5a5f3d diff --git a/packages/project-editor/flow/runtime/cpp/lvgl-runtime/common/src/flow.cpp b/packages/project-editor/flow/runtime/cpp/lvgl-runtime/common/src/flow.cpp index e345b9da..626f8488 100644 --- a/packages/project-editor/flow/runtime/cpp/lvgl-runtime/common/src/flow.cpp +++ b/packages/project-editor/flow/runtime/cpp/lvgl-runtime/common/src/flow.cpp @@ -951,7 +951,7 @@ EM_PORT_API(lv_group_t *) lvglCreateGroup() { } EM_PORT_API(void) lvglAddScreenLoadedEventHandler(lv_obj_t *screenObj) { - lv_obj_add_event_cb(screenObj, screen_loaded_event_callback, LV_EVENT_SCREEN_LOADED, 0); + lv_obj_add_event_cb(screenObj, screen_loaded_event_callback, LV_EVENT_SCREEN_LOAD_START, 0); } EM_PORT_API(void) lvglGroupAddObject(lv_obj_t *screenObj, lv_group_t *groupObj, lv_obj_t *obj) { diff --git a/packages/project-editor/flow/runtime/lvgl_runtime_v8.3.wasm b/packages/project-editor/flow/runtime/lvgl_runtime_v8.3.wasm index 7a47df9a..5f37d99f 100644 Binary files a/packages/project-editor/flow/runtime/lvgl_runtime_v8.3.wasm and b/packages/project-editor/flow/runtime/lvgl_runtime_v8.3.wasm differ diff --git a/packages/project-editor/flow/runtime/lvgl_runtime_v9.0.wasm b/packages/project-editor/flow/runtime/lvgl_runtime_v9.0.wasm index af979221..7fad0fbb 100644 Binary files a/packages/project-editor/flow/runtime/lvgl_runtime_v9.0.wasm and b/packages/project-editor/flow/runtime/lvgl_runtime_v9.0.wasm differ diff --git a/packages/project-editor/lvgl/actions.tsx b/packages/project-editor/lvgl/actions.tsx index 7c374b26..e5038f96 100644 --- a/packages/project-editor/lvgl/actions.tsx +++ b/packages/project-editor/lvgl/actions.tsx @@ -61,7 +61,7 @@ import { import { buildExpression } from "project-editor/flow/expression"; import { escapeCString } from "./widget-common"; import { getLvglFlagCodes } from "./lvgl-versions"; -import { LVGL_FLAG_CODES } from "./lvgl-constants"; +import { LVGL_FLAG_CODES, LVGL_STATE_CODES } from "./lvgl-constants"; //////////////////////////////////////////////////////////////////////////////// @@ -73,6 +73,8 @@ const LVGL_ACTIONS = { REMOVE_STYLE: 4, ADD_FLAG: 5, CLEAR_FLAG: 6, + ADD_STATE: 8, + CLEAR_STATE: 9, GROUP: 7 }; @@ -97,6 +99,10 @@ export class LVGLActionType extends EezObject { return LVGLAddFlagActionType; else if (jsObject.action == "CLEAR_FLAG") return LVGLClearFlagActionType; + else if (jsObject.action == "ADD_STATE") + return LVGLAddStateActionType; + else if (jsObject.action == "CLEAR_STATE") + return LVGLClearStateActionType; else return LVGLGroupActionType; }, @@ -212,6 +218,24 @@ export class LVGLActionType extends EezObject { ), LVGLClearFlagActionType ); + } else if (result.values.action == "ADD_STATE") { + actionTypeObject = createObject( + project._store, + Object.assign( + actionTypeProperties, + LVGLAddStateActionType.classInfo.defaultValue + ), + LVGLAddStateActionType + ); + } else if (result.values.action == "CLEAR_STATE") { + actionTypeObject = createObject( + project._store, + Object.assign( + actionTypeProperties, + LVGLClearStateActionType.classInfo.defaultValue + ), + LVGLClearStateActionType + ); } else if (result.values.action == "GROUP") { actionTypeObject = createObject( project._store, @@ -1557,6 +1581,208 @@ registerClass("LVGLClearFlagActionType", LVGLClearFlagActionType); //////////////////////////////////////////////////////////////////////////////// +export class LVGLAddStateActionType extends LVGLActionType { + target: string; + state: keyof typeof LVGL_STATE_CODES; + + override makeEditable() { + super.makeEditable(); + + makeObservable(this, { + target: observable, + state: observable + }); + } + + static classInfo = makeDerivedClassInfo(LVGLActionType.classInfo, { + properties: [ + { + name: "target", + displayName: "Target", + type: PropertyType.Enum, + enumItems: (actionType: LVGLAddStateActionType) => { + const lvglIdentifiers = ProjectEditor.getProjectStore( + actionType + ).lvglIdentifiers.getIdentifiersVisibleFromFlow( + ProjectEditor.getFlow(actionType) + ); + + return lvglIdentifiers.map(lvglIdentifier => ({ + id: lvglIdentifier.identifier, + label: lvglIdentifier.identifier + })); + } + }, + { + name: "state", + type: PropertyType.Enum, + enumItems: (actionType: LVGLAddStateActionType) => { + return Object.keys(LVGL_STATE_CODES).map(state => ({ + id: state, + label: state + })); + } + } + ], + defaultValue: {}, + listLabel: (action: LVGLAddStateActionType, collapsed: boolean) => { + if (!collapsed) { + return "Add state"; + } + let singleItem = + (getParent(action) as LVGLActionType[]).length == 1; + if (singleItem) { + return ( + <> + {action.state} in {action.target} + + ); + } else { + return ( + <> + Add state {action.state} in {action.target} + + ); + } + }, + check: (object: LVGLAddStateActionType, messages: IMessage[]) => { + const projectStore = ProjectEditor.getProjectStore(object); + + if (object.target) { + const lvglIdentifier = + projectStore.lvglIdentifiers.getIdentifierByName( + ProjectEditor.getFlow(object), + object.target + ); + + if (lvglIdentifier == undefined) { + messages.push(propertyNotFoundMessage(object, "target")); + } + } else { + messages.push(propertyNotSetMessage(object, "target")); + } + } + }); + + override build(assets: Assets, dataBuffer: DataBuffer) { + // target + dataBuffer.writeInt32( + assets.projectStore.lvglIdentifiers.getIdentifierByName( + ProjectEditor.getFlow(this), + this.target + )?.index ?? -1 + ); + + // state + dataBuffer.writeUint32(LVGL_STATE_CODES[this.state] ?? 0); + } +} + +registerClass("LVGLAddStateActionType", LVGLAddStateActionType); + +//////////////////////////////////////////////////////////////////////////////// + +export class LVGLClearStateActionType extends LVGLActionType { + target: string; + state: keyof typeof LVGL_STATE_CODES; + + override makeEditable() { + super.makeEditable(); + + makeObservable(this, { + target: observable, + state: observable + }); + } + + static classInfo = makeDerivedClassInfo(LVGLActionType.classInfo, { + properties: [ + { + name: "target", + displayName: "Target", + type: PropertyType.Enum, + enumItems: (actionType: LVGLClearStateActionType) => { + const lvglIdentifiers = ProjectEditor.getProjectStore( + actionType + ).lvglIdentifiers.getIdentifiersVisibleFromFlow( + ProjectEditor.getFlow(actionType) + ); + + return lvglIdentifiers.map(lvglIdentifier => ({ + id: lvglIdentifier.identifier, + label: lvglIdentifier.identifier + })); + } + }, + { + name: "state", + type: PropertyType.Enum, + enumItems: (actionType: LVGLClearStateActionType) => { + return Object.keys(LVGL_STATE_CODES).map(state => ({ + id: state, + label: state + })); + } + } + ], + defaultValue: {}, + listLabel: (action: LVGLClearStateActionType, collapsed: boolean) => { + if (!collapsed) { + return "Clear state"; + } + let singleItem = + (getParent(action) as LVGLActionType[]).length == 1; + if (singleItem) { + return ( + <> + {action.state} in {action.target} + + ); + } else { + return ( + <> + Clear state {action.state} in {action.target} + + ); + } + }, + check: (object: LVGLClearStateActionType, messages: IMessage[]) => { + const projectStore = ProjectEditor.getProjectStore(object); + + if (object.target) { + const lvglIdentifier = + projectStore.lvglIdentifiers.getIdentifierByName( + ProjectEditor.getFlow(object), + object.target + ); + + if (lvglIdentifier == undefined) { + messages.push(propertyNotFoundMessage(object, "target")); + } + } else { + messages.push(propertyNotSetMessage(object, "target")); + } + } + }); + + override build(assets: Assets, dataBuffer: DataBuffer) { + // target + dataBuffer.writeInt32( + assets.projectStore.lvglIdentifiers.getIdentifierByName( + ProjectEditor.getFlow(this), + this.target + )?.index ?? -1 + ); + + // state + dataBuffer.writeUint32(LVGL_STATE_CODES[this.state] ?? 0); + } +} + +registerClass("LVGLClearStateActionType", LVGLClearStateActionType); + +//////////////////////////////////////////////////////////////////////////////// + const GROUP_ACTIONS = { SET_WRAP: 0, FOCUS_OBJ: 1, diff --git a/packages/project-editor/lvgl/page-runtime.ts b/packages/project-editor/lvgl/page-runtime.ts index 89600abd..09a9a86d 100644 --- a/packages/project-editor/lvgl/page-runtime.ts +++ b/packages/project-editor/lvgl/page-runtime.ts @@ -762,7 +762,6 @@ export class LVGLPageViewerRuntime extends LVGLPageRuntime { // add widgets to groups for (const page of this.pages) { if (page._lvglObj) { - this.wasm._lvglAddScreenLoadedEventHandler(page._lvglObj); for ( let i = 0; i < this.project.lvglGroups.groups.length; @@ -829,6 +828,8 @@ export class LVGLPageViewerRuntime extends LVGLPageRuntime { const pageObj = this.page.lvglCreate(this, 0); + this.wasm._lvglAddScreenLoadedEventHandler(pageObj); + runInAction(() => { this.page._lvglObj = pageObj; }); diff --git a/resources/eez-framework-amalgamation/eez-flow.cpp b/resources/eez-framework-amalgamation/eez-flow.cpp index c934991b..838602c1 100644 --- a/resources/eez-framework-amalgamation/eez-flow.cpp +++ b/resources/eez-framework-amalgamation/eez-flow.cpp @@ -1,4 +1,4 @@ -/* Autogenerated on September 27, 2024 2:31:05 PM from eez-framework commit ca74f143c589ae87fb5617d7799d5cc418c825b0 */ +/* Autogenerated on October 1, 2024 11:29:42 AM from eez-framework commit ca74f143c589ae87fb5617d7799d5cc418c825b0 */ /* * eez-framework * @@ -4066,6 +4066,32 @@ void executeLVGLComponent(FlowState *flowState, unsigned componentIndex) { lv_group_set_editing(target, specific->enable ? true : false); } } + } else if (general->action == ADD_STATE) { + auto specific = (LVGLComponent_AddState_ActionType *)general; + auto target = getLvglObjectFromIndexHook(flowState->lvglWidgetStartIndex + specific->target); + if (!target) { + if (!executionState) { + executionState = allocateComponentExecutionState(flowState, componentIndex); + } + executionState->actionIndex = actionIndex; + addToQueue(flowState, componentIndex, -1, -1, -1, true); + return; + } else { + lv_obj_add_state(target, (lv_state_t)specific->state); + } + } else if (general->action == CLEAR_STATE) { + auto specific = (LVGLComponent_ClearState_ActionType *)general; + auto target = getLvglObjectFromIndexHook(flowState->lvglWidgetStartIndex + specific->target); + if (!target) { + if (!executionState) { + executionState = allocateComponentExecutionState(flowState, componentIndex); + } + executionState->actionIndex = actionIndex; + addToQueue(flowState, componentIndex, -1, -1, -1, true); + return; + } else { + lv_obj_clear_state(target, (lv_state_t)specific->state); + } } } propagateValueThroughSeqout(flowState, componentIndex); diff --git a/resources/eez-framework-amalgamation/eez-flow.h b/resources/eez-framework-amalgamation/eez-flow.h index c7dcb6aa..95cafcdc 100644 --- a/resources/eez-framework-amalgamation/eez-flow.h +++ b/resources/eez-framework-amalgamation/eez-flow.h @@ -1,4 +1,4 @@ -/* Autogenerated on September 27, 2024 2:31:05 PM from eez-framework commit ca74f143c589ae87fb5617d7799d5cc418c825b0 */ +/* Autogenerated on October 1, 2024 11:29:42 AM from eez-framework commit ca74f143c589ae87fb5617d7799d5cc418c825b0 */ /* * eez-framework * @@ -2653,7 +2653,9 @@ enum LVGL_ACTIONS { REMOVE_STYLE, ADD_FLAG, CLEAR_FLAG, - GROUP + GROUP, + ADD_STATE, + CLEAR_STATE, }; struct LVGLComponent_ActionType { uint32_t action; @@ -2717,6 +2719,14 @@ struct LVGLComponent_Group_ActionType : public LVGLComponent_ActionType { int32_t target; uint32_t enable; }; +struct LVGLComponent_AddState_ActionType : public LVGLComponent_ActionType { + int32_t target; + uint32_t state; +}; +struct LVGLComponent_ClearState_ActionType : public LVGLComponent_ActionType { + int32_t target; + uint32_t state; +}; struct LVGLComponent : public Component { ListOfAssetsPtr actions; };