Skip to content

Commit 2041a3c

Browse files
committed
1 parent 53a75a3 commit 2041a3c

File tree

8 files changed

+270
-7
lines changed

8 files changed

+270
-7
lines changed

packages/project-editor/flow/runtime/cpp/lvgl-runtime/common/src/flow.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -951,7 +951,7 @@ EM_PORT_API(lv_group_t *) lvglCreateGroup() {
951951
}
952952

953953
EM_PORT_API(void) lvglAddScreenLoadedEventHandler(lv_obj_t *screenObj) {
954-
lv_obj_add_event_cb(screenObj, screen_loaded_event_callback, LV_EVENT_SCREEN_LOADED, 0);
954+
lv_obj_add_event_cb(screenObj, screen_loaded_event_callback, LV_EVENT_SCREEN_LOAD_START, 0);
955955
}
956956

957957
EM_PORT_API(void) lvglGroupAddObject(lv_obj_t *screenObj, lv_group_t *groupObj, lv_obj_t *obj) {
Binary file not shown.
Binary file not shown.

packages/project-editor/lvgl/actions.tsx

+227-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ import {
6161
import { buildExpression } from "project-editor/flow/expression";
6262
import { escapeCString } from "./widget-common";
6363
import { getLvglFlagCodes } from "./lvgl-versions";
64-
import { LVGL_FLAG_CODES } from "./lvgl-constants";
64+
import { LVGL_FLAG_CODES, LVGL_STATE_CODES } from "./lvgl-constants";
6565

6666
////////////////////////////////////////////////////////////////////////////////
6767

@@ -73,6 +73,8 @@ const LVGL_ACTIONS = {
7373
REMOVE_STYLE: 4,
7474
ADD_FLAG: 5,
7575
CLEAR_FLAG: 6,
76+
ADD_STATE: 8,
77+
CLEAR_STATE: 9,
7678
GROUP: 7
7779
};
7880

@@ -97,6 +99,10 @@ export class LVGLActionType extends EezObject {
9799
return LVGLAddFlagActionType;
98100
else if (jsObject.action == "CLEAR_FLAG")
99101
return LVGLClearFlagActionType;
102+
else if (jsObject.action == "ADD_STATE")
103+
return LVGLAddStateActionType;
104+
else if (jsObject.action == "CLEAR_STATE")
105+
return LVGLClearStateActionType;
100106
else return LVGLGroupActionType;
101107
},
102108

@@ -212,6 +218,24 @@ export class LVGLActionType extends EezObject {
212218
),
213219
LVGLClearFlagActionType
214220
);
221+
} else if (result.values.action == "ADD_STATE") {
222+
actionTypeObject = createObject<LVGLAddStateActionType>(
223+
project._store,
224+
Object.assign(
225+
actionTypeProperties,
226+
LVGLAddStateActionType.classInfo.defaultValue
227+
),
228+
LVGLAddStateActionType
229+
);
230+
} else if (result.values.action == "CLEAR_STATE") {
231+
actionTypeObject = createObject<LVGLClearStateActionType>(
232+
project._store,
233+
Object.assign(
234+
actionTypeProperties,
235+
LVGLClearStateActionType.classInfo.defaultValue
236+
),
237+
LVGLClearStateActionType
238+
);
215239
} else if (result.values.action == "GROUP") {
216240
actionTypeObject = createObject<LVGLGroupActionType>(
217241
project._store,
@@ -1557,6 +1581,208 @@ registerClass("LVGLClearFlagActionType", LVGLClearFlagActionType);
15571581

15581582
////////////////////////////////////////////////////////////////////////////////
15591583

1584+
export class LVGLAddStateActionType extends LVGLActionType {
1585+
target: string;
1586+
state: keyof typeof LVGL_STATE_CODES;
1587+
1588+
override makeEditable() {
1589+
super.makeEditable();
1590+
1591+
makeObservable(this, {
1592+
target: observable,
1593+
state: observable
1594+
});
1595+
}
1596+
1597+
static classInfo = makeDerivedClassInfo(LVGLActionType.classInfo, {
1598+
properties: [
1599+
{
1600+
name: "target",
1601+
displayName: "Target",
1602+
type: PropertyType.Enum,
1603+
enumItems: (actionType: LVGLAddStateActionType) => {
1604+
const lvglIdentifiers = ProjectEditor.getProjectStore(
1605+
actionType
1606+
).lvglIdentifiers.getIdentifiersVisibleFromFlow(
1607+
ProjectEditor.getFlow(actionType)
1608+
);
1609+
1610+
return lvglIdentifiers.map(lvglIdentifier => ({
1611+
id: lvglIdentifier.identifier,
1612+
label: lvglIdentifier.identifier
1613+
}));
1614+
}
1615+
},
1616+
{
1617+
name: "state",
1618+
type: PropertyType.Enum,
1619+
enumItems: (actionType: LVGLAddStateActionType) => {
1620+
return Object.keys(LVGL_STATE_CODES).map(state => ({
1621+
id: state,
1622+
label: state
1623+
}));
1624+
}
1625+
}
1626+
],
1627+
defaultValue: {},
1628+
listLabel: (action: LVGLAddStateActionType, collapsed: boolean) => {
1629+
if (!collapsed) {
1630+
return "Add state";
1631+
}
1632+
let singleItem =
1633+
(getParent(action) as LVGLActionType[]).length == 1;
1634+
if (singleItem) {
1635+
return (
1636+
<>
1637+
{action.state} in {action.target}
1638+
</>
1639+
);
1640+
} else {
1641+
return (
1642+
<>
1643+
Add state {action.state} in {action.target}
1644+
</>
1645+
);
1646+
}
1647+
},
1648+
check: (object: LVGLAddStateActionType, messages: IMessage[]) => {
1649+
const projectStore = ProjectEditor.getProjectStore(object);
1650+
1651+
if (object.target) {
1652+
const lvglIdentifier =
1653+
projectStore.lvglIdentifiers.getIdentifierByName(
1654+
ProjectEditor.getFlow(object),
1655+
object.target
1656+
);
1657+
1658+
if (lvglIdentifier == undefined) {
1659+
messages.push(propertyNotFoundMessage(object, "target"));
1660+
}
1661+
} else {
1662+
messages.push(propertyNotSetMessage(object, "target"));
1663+
}
1664+
}
1665+
});
1666+
1667+
override build(assets: Assets, dataBuffer: DataBuffer) {
1668+
// target
1669+
dataBuffer.writeInt32(
1670+
assets.projectStore.lvglIdentifiers.getIdentifierByName(
1671+
ProjectEditor.getFlow(this),
1672+
this.target
1673+
)?.index ?? -1
1674+
);
1675+
1676+
// state
1677+
dataBuffer.writeUint32(LVGL_STATE_CODES[this.state] ?? 0);
1678+
}
1679+
}
1680+
1681+
registerClass("LVGLAddStateActionType", LVGLAddStateActionType);
1682+
1683+
////////////////////////////////////////////////////////////////////////////////
1684+
1685+
export class LVGLClearStateActionType extends LVGLActionType {
1686+
target: string;
1687+
state: keyof typeof LVGL_STATE_CODES;
1688+
1689+
override makeEditable() {
1690+
super.makeEditable();
1691+
1692+
makeObservable(this, {
1693+
target: observable,
1694+
state: observable
1695+
});
1696+
}
1697+
1698+
static classInfo = makeDerivedClassInfo(LVGLActionType.classInfo, {
1699+
properties: [
1700+
{
1701+
name: "target",
1702+
displayName: "Target",
1703+
type: PropertyType.Enum,
1704+
enumItems: (actionType: LVGLClearStateActionType) => {
1705+
const lvglIdentifiers = ProjectEditor.getProjectStore(
1706+
actionType
1707+
).lvglIdentifiers.getIdentifiersVisibleFromFlow(
1708+
ProjectEditor.getFlow(actionType)
1709+
);
1710+
1711+
return lvglIdentifiers.map(lvglIdentifier => ({
1712+
id: lvglIdentifier.identifier,
1713+
label: lvglIdentifier.identifier
1714+
}));
1715+
}
1716+
},
1717+
{
1718+
name: "state",
1719+
type: PropertyType.Enum,
1720+
enumItems: (actionType: LVGLClearStateActionType) => {
1721+
return Object.keys(LVGL_STATE_CODES).map(state => ({
1722+
id: state,
1723+
label: state
1724+
}));
1725+
}
1726+
}
1727+
],
1728+
defaultValue: {},
1729+
listLabel: (action: LVGLClearStateActionType, collapsed: boolean) => {
1730+
if (!collapsed) {
1731+
return "Clear state";
1732+
}
1733+
let singleItem =
1734+
(getParent(action) as LVGLActionType[]).length == 1;
1735+
if (singleItem) {
1736+
return (
1737+
<>
1738+
{action.state} in {action.target}
1739+
</>
1740+
);
1741+
} else {
1742+
return (
1743+
<>
1744+
Clear state {action.state} in {action.target}
1745+
</>
1746+
);
1747+
}
1748+
},
1749+
check: (object: LVGLClearStateActionType, messages: IMessage[]) => {
1750+
const projectStore = ProjectEditor.getProjectStore(object);
1751+
1752+
if (object.target) {
1753+
const lvglIdentifier =
1754+
projectStore.lvglIdentifiers.getIdentifierByName(
1755+
ProjectEditor.getFlow(object),
1756+
object.target
1757+
);
1758+
1759+
if (lvglIdentifier == undefined) {
1760+
messages.push(propertyNotFoundMessage(object, "target"));
1761+
}
1762+
} else {
1763+
messages.push(propertyNotSetMessage(object, "target"));
1764+
}
1765+
}
1766+
});
1767+
1768+
override build(assets: Assets, dataBuffer: DataBuffer) {
1769+
// target
1770+
dataBuffer.writeInt32(
1771+
assets.projectStore.lvglIdentifiers.getIdentifierByName(
1772+
ProjectEditor.getFlow(this),
1773+
this.target
1774+
)?.index ?? -1
1775+
);
1776+
1777+
// state
1778+
dataBuffer.writeUint32(LVGL_STATE_CODES[this.state] ?? 0);
1779+
}
1780+
}
1781+
1782+
registerClass("LVGLClearStateActionType", LVGLClearStateActionType);
1783+
1784+
////////////////////////////////////////////////////////////////////////////////
1785+
15601786
const GROUP_ACTIONS = {
15611787
SET_WRAP: 0,
15621788
FOCUS_OBJ: 1,

packages/project-editor/lvgl/page-runtime.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -762,7 +762,6 @@ export class LVGLPageViewerRuntime extends LVGLPageRuntime {
762762
// add widgets to groups
763763
for (const page of this.pages) {
764764
if (page._lvglObj) {
765-
this.wasm._lvglAddScreenLoadedEventHandler(page._lvglObj);
766765
for (
767766
let i = 0;
768767
i < this.project.lvglGroups.groups.length;
@@ -829,6 +828,8 @@ export class LVGLPageViewerRuntime extends LVGLPageRuntime {
829828

830829
const pageObj = this.page.lvglCreate(this, 0);
831830

831+
this.wasm._lvglAddScreenLoadedEventHandler(pageObj);
832+
832833
runInAction(() => {
833834
this.page._lvglObj = pageObj;
834835
});

resources/eez-framework-amalgamation/eez-flow.cpp

+27-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Autogenerated on September 27, 2024 2:31:05 PM from eez-framework commit ca74f143c589ae87fb5617d7799d5cc418c825b0 */
1+
/* Autogenerated on October 1, 2024 11:29:42 AM from eez-framework commit ca74f143c589ae87fb5617d7799d5cc418c825b0 */
22
/*
33
* eez-framework
44
*
@@ -4066,6 +4066,32 @@ void executeLVGLComponent(FlowState *flowState, unsigned componentIndex) {
40664066
lv_group_set_editing(target, specific->enable ? true : false);
40674067
}
40684068
}
4069+
} else if (general->action == ADD_STATE) {
4070+
auto specific = (LVGLComponent_AddState_ActionType *)general;
4071+
auto target = getLvglObjectFromIndexHook(flowState->lvglWidgetStartIndex + specific->target);
4072+
if (!target) {
4073+
if (!executionState) {
4074+
executionState = allocateComponentExecutionState<LVGLExecutionState>(flowState, componentIndex);
4075+
}
4076+
executionState->actionIndex = actionIndex;
4077+
addToQueue(flowState, componentIndex, -1, -1, -1, true);
4078+
return;
4079+
} else {
4080+
lv_obj_add_state(target, (lv_state_t)specific->state);
4081+
}
4082+
} else if (general->action == CLEAR_STATE) {
4083+
auto specific = (LVGLComponent_ClearState_ActionType *)general;
4084+
auto target = getLvglObjectFromIndexHook(flowState->lvglWidgetStartIndex + specific->target);
4085+
if (!target) {
4086+
if (!executionState) {
4087+
executionState = allocateComponentExecutionState<LVGLExecutionState>(flowState, componentIndex);
4088+
}
4089+
executionState->actionIndex = actionIndex;
4090+
addToQueue(flowState, componentIndex, -1, -1, -1, true);
4091+
return;
4092+
} else {
4093+
lv_obj_clear_state(target, (lv_state_t)specific->state);
4094+
}
40694095
}
40704096
}
40714097
propagateValueThroughSeqout(flowState, componentIndex);

resources/eez-framework-amalgamation/eez-flow.h

+12-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Autogenerated on September 27, 2024 2:31:05 PM from eez-framework commit ca74f143c589ae87fb5617d7799d5cc418c825b0 */
1+
/* Autogenerated on October 1, 2024 11:29:42 AM from eez-framework commit ca74f143c589ae87fb5617d7799d5cc418c825b0 */
22
/*
33
* eez-framework
44
*
@@ -2653,7 +2653,9 @@ enum LVGL_ACTIONS {
26532653
REMOVE_STYLE,
26542654
ADD_FLAG,
26552655
CLEAR_FLAG,
2656-
GROUP
2656+
GROUP,
2657+
ADD_STATE,
2658+
CLEAR_STATE,
26572659
};
26582660
struct LVGLComponent_ActionType {
26592661
uint32_t action;
@@ -2717,6 +2719,14 @@ struct LVGLComponent_Group_ActionType : public LVGLComponent_ActionType {
27172719
int32_t target;
27182720
uint32_t enable;
27192721
};
2722+
struct LVGLComponent_AddState_ActionType : public LVGLComponent_ActionType {
2723+
int32_t target;
2724+
uint32_t state;
2725+
};
2726+
struct LVGLComponent_ClearState_ActionType : public LVGLComponent_ActionType {
2727+
int32_t target;
2728+
uint32_t state;
2729+
};
27202730
struct LVGLComponent : public Component {
27212731
ListOfAssetsPtr<LVGLComponent_ActionType> actions;
27222732
};

0 commit comments

Comments
 (0)