Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
mvladic committed Sep 29, 2024
1 parent bc8307d commit fcf1060
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 9 deletions.
4 changes: 2 additions & 2 deletions packages/eez-studio-types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -138,17 +138,21 @@ 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);
setObjectIndex(obj, index);
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);
Expand Down
Binary file modified packages/project-editor/flow/runtime/lvgl_runtime_v8.3.wasm
Binary file not shown.
Binary file modified packages/project-editor/flow/runtime/lvgl_runtime_v9.0.wasm
Binary file not shown.
23 changes: 20 additions & 3 deletions packages/project-editor/lvgl/widgets/Image.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -103,6 +112,7 @@ export class LVGLImageWidget extends LVGLWidget {
height: 100,
widthUnit: "content",
heightUnit: "content",
setPivot: false,
pivotX: 0,
pivotY: 0,
zoom: 256,
Expand All @@ -116,6 +126,10 @@ export class LVGLImageWidget extends LVGLWidget {
if (jsObject.innerAlign == undefined) {
jsObject.innerAlign = "CENTER";
}

if (jsObject.setPivot == undefined) {
jsObject.setPivot = true;
}
},

icon: (
Expand Down Expand Up @@ -165,6 +179,7 @@ export class LVGLImageWidget extends LVGLWidget {

makeObservable(this, {
image: observable,
setPivot: observable,
pivotX: observable,
pivotY: observable,
zoom: observable,
Expand All @@ -189,6 +204,7 @@ export class LVGLImageWidget extends LVGLWidget {
rect.height,

0,
this.setPivot,
this.pivotX,
this.pivotY,
this.zoom,
Expand All @@ -204,6 +220,7 @@ export class LVGLImageWidget extends LVGLWidget {
runtime.wasm._lvglSetImageSrc(
obj,
bitmapPtr,
this.setPivot,
this.pivotX,
this.pivotY,
this.zoom,
Expand Down Expand Up @@ -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});`
);
Expand Down

0 comments on commit fcf1060

Please sign in to comment.