diff --git a/packages/eez-studio-types/index.d.ts b/packages/eez-studio-types/index.d.ts index b701e9eb..37d3d516 100644 --- a/packages/eez-studio-types/index.d.ts +++ b/packages/eez-studio-types/index.d.ts @@ -628,8 +628,8 @@ export interface IWasmFlowRuntime { _lvglCreatePanel(parentObj: number, index: number, x: number, y: number, w: number, h: number): number; _lvglCreateUserWidget(parentObj: number, index: number, x: number, y: number, w: number, h: number): number; - _lvglCreateImage(parentObj: number, index: number, x: number, y: number, w: number, h: number, img_src: number, pivotX: number, pivotY: number, zoom: number, angle: number, innerAlign: number): number; - _lvglSetImageSrc(parentObj: number, img_src: number, pivotX: number, pivotY: number, zoom: number, angle: number, innerAlign: number): void; + _lvglCreateImage(parentObj: number, index: number, x: number, y: number, w: number, h: number, img_src: number, setPivot: boolean, pivotX: number, pivotY: number, zoom: number, angle: number, innerAlign: number): number; + _lvglSetImageSrc(parentObj: number, img_src: number, setPivot: boolean, pivotX: number, pivotY: number, zoom: number, angle: number, innerAlign: number): void; _lvglCreateLine(parentObj: number, index: number, x: number, y: number, w: number, h: number): number; _lvglCreateSlider(parentObj: number, index: number, x: number, y: number, w: number, h: number, min: number, max: number, mode: number, value: number, value_left: number): number; diff --git a/packages/project-editor/flow/runtime/cpp/lvgl-runtime/common/src/studio_api.cpp b/packages/project-editor/flow/runtime/cpp/lvgl-runtime/common/src/studio_api.cpp index 5b81ec53..2602f94e 100644 --- a/packages/project-editor/flow/runtime/cpp/lvgl-runtime/common/src/studio_api.cpp +++ b/packages/project-editor/flow/runtime/cpp/lvgl-runtime/common/src/studio_api.cpp @@ -128,7 +128,7 @@ EM_PORT_API(lv_obj_t *) lvglCreateUserWidget(lv_obj_t *parentObj, int32_t index, return obj; } -EM_PORT_API(lv_obj_t *) lvglCreateImage(lv_obj_t *parentObj, int32_t index, lv_coord_t x, lv_coord_t y, lv_coord_t w, lv_coord_t h, const void *img_src, lv_coord_t pivotX, lv_coord_t pivotY, uint16_t zoom, int16_t angle, int inner_align) { +EM_PORT_API(lv_obj_t *) lvglCreateImage(lv_obj_t *parentObj, int32_t index, lv_coord_t x, lv_coord_t y, lv_coord_t w, lv_coord_t h, const void *img_src, bool setPivot, lv_coord_t pivotX, lv_coord_t pivotY, uint16_t zoom, int16_t angle, int inner_align) { lv_obj_t *obj = lv_img_create(parentObj); lv_obj_set_pos(obj, x, y); lv_obj_set_size(obj, w, h); @@ -138,7 +138,9 @@ EM_PORT_API(lv_obj_t *) lvglCreateImage(lv_obj_t *parentObj, int32_t index, lv_c lv_image_set_inner_align(obj, (lv_image_align_t)inner_align); #endif } - lv_img_set_pivot(obj, pivotX, pivotY); + if (setPivot) { + lv_img_set_pivot(obj, pivotX, pivotY); + } lv_img_set_zoom(obj, zoom); lv_img_set_angle(obj, angle); lv_obj_update_layout(obj); @@ -146,9 +148,11 @@ EM_PORT_API(lv_obj_t *) lvglCreateImage(lv_obj_t *parentObj, int32_t index, lv_c return obj; } -EM_PORT_API(void) lvglSetImageSrc(lv_obj_t *obj, const void *img_src, lv_coord_t pivotX, lv_coord_t pivotY, uint16_t zoom, int16_t angle, int inner_align) { +EM_PORT_API(void) lvglSetImageSrc(lv_obj_t *obj, const void *img_src, bool setPivot, lv_coord_t pivotX, lv_coord_t pivotY, uint16_t zoom, int16_t angle, int inner_align) { lv_img_set_src(obj, img_src); - lv_img_set_pivot(obj, pivotX, pivotY); + if (setPivot) { + lv_img_set_pivot(obj, pivotX, pivotY); + } lv_img_set_zoom(obj, zoom); lv_img_set_angle(obj, angle); lv_obj_update_layout(obj); diff --git a/packages/project-editor/flow/runtime/lvgl_runtime_v8.3.wasm b/packages/project-editor/flow/runtime/lvgl_runtime_v8.3.wasm index b7285279..7a47df9a 100644 Binary files a/packages/project-editor/flow/runtime/lvgl_runtime_v8.3.wasm and b/packages/project-editor/flow/runtime/lvgl_runtime_v8.3.wasm differ diff --git a/packages/project-editor/flow/runtime/lvgl_runtime_v9.0.wasm b/packages/project-editor/flow/runtime/lvgl_runtime_v9.0.wasm index 8cd013ba..af979221 100644 Binary files a/packages/project-editor/flow/runtime/lvgl_runtime_v9.0.wasm and b/packages/project-editor/flow/runtime/lvgl_runtime_v9.0.wasm differ diff --git a/packages/project-editor/lvgl/widgets/Image.tsx b/packages/project-editor/lvgl/widgets/Image.tsx index aaa0b8fe..cc97424a 100644 --- a/packages/project-editor/lvgl/widgets/Image.tsx +++ b/packages/project-editor/lvgl/widgets/Image.tsx @@ -24,6 +24,7 @@ import { LV_IMAGE_ALIGN } from "../lvgl-constants"; export class LVGLImageWidget extends LVGLWidget { image: string; + setPivot: boolean; pivotX: number; pivotY: number; zoom: number; @@ -57,17 +58,25 @@ export class LVGLImageWidget extends LVGLWidget { referencedObjectCollectionPath: "bitmaps", propertyGridGroup: specificGroup }, + { + name: "setPivot", + displayName: "Change pivot point (default is center)", + type: PropertyType.Boolean, + propertyGridGroup: specificGroup + }, { name: "pivotX", displayName: "Pivot X", type: PropertyType.Number, - propertyGridGroup: specificGroup + propertyGridGroup: specificGroup, + disabled: (widget: LVGLImageWidget) => !widget.setPivot }, { name: "pivotY", displayName: "Pivot Y", type: PropertyType.Number, - propertyGridGroup: specificGroup + propertyGridGroup: specificGroup, + disabled: (widget: LVGLImageWidget) => !widget.setPivot }, { name: "zoom", @@ -103,6 +112,7 @@ export class LVGLImageWidget extends LVGLWidget { height: 100, widthUnit: "content", heightUnit: "content", + setPivot: false, pivotX: 0, pivotY: 0, zoom: 256, @@ -116,6 +126,10 @@ export class LVGLImageWidget extends LVGLWidget { if (jsObject.innerAlign == undefined) { jsObject.innerAlign = "CENTER"; } + + if (jsObject.setPivot == undefined) { + jsObject.setPivot = true; + } }, icon: ( @@ -165,6 +179,7 @@ export class LVGLImageWidget extends LVGLWidget { makeObservable(this, { image: observable, + setPivot: observable, pivotX: observable, pivotY: observable, zoom: observable, @@ -189,6 +204,7 @@ export class LVGLImageWidget extends LVGLWidget { rect.height, 0, + this.setPivot, this.pivotX, this.pivotY, this.zoom, @@ -204,6 +220,7 @@ export class LVGLImageWidget extends LVGLWidget { runtime.wasm._lvglSetImageSrc( obj, bitmapPtr, + this.setPivot, this.pivotX, this.pivotY, this.zoom, @@ -236,7 +253,7 @@ export class LVGLImageWidget extends LVGLWidget { } } - if (this.pivotX != 0 || this.pivotY != 0) { + if (this.setPivot) { build.line( `lv_img_set_pivot(obj, ${this.pivotX}, ${this.pivotY});` );