55 IMessage ,
66 MessageType ,
77 makeDerivedClassInfo ,
8- LVGLParts
8+ LVGLParts ,
9+ PropertyType
910} from "project-editor/core/object" ;
1011
1112import { ProjectType } from "project-editor/project/project" ;
@@ -17,15 +18,6 @@ import { getLvglParts } from "../lvgl-versions";
1718import { Rect } from "eez-studio-shared/geometry" ;
1819import { AutoSize } from "project-editor/flow/component" ;
1920import { IResizeHandler } from "project-editor/flow/flow-interfaces" ;
20- import {
21- bg_opa_property_info ,
22- border_width_property_info ,
23- pad_bottom_property_info ,
24- pad_left_property_info ,
25- pad_right_property_info ,
26- pad_top_property_info ,
27- radius_property_info
28- } from "../style-catalog" ;
2921import type { LVGLCode } from "project-editor/lvgl/to-lvgl-code" ;
3022
3123////////////////////////////////////////////////////////////////////////////////
@@ -55,14 +47,67 @@ export class LVGLContainerWidget extends LVGLWidget {
5547
5648 componentPaletteGroupName : "!1Basic" ,
5749
58- properties : [ ] ,
50+ properties : [
51+ {
52+ name : "containerVersion" ,
53+ type : PropertyType . Number ,
54+ hideInPropertyGrid : true ,
55+ hideInDocumentation : "all"
56+ }
57+ ] ,
5958
6059 defaultValue : {
6160 left : 0 ,
6261 top : 0 ,
6362 width : 300 ,
6463 height : 200 ,
65- clickableFlag : true
64+ clickableFlag : true ,
65+ localStyles : {
66+ definition : {
67+ MAIN : {
68+ DEFAULT : {
69+ pad_left : 0 ,
70+ pad_top : 0 ,
71+ pad_right : 0 ,
72+ pad_bottom : 0 ,
73+ bg_opa : 0 ,
74+ border_width : 0 ,
75+ radius : 0
76+ }
77+ }
78+ }
79+ } ,
80+ containerVersion : 1
81+ } ,
82+
83+ beforeLoadHook : ( object , jsObject ) => {
84+ if ( jsObject . containerVersion == undefined ) {
85+ const definition = LVGLContainerWidget . classInfo . defaultValue . localStyles . definition ;
86+
87+ Object . keys ( definition ) . forEach ( part => {
88+ Object . keys ( definition [ part ] ) . forEach ( state => {
89+ Object . keys ( definition [ part ] [ state ] ) . forEach ( propertyName => {
90+ if ( jsObject . localStyles ?. definition ?. [ part ] ?. [ state ] ?. [ propertyName ] == undefined ) {
91+ if ( ! jsObject . localStyles ) {
92+ jsObject . localStyles = { } ;
93+ }
94+ if ( ! jsObject . localStyles . definition ) {
95+ jsObject . localStyles . definition = { } ;
96+ }
97+ if ( ! jsObject . localStyles . definition [ part ] ) {
98+ jsObject . localStyles . definition [ part ] = { } ;
99+ }
100+ if ( ! jsObject . localStyles . definition [ part ] [ state ] ) {
101+ jsObject . localStyles . definition [ part ] [ state ] = { } ;
102+ }
103+ jsObject . localStyles . definition [ part ] [ state ] [ propertyName ] = definition [ part ] [ state ] [ propertyName ] ;
104+ }
105+ } ) ;
106+ } ) ;
107+ } ) ;
108+
109+ jsObject . containerVersion = 1 ;
110+ }
66111 } ,
67112
68113 check : ( widget : LVGLTabviewWidget , messages : IMessage [ ] ) => {
@@ -237,13 +282,5 @@ export class LVGLContainerWidget extends LVGLWidget {
237282 }
238283
239284 code . createObject ( `lv_obj_create` ) ;
240-
241- this . buildStyleIfNotDefinedInCode ( code , pad_left_property_info ) ;
242- this . buildStyleIfNotDefinedInCode ( code , pad_top_property_info ) ;
243- this . buildStyleIfNotDefinedInCode ( code , pad_right_property_info ) ;
244- this . buildStyleIfNotDefinedInCode ( code , pad_bottom_property_info ) ;
245- this . buildStyleIfNotDefinedInCode ( code , bg_opa_property_info ) ;
246- this . buildStyleIfNotDefinedInCode ( code , border_width_property_info ) ;
247- this . buildStyleIfNotDefinedInCode ( code , radius_property_info ) ;
248285 }
249286}
0 commit comments