From fcf10602eb769240acac7790f70b71947b8e597b Mon Sep 17 00:00:00 2001 From: Martin Vladic Date: Sun, 29 Sep 2024 15:03:18 +0200 Subject: [PATCH] #543 --- packages/eez-studio-types/index.d.ts | 4 +-- .../lvgl-runtime/common/src/studio_api.cpp | 12 ++++++--- .../flow/runtime/lvgl_runtime_v8.3.wasm | Bin 1894006 -> 1894080 bytes .../flow/runtime/lvgl_runtime_v9.0.wasm | Bin 1856357 -> 1856433 bytes .../project-editor/lvgl/widgets/Image.tsx | 23 +++++++++++++++--- 5 files changed, 30 insertions(+), 9 deletions(-) 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 b7285279e61b0e750710f84b47298ce5f3ab6113..7a47df9a9b01d1e881700f2a02892a5715b667ea 100644 GIT binary patch delta 854 zcmXYvOHUI~6vyY@zJ_^pZabB}rsbRhW)dg`3I#d^I#3>o??fZ6&=^BxS82C&;ew4Z z5*M@Z6Sy!j>4GgE0MxA?!G&8BjYQ9FImvJSGw1&AojL!^uZyGe%cFO1EVXxC%2RgC zdZ!3SFOTFX?)zJ=APF91TUN?EaMgoyAha>g#4Clu4x$cNXtf?`gT*eMQmo z4;W)+oZEd@tYz56>jU@Xz-4C#F8>hz8dqgg4Sw%&pQ(ZOgv1H1n%wQlK2FPJ2g@)GWpQEY zV3n0T&iD)~Fawn~&hjSAZkfv97@PyE!ZJ87WfZHvzy+9xg$^#lA}n;VMx7<7!cqs9 zVHuXXxB_!fgB9^ro-N;4mwQv__56STLf8Ng8f{#KI;@Is*3hyhElFIb!%c7=a|e*lff8LGH8MUCglTKSxIA@;;|qORvQJyBV;@S zcLL~_NKy18$>6xf%P-{IgSDJ&3d|42b|4Q<8w-$wf*gC`C`v~h$7pPTF@O#t&|Mcx zP=t~kdte)faT?nPoS-kAIK)YqJlU^sB1D9V2oWV>gi4GM8le*gVG?n|A_S2jl7vm9 Wh#SNxktQ-kmdFwLv;B&bKKlM+iFf{I%c{{a_nO-PJ*U&~E?@8sS&@8rHYZSVg%+kgMoX3tr3JK4Od z*zw25%sT$}h^L#ahwOpIoYp7(w>BayFV5q!c){`ttYXl0mdUD-rnd!LZ=5oEaW^UK+7{%gNEM^Sc zWsIdW+-dn@*<~+Z?f6GKK0Dd*`7cd>qqDhaewA--gsg}Rk|A?RQX$Ke7$I{=%sLmy z_a*`%fn84J5tf7XfLphBxOk!G` z+uej2bu};Rjmt|-&Z3UlJvoON%!%(;j_rA6apVGJg;+p%AQ!QS@K7#c9!uiem2Vl# z;%};(x}wCFt60IRc*nZKMx!d%=y$B`%5|&{$I!6N*PIoj^P7Av+FapgHsy0ynlNC} z8$q2HO>FS6O53VN_8}Fptju?|?MEK{d(uT8T(xb-QBV#Mz4+PV00orPdYuo07^L+Y zkY%J$-jx8N@;$zFbP;euBXlB8B#0g&Nu&saFbRuD6B)uL1kp=mi5%e&eMFw+ 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 8cd013ba3fb483de7265e123953522e6b39e71d7..af979221f6e9a423df9732f11e28f16a8eb32ee1 100644 GIT binary patch delta 1181 zcmXX@O^91n6u$SqpS;|cmv@uAm*1DMmM%vMx{wIbl~uYC3xW%G7B?N&ZUr6B&CDg=`wr)PIhXr=&yR=Sd^!C1 zuw=vsF+bR|;sZKtFBPAiqlZh`O^b~FWF5C0sqkpgR%=ikwXYeR_YF^{vxMDpt zW+Ja{3X_>-uU_UY&+pYMp6_|Rign4W2;27bX^sDIZgDF#nH?q@@(B-^B`Sz@Q%_$Nu|q!Lk_VEY)mUxg29w zim{qfs-a|6N?EYDVYm*n*mYH_sr5!auU_7`v365dtFJI7YqvP(nXHHeGa0ijrsRy0 zDT@`T&n$hYpz>7~%)S=9ZfC>dioHsmO}cg_?I({^*AHg5w}Ut4gmB&2APB~Ps^gOQ z`uF$lcPIC|eE6UFm%$fD-(3}#;}k0JLG7?Mk<%9uQMxb6L~@rGiQHWt5M}y;lwENN zbC6S?`k1F?zArMmnZbglbtGk1EMo`-2q0A7r_ZLerz_^Mq^XN#C_)L!>gO~#)aYPk zz><4!N2C209A}q083e8DATglR28(xk9GIOW)ZHgtw~0a|cDJ@8%d7g&4L{6L2B zbitg~M%dF-#)~iqJ-Dbo*FwF29{eR<#D&4>sey~I0E2=y z3asA2HCThyySNU^u&zEkmuGXNwPApH(XkTjFPbO;i-4nd$xrMtsQM21d4f~h^1VC{1H2iUvZAxiay z2~xi}6KgJ`2O03Rb#j4~FgxJrLl*oYD)Azympr;k%X69(g-N7S%t0OsQ=g{e0OS&v z7*2gELI}knr5Hd-`!rRQwZfqY6;`1F)jQX)1~sVO#R$p}X``mPI@GmM)4HL_#HJ1s zpb0Rfq#Km<1E2h8(R*6Au?_7G8~xZ8*AHb+5DbDzun0CGMQ{jdf}F^nd-5$WO#Xi6 z{$}&S=*e^U5icC>pSY9#lgtlaQN5UWge<`)C_;{qC+Jx~2nj_(iBKj~2-V4AQrmp| EKUd+?D*ylh delta 1059 zcmXYt&x_ku5Xav<{je-q(z7Mm^6z8j{W|F*7!5$Mbe(t-T~g7iO|K9Rod zG@+J$=6nh`{mr=wP)}>_80ype?k@n1^qRj$@5FCfO|7ZX(@c;3FOtwO7y!#O8b&_P zn2}+uDuk#DyJFjRXn>|U7BkotQLT#YdZ8fRA6(tKW>+d7FlJY;13=E>$eGTVX)s~8 zg`F{2NOfkYpoG#7S=9L`+B3bNxM6NmWru#-&id&i(evWsr0q$VRJu`FVU5f;U-^KK|hBPL@k$uh>WGHIUWmBp!s zl2A6WflcwXzbK*-ee%hG2gw89Srl7JggmDtC)?Pw_)3qtjDOu3#5e z#*=MIN>@^Z+xlU<;#qOl7(5_8Bc%&N86N@D4tjgIm; zFVcuI?vZY*4cWj(i%ot$%dZ^n^*Ess zI$;ndks&N1OW3o$o^$d9!r7%)&YvcP6LI1^g7EO^i8Fh8l6&?e<+oFp@Ccs}M4l)R W0ipU4Q6x%4Oq7Yr>~>n+dHz2zs>jy= 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});` );