Skip to content

Commit 4638c16

Browse files
committed
1 parent da55e90 commit 4638c16

1 file changed

Lines changed: 56 additions & 49 deletions

File tree

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

Lines changed: 56 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,27 @@ import {
99
PropertyType
1010
} from "project-editor/core/object";
1111

12-
import { ProjectType } from "project-editor/project/project";
12+
import { findLvglStyle, ProjectType } from "project-editor/project/project";
1313

1414
import { LVGLTabviewWidget, LVGLTabWidget, LVGLWidget } from "./internal";
1515
import { getDropdown, getTabview } from "../widget-common";
1616
import { getProjectStore, Message } from "project-editor/store";
17-
import { getLvglParts } from "../lvgl-versions";
17+
import { getLvglParts, getLvglStylePropName } from "../lvgl-versions";
1818
import { Rect } from "eez-studio-shared/geometry";
1919
import { AutoSize } from "project-editor/flow/component";
2020
import { IResizeHandler } from "project-editor/flow/flow-interfaces";
21+
import {
22+
bg_opa_property_info,
23+
border_width_property_info,
24+
LVGLPropertyInfo,
25+
pad_bottom_property_info,
26+
pad_left_property_info,
27+
pad_right_property_info,
28+
pad_top_property_info,
29+
radius_property_info
30+
} from "../style-catalog";
2131
import type { LVGLCode } from "project-editor/lvgl/to-lvgl-code";
32+
import { ProjectEditor } from "project-editor/project-editor-interface";
2233

2334
////////////////////////////////////////////////////////////////////////////////
2435

@@ -56,58 +67,13 @@ export class LVGLContainerWidget extends LVGLWidget {
5667
}
5768
],
5869

70+
5971
defaultValue: {
6072
left: 0,
6173
top: 0,
6274
width: 300,
6375
height: 200,
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-
}
76+
clickableFlag: true
11177
},
11278

11379
check: (widget: LVGLTabviewWidget, messages: IMessage[]) => {
@@ -186,6 +152,8 @@ export class LVGLContainerWidget extends LVGLWidget {
186152
}
187153
});
188154

155+
containerVersion: number;
156+
189157
override makeEditable() {
190158
super.makeEditable();
191159

@@ -257,6 +225,35 @@ export class LVGLContainerWidget extends LVGLWidget {
257225
return super.getResizeHandlers();
258226
}
259227

228+
isStyleOverriden(propertyInfo: LVGLPropertyInfo) {
229+
if (this.localStyles.getPropertyValue(propertyInfo, "MAIN", "DEFAULT") != undefined) {
230+
return true;
231+
}
232+
233+
if (this.useStyle) {
234+
const lvglStyle = findLvglStyle(ProjectEditor.getProject(this), this.useStyle);
235+
if (lvglStyle) {
236+
if (lvglStyle.fullDefinition?.["MAIN"]?.["DEFAULT"]?.[propertyInfo.name] != undefined) {
237+
return true;
238+
}
239+
}
240+
}
241+
242+
return false;
243+
}
244+
245+
buildStyleIfNotOverriden(code: LVGLCode, propertyInfo: LVGLPropertyInfo) {
246+
if (!this.isStyleOverriden(propertyInfo)) {
247+
const stylePropName = getLvglStylePropName(code.project, propertyInfo.name);
248+
249+
code.callObjectFunction(
250+
`lv_obj_set_style_${stylePropName}`,
251+
0,
252+
code.or(code.constant("LV_PART_MAIN"), code.constant("LV_STATE_DEFAULT"))
253+
);
254+
}
255+
}
256+
260257
override toLVGLCode(code: LVGLCode) {
261258
const tabview = getTabview(this);
262259
if (tabview) {
@@ -282,5 +279,15 @@ export class LVGLContainerWidget extends LVGLWidget {
282279
}
283280

284281
code.createObject(`lv_obj_create`);
282+
283+
if (this.containerVersion !== 1) {
284+
this.buildStyleIfNotOverriden(code, pad_left_property_info);
285+
this.buildStyleIfNotOverriden(code, pad_top_property_info);
286+
this.buildStyleIfNotOverriden(code, pad_right_property_info);
287+
this.buildStyleIfNotOverriden(code, pad_bottom_property_info);
288+
this.buildStyleIfNotOverriden(code, bg_opa_property_info);
289+
this.buildStyleIfNotOverriden(code, border_width_property_info);
290+
this.buildStyleIfNotOverriden(code, radius_property_info);
291+
}
285292
}
286293
}

0 commit comments

Comments
 (0)