Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
mvladic committed Oct 1, 2024
1 parent 53a75a3 commit 2041a3c
Show file tree
Hide file tree
Showing 8 changed files with 270 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Binary file modified packages/project-editor/flow/runtime/lvgl_runtime_v8.3.wasm
Binary file not shown.
Binary file modified packages/project-editor/flow/runtime/lvgl_runtime_v9.0.wasm
Binary file not shown.
228 changes: 227 additions & 1 deletion packages/project-editor/lvgl/actions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";

////////////////////////////////////////////////////////////////////////////////

Expand All @@ -73,6 +73,8 @@ const LVGL_ACTIONS = {
REMOVE_STYLE: 4,
ADD_FLAG: 5,
CLEAR_FLAG: 6,
ADD_STATE: 8,
CLEAR_STATE: 9,
GROUP: 7
};

Expand All @@ -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;
},

Expand Down Expand Up @@ -212,6 +218,24 @@ export class LVGLActionType extends EezObject {
),
LVGLClearFlagActionType
);
} else if (result.values.action == "ADD_STATE") {
actionTypeObject = createObject<LVGLAddStateActionType>(
project._store,
Object.assign(
actionTypeProperties,
LVGLAddStateActionType.classInfo.defaultValue
),
LVGLAddStateActionType
);
} else if (result.values.action == "CLEAR_STATE") {
actionTypeObject = createObject<LVGLClearStateActionType>(
project._store,
Object.assign(
actionTypeProperties,
LVGLClearStateActionType.classInfo.defaultValue
),
LVGLClearStateActionType
);
} else if (result.values.action == "GROUP") {
actionTypeObject = createObject<LVGLGroupActionType>(
project._store,
Expand Down Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion packages/project-editor/lvgl/page-runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
});
Expand Down
28 changes: 27 additions & 1 deletion resources/eez-framework-amalgamation/eez-flow.cpp
Original file line number Diff line number Diff line change
@@ -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
*
Expand Down Expand Up @@ -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<LVGLExecutionState>(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<LVGLExecutionState>(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);
Expand Down
14 changes: 12 additions & 2 deletions resources/eez-framework-amalgamation/eez-flow.h
Original file line number Diff line number Diff line change
@@ -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
*
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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<LVGLComponent_ActionType> actions;
};
Expand Down

0 comments on commit 2041a3c

Please sign in to comment.