Skip to content

Commit ac44cd3

Browse files
committed
1 parent ca7e7e6 commit ac44cd3

2 files changed

Lines changed: 58 additions & 34 deletions

File tree

packages/project-editor/lvgl/widgets/Base.tsx

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,7 @@ import { validators } from "eez-studio-shared/validation";
7979
import {
8080
getLvglCoord,
8181
getLvglEvents,
82-
getLvglFlagCodes,
83-
getLvglStylePropName
82+
getLvglFlagCodes
8483
} from "project-editor/lvgl/lvgl-versions";
8584
import {
8685
LVGL_FLAG_CODES,
@@ -1625,18 +1624,6 @@ export class LVGLWidget extends Widget {
16251624
}
16261625
}
16271626

1628-
buildStyleIfNotDefinedInCode(code: LVGLCode, propertyInfo: LVGLPropertyInfo) {
1629-
if (this.localStyles.getPropertyValue(propertyInfo, "MAIN", "DEFAULT") == undefined) {
1630-
const stylePropName = getLvglStylePropName(code.project, propertyInfo.name);
1631-
1632-
code.callObjectFunction(
1633-
`lv_obj_set_style_${stylePropName}`,
1634-
0,
1635-
code.or(code.constant("LV_PART_MAIN"), code.constant("LV_STATE_DEFAULT"))
1636-
);
1637-
}
1638-
}
1639-
16401627
////////////////////////////////////////////////////////////////////////////////
16411628
////////////////////////////////////////////////////////////////////////////////
16421629
////////////////////////////////////////////////////////////////////////////////

packages/project-editor/lvgl/widgets/Container.tsx

Lines changed: 57 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import {
55
IMessage,
66
MessageType,
77
makeDerivedClassInfo,
8-
LVGLParts
8+
LVGLParts,
9+
PropertyType
910
} from "project-editor/core/object";
1011

1112
import { ProjectType } from "project-editor/project/project";
@@ -17,15 +18,6 @@ import { getLvglParts } from "../lvgl-versions";
1718
import { Rect } from "eez-studio-shared/geometry";
1819
import { AutoSize } from "project-editor/flow/component";
1920
import { 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";
2921
import 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

Comments
 (0)