Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
mvladic committed Mar 11, 2025
1 parent 99c3c72 commit f1ac6a8
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 13 deletions.
33 changes: 30 additions & 3 deletions packages/project-editor/lvgl/to-lvgl-code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,10 @@ export interface LVGLCode {
lvglAddObjectFlowCallback(propertyName: string, filter: number): void;

//
postExecute(callback: () => void): void;
postWidgetExecute(callback: () => void): void;

//
postPageExecute(callback: () => void): void;
}

////////////////////////////////////////////////////////////////////////////////
Expand All @@ -180,6 +183,8 @@ export class SimulatorLVGLCode implements LVGLCode {

allocated: number[] = [];

postWidgetExecuteCallbacks: (() => void)[] = [];

startWidget(
widget: LVGLWidget,
parentObj: number,
Expand All @@ -191,6 +196,11 @@ export class SimulatorLVGLCode implements LVGLCode {
}

endWidget() {
for (const callback of this.postWidgetExecuteCallbacks) {
callback();
}
this.postWidgetExecuteCallbacks = [];

this.callObjectFunction("lv_obj_update_layout");

for (const tempStr of this.allocated) {
Expand Down Expand Up @@ -683,7 +693,7 @@ export class SimulatorLVGLCode implements LVGLCode {
}
}

postExecute(callback: () => void) {
postPageExecute(callback: () => void) {
const widget = this.widget;
const obj = this.obj;
this.pageRuntime.addPostCreateCallback(() => {
Expand All @@ -692,6 +702,10 @@ export class SimulatorLVGLCode implements LVGLCode {
callback();
});
}

postWidgetExecute(callback: () => void) {
this.postWidgetExecuteCallbacks.push(callback);
}
}

export class BuildLVGLCode implements LVGLCode {
Expand All @@ -703,10 +717,19 @@ export class BuildLVGLCode implements LVGLCode {
componentIndex: number;
propertyIndex: number;

noGoodNameCallbacks: (() => void)[] = [];

startWidget(widget: LVGLWidget) {
this.widget = widget;
}

endWidget() {
for (const callback of this.noGoodNameCallbacks) {
callback();
}
this.noGoodNameCallbacks = [];
}

get project() {
return this.build.project;
}
Expand Down Expand Up @@ -1211,7 +1234,11 @@ export class BuildLVGLCode implements LVGLCode {
// this function is only used for the simulator
}

postExecute(callback: () => void) {
postPageExecute(callback: () => void) {
this.build.postBuildAdd(callback);
}

postWidgetExecute(callback: () => void) {
this.noGoodNameCallbacks.push(callback);
}
}
5 changes: 4 additions & 1 deletion packages/project-editor/lvgl/widgets/Base.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1852,6 +1852,8 @@ export class LVGLWidget extends Widget {
this._yScroll2 = runtime.wasm._lvglGetScrollY(obj);
}

runtime.toLVGLCode.endWidget();

return obj;
}

Expand All @@ -1867,7 +1869,6 @@ export class LVGLWidget extends Widget {
const code = runtime.toLVGLCode;
code.startWidget(this, parentObj, customWidget);
this.toLVGLCode(code);
code.endWidget();
return code.obj;
}

Expand Down Expand Up @@ -2211,6 +2212,8 @@ export class LVGLWidget extends Widget {
}
this.localStyles.lvglBuild(build);

build.toLVGLCode.endWidget();

// children
if (this.children.length > 0) {
build.blockStart("{");
Expand Down
2 changes: 1 addition & 1 deletion packages/project-editor/lvgl/widgets/Keyboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ export class LVGLKeyboardWidget extends LVGLWidget {
return;
}

code.postExecute(() => {
code.postPageExecute(() => {
let keyboardAccessor;
let textareaAccessor;

Expand Down
10 changes: 6 additions & 4 deletions packages/project-editor/lvgl/widgets/Label.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,12 @@ export class LVGLLabelWidget extends LVGLWidget {
}

// text
code.callObjectFunction(
"lv_label_set_text",
code.stringProperty(this.textType, this.text, this.previewValue)
);
code.postWidgetExecute(() => {
code.callObjectFunction(
"lv_label_set_text",
code.stringProperty(this.textType, this.text, this.previewValue)
);
});
if (this.textType == "expression") {
code.addToTick("text", () => {
const new_val = code.evalTextProperty(
Expand Down
4 changes: 4 additions & 0 deletions packages/project-editor/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1512,6 +1512,10 @@ export class ProjectStore {
};

async findProjectComponent() {
if (this.runtime && !this.runtime.isDebuggerActive) {
return;
}

const result = await showGenericDialog({
dialogDefinition: {
title: "Find Project Component",
Expand Down
23 changes: 20 additions & 3 deletions packages/project-editor/ui-components/PropertyGrid/Property.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,21 +130,38 @@ export const Property = observer(
}
}

_lastValue: any;

updateChangeDocumentObserver() {
if (this.changeDocumentDisposer) {
this.changeDocumentDisposer();
}

this.changeDocumentDisposer = autorun(() => {
const lastValue = this._lastValue;
this._lastValue = this._value;
if (this._value != lastValue) {
return;
}

if (this.context.project) {
const getPropertyValueResult = getPropertyValue(
this.props.objects,
this.props.propertyInfo
);

const value = getPropertyValueResult
? getPropertyValueResult.value
: undefined;

if (typeof value == "number") {
if (value == filterNumber(this._value)) {
return;
}
}

runInAction(() => {
this._value = getPropertyValueResult
? getPropertyValueResult.value
: undefined;
this._value = value;
});
}
});
Expand Down

0 comments on commit f1ac6a8

Please sign in to comment.