@@ -61,7 +61,7 @@ import {
61
61
import { buildExpression } from "project-editor/flow/expression" ;
62
62
import { escapeCString } from "./widget-common" ;
63
63
import { getLvglFlagCodes } from "./lvgl-versions" ;
64
- import { LVGL_FLAG_CODES } from "./lvgl-constants" ;
64
+ import { LVGL_FLAG_CODES , LVGL_STATE_CODES } from "./lvgl-constants" ;
65
65
66
66
////////////////////////////////////////////////////////////////////////////////
67
67
@@ -73,6 +73,8 @@ const LVGL_ACTIONS = {
73
73
REMOVE_STYLE : 4 ,
74
74
ADD_FLAG : 5 ,
75
75
CLEAR_FLAG : 6 ,
76
+ ADD_STATE : 8 ,
77
+ CLEAR_STATE : 9 ,
76
78
GROUP : 7
77
79
} ;
78
80
@@ -97,6 +99,10 @@ export class LVGLActionType extends EezObject {
97
99
return LVGLAddFlagActionType ;
98
100
else if ( jsObject . action == "CLEAR_FLAG" )
99
101
return LVGLClearFlagActionType ;
102
+ else if ( jsObject . action == "ADD_STATE" )
103
+ return LVGLAddStateActionType ;
104
+ else if ( jsObject . action == "CLEAR_STATE" )
105
+ return LVGLClearStateActionType ;
100
106
else return LVGLGroupActionType ;
101
107
} ,
102
108
@@ -212,6 +218,24 @@ export class LVGLActionType extends EezObject {
212
218
) ,
213
219
LVGLClearFlagActionType
214
220
) ;
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
+ ) ;
215
239
} else if ( result . values . action == "GROUP" ) {
216
240
actionTypeObject = createObject < LVGLGroupActionType > (
217
241
project . _store ,
@@ -1557,6 +1581,208 @@ registerClass("LVGLClearFlagActionType", LVGLClearFlagActionType);
1557
1581
1558
1582
////////////////////////////////////////////////////////////////////////////////
1559
1583
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
+
1560
1786
const GROUP_ACTIONS = {
1561
1787
SET_WRAP : 0 ,
1562
1788
FOCUS_OBJ : 1 ,
0 commit comments