1
- import React from "react" ;
2
- import { observer } from "mobx-react" ;
3
-
4
1
import {
5
2
getParent ,
6
3
getProperty ,
7
4
IEezObject ,
8
5
IMessage ,
9
- MessageType ,
10
- PropertyProps
6
+ MessageType
11
7
} from "project-editor/core/object" ;
12
8
import { ProjectEditor } from "project-editor/project-editor-interface" ;
13
9
import {
@@ -22,295 +18,11 @@ import {
22
18
LVGLTabWidget ,
23
19
type LVGLWidget
24
20
} from "project-editor/lvgl/widgets" ;
25
- import { ProjectContext } from "project-editor/project/context" ;
26
- import { humanize } from "eez-studio-shared/string" ;
27
- import { Checkbox } from "project-editor/ui-components/PropertyGrid/Checkbox" ;
28
21
import {
29
22
LVGLPageEditorRuntime ,
30
23
type LVGLPageRuntime
31
24
} from "project-editor/lvgl/page-runtime" ;
32
25
import { evalConstantExpression } from "project-editor/flow/expression" ;
33
- import {
34
- LVGL_FLAG_CODES ,
35
- LVGL_REACTIVE_FLAGS ,
36
- LVGL_REACTIVE_STATES ,
37
- LVGL_STATE_CODES
38
- } from "project-editor/lvgl/lvgl-constants" ;
39
- import { getLvglFlagCodes } from "./lvgl-versions" ;
40
-
41
- ////////////////////////////////////////////////////////////////////////////////
42
-
43
- export const LVGLWidgetFlagsProperty = observer (
44
- class LVGLWidgetFlagsProperty extends React . Component < PropertyProps > {
45
- static contextType = ProjectContext ;
46
- declare context : React . ContextType < typeof ProjectContext > ;
47
-
48
- render ( ) {
49
- const flagNames : ( keyof typeof LVGL_FLAG_CODES ) [ ] = [ ] ;
50
-
51
- this . props . objects . map ( ( widget : LVGLWidget ) => {
52
- const flags = Object . keys (
53
- getLvglFlagCodes ( widget )
54
- ) as ( keyof typeof LVGL_FLAG_CODES ) [ ] ;
55
- for ( const flagName of flags ) {
56
- if (
57
- flagNames . indexOf ( flagName ) == - 1 &&
58
- LVGL_REACTIVE_FLAGS . indexOf ( flagName ) == - 1
59
- ) {
60
- flagNames . push ( flagName ) ;
61
- }
62
- }
63
- } ) ;
64
-
65
- return (
66
- < div >
67
- { flagNames . map ( flagName => {
68
- let values = this . props . objects . map (
69
- ( widget : LVGLWidget ) =>
70
- ( widget . widgetFlags || "" )
71
- . split ( "|" )
72
- . indexOf ( flagName ) != - 1
73
- ) ;
74
-
75
- let numEnabled = 0 ;
76
- let numDisabled = 0 ;
77
- values . forEach ( value => {
78
- if ( value ) {
79
- numEnabled ++ ;
80
- } else {
81
- numDisabled ++ ;
82
- }
83
- } ) ;
84
-
85
- let state =
86
- numEnabled == 0
87
- ? false
88
- : numDisabled == 0
89
- ? true
90
- : undefined ;
91
-
92
- return (
93
- < Checkbox
94
- key = { flagName }
95
- state = { state }
96
- label = { humanize ( flagName ) }
97
- onChange = { ( value : boolean ) => {
98
- this . context . undoManager . setCombineCommands (
99
- true
100
- ) ;
101
-
102
- if ( value ) {
103
- this . props . objects . forEach (
104
- ( widget : LVGLWidget ) => {
105
- const flags = Object . keys (
106
- getLvglFlagCodes ( widget )
107
- ) as ( keyof typeof LVGL_FLAG_CODES ) [ ] ;
108
-
109
- if (
110
- flags . indexOf ( flagName ) ==
111
- - 1
112
- ) {
113
- return ;
114
- }
115
-
116
- const flagsArr =
117
- widget . widgetFlags . trim ( ) !=
118
- ""
119
- ? widget . widgetFlags . split (
120
- "|"
121
- )
122
- : [ ] ;
123
- if (
124
- flagsArr . indexOf (
125
- flagName
126
- ) == - 1
127
- ) {
128
- flagsArr . push ( flagName ) ;
129
- this . context . updateObject (
130
- widget ,
131
- {
132
- widgetFlags :
133
- flagsArr . join (
134
- "|"
135
- )
136
- }
137
- ) ;
138
- }
139
- }
140
- ) ;
141
- } else {
142
- this . props . objects . forEach (
143
- ( widget : LVGLWidget ) => {
144
- const flags = Object . keys (
145
- getLvglFlagCodes ( widget )
146
- ) as ( keyof typeof LVGL_FLAG_CODES ) [ ] ;
147
-
148
- if (
149
- flags . indexOf ( flagName ) ==
150
- - 1
151
- ) {
152
- return ;
153
- }
154
-
155
- const flagsArr = (
156
- widget . widgetFlags || ""
157
- ) . split ( "|" ) ;
158
- const i =
159
- flagsArr . indexOf ( flagName ) ;
160
- if ( i != - 1 ) {
161
- flagsArr . splice ( i , 1 ) ;
162
- this . context . updateObject (
163
- widget ,
164
- {
165
- widgetFlags :
166
- flagsArr . join (
167
- "|"
168
- )
169
- }
170
- ) ;
171
- }
172
- }
173
- ) ;
174
- }
175
-
176
- this . context . undoManager . setCombineCommands (
177
- false
178
- ) ;
179
- } }
180
- readOnly = { this . props . readOnly }
181
- />
182
- ) ;
183
- } ) }
184
- </ div >
185
- ) ;
186
- }
187
- }
188
- ) ;
189
-
190
- ////////////////////////////////////////////////////////////////////////////////
191
-
192
- export const LVGLWidgetStatesProperty = observer (
193
- class LVGLWidgetStatesProperty extends React . Component < PropertyProps > {
194
- static contextType = ProjectContext ;
195
- declare context : React . ContextType < typeof ProjectContext > ;
196
-
197
- render ( ) {
198
- const stateNames : ( keyof typeof LVGL_STATE_CODES ) [ ] = [ ] ;
199
-
200
- this . props . objects . map ( ( widget : LVGLWidget ) => {
201
- for ( const stateName of Object . keys (
202
- LVGL_STATE_CODES
203
- ) as ( keyof typeof LVGL_STATE_CODES ) [ ] ) {
204
- if (
205
- stateNames . indexOf ( stateName ) == - 1 &&
206
- LVGL_REACTIVE_STATES . indexOf ( stateName ) == - 1
207
- ) {
208
- stateNames . push ( stateName ) ;
209
- }
210
- }
211
- } ) ;
212
-
213
- return (
214
- < div >
215
- { stateNames . map ( stateName => {
216
- let values = this . props . objects . map (
217
- ( widget : LVGLWidget ) =>
218
- ( widget . states || "" )
219
- . split ( "|" )
220
- . indexOf ( stateName ) != - 1
221
- ) ;
222
-
223
- let numEnabled = 0 ;
224
- let numDisabled = 0 ;
225
- values . forEach ( value => {
226
- if ( value ) {
227
- numEnabled ++ ;
228
- } else {
229
- numDisabled ++ ;
230
- }
231
- } ) ;
232
-
233
- let state =
234
- numEnabled == 0
235
- ? false
236
- : numDisabled == 0
237
- ? true
238
- : undefined ;
239
-
240
- return (
241
- < Checkbox
242
- key = { stateName }
243
- state = { state }
244
- label = { humanize ( stateName ) }
245
- onChange = { ( value : boolean ) => {
246
- this . context . undoManager . setCombineCommands (
247
- true
248
- ) ;
249
-
250
- if ( value ) {
251
- this . props . objects . forEach (
252
- ( widget : LVGLWidget ) => {
253
- const statesArr =
254
- widget . states . trim ( ) != ""
255
- ? widget . states . split (
256
- "|"
257
- )
258
- : [ ] ;
259
- if (
260
- statesArr . indexOf (
261
- stateName
262
- ) == - 1
263
- ) {
264
- statesArr . push ( stateName ) ;
265
- this . context . updateObject (
266
- widget ,
267
- {
268
- states : statesArr . join (
269
- "|"
270
- )
271
- }
272
- ) ;
273
- }
274
- }
275
- ) ;
276
- } else {
277
- this . props . objects . forEach (
278
- ( widget : LVGLWidget ) => {
279
- const statesArr = (
280
- widget . states || ""
281
- ) . split ( "|" ) ;
282
- const i =
283
- statesArr . indexOf (
284
- stateName
285
- ) ;
286
- if ( i != - 1 ) {
287
- statesArr . splice ( i , 1 ) ;
288
- this . context . updateObject (
289
- widget ,
290
- {
291
- states : statesArr . join (
292
- "|"
293
- )
294
- }
295
- ) ;
296
- }
297
- }
298
- ) ;
299
- }
300
-
301
- this . context . undoManager . setCombineCommands (
302
- false
303
- ) ;
304
- } }
305
- readOnly = { this . props . readOnly }
306
- />
307
- ) ;
308
- } ) }
309
- </ div >
310
- ) ;
311
- }
312
- }
313
- ) ;
314
26
315
27
export function getCode < T extends string > (
316
28
arr : T [ ] ,
0 commit comments