Skip to content

Commit c17c919

Browse files
committed
1 parent 66754f6 commit c17c919

File tree

6 files changed

+113
-2
lines changed

6 files changed

+113
-2
lines changed

packages/eez-studio-types/index.d.ts

+4
Original file line numberDiff line numberDiff line change
@@ -756,8 +756,12 @@ export interface IWasmFlowRuntime {
756756
_lvglSetTimelinePosition(timelinePosition: number): void;
757757
_lvglClearTimeline(): void;
758758
_lvglGetFlowState(flowState: number, userWidgetComponentIndexOrPageIndex: number): number;
759+
759760
_lvglSetScrollBarMode(obj: number, mode: number);
760761
_lvglSetScrollDir(obj: number, dir: number);
762+
_lvglSetScrollSnapX(obj: number, align: number);
763+
_lvglSetScrollSnapY(obj: number, align: number);
764+
761765
_lvglTabviewSetActive(obj: number, tab_id: number, anim_en: number);
762766
_lvglTabviewGetTabBar(obj: number, index: number);
763767
_lvglTabviewGetTabContent(obj: number, index: number);

packages/project-editor/flow/runtime/cpp/lvgl-runtime/common/src/studio_api.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -1120,6 +1120,14 @@ EM_PORT_API(void) lvglSetScrollDir(lv_obj_t *obj, lv_dir_t dir) {
11201120
lv_obj_set_scroll_dir(obj, dir);
11211121
}
11221122

1123+
EM_PORT_API(void) lvglSetScrollSnapX(lv_obj_t *obj, lv_scroll_snap_t align) {
1124+
lv_obj_set_scroll_snap_x(obj, align);
1125+
}
1126+
1127+
EM_PORT_API(void) lvglSetScrollSnapY(lv_obj_t *obj, lv_scroll_snap_t align) {
1128+
lv_obj_set_scroll_snap_y(obj, align);
1129+
}
1130+
11231131
EM_PORT_API(void) lvglTabviewSetActive(lv_obj_t *obj, uint32_t tab_id, lv_anim_enable_t anim_en) {
11241132
#if LVGL_VERSION_MAJOR >= 9
11251133
lv_tabview_set_active(obj, tab_id, anim_en);

packages/project-editor/flow/runtime/lvgl_runtime_v9.0.js

+2
Original file line numberDiff line numberDiff line change
@@ -4831,6 +4831,8 @@ var _lvglSetTimelinePosition = Module['_lvglSetTimelinePosition'] = createExport
48314831
var _lvglClearTimeline = Module['_lvglClearTimeline'] = createExportWrapper('lvglClearTimeline');
48324832
var _lvglSetScrollBarMode = Module['_lvglSetScrollBarMode'] = createExportWrapper('lvglSetScrollBarMode');
48334833
var _lvglSetScrollDir = Module['_lvglSetScrollDir'] = createExportWrapper('lvglSetScrollDir');
4834+
var _lvglSetScrollSnapX = Module['_lvglSetScrollSnapX'] = createExportWrapper('lvglSetScrollSnapX');
4835+
var _lvglSetScrollSnapY = Module['_lvglSetScrollSnapY'] = createExportWrapper('lvglSetScrollSnapY');
48344836
var _lvglTabviewSetActive = Module['_lvglTabviewSetActive'] = createExportWrapper('lvglTabviewSetActive');
48354837
var _lvglTabviewGetTabBar = Module['_lvglTabviewGetTabBar'] = createExportWrapper('lvglTabviewGetTabBar');
48364838
var _lvglTabviewGetTabContent = Module['_lvglTabviewGetTabContent'] = createExportWrapper('lvglTabviewGetTabContent');
Binary file not shown.

packages/project-editor/lvgl/lvgl-constants.ts

+14
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,20 @@ export const LV_ANIM_ON = 1;
247247

248248
////////////////////////////////////////////////////////////////////////////////
249249

250+
const LV_SCROLL_SNAP_NONE = 0;
251+
const LV_SCROLL_SNAP_START = 1;
252+
const LV_SCROLL_SNAP_END = 2;
253+
const LV_SCROLL_SNAP_CENTER = 3;
254+
255+
export const LVGL_SCROLL_SNAP: { [key: string]: number } = {
256+
none: LV_SCROLL_SNAP_NONE,
257+
start: LV_SCROLL_SNAP_START,
258+
end: LV_SCROLL_SNAP_END,
259+
center: LV_SCROLL_SNAP_CENTER
260+
};
261+
262+
////////////////////////////////////////////////////////////////////////////////
263+
250264
export const LVGL_FLAG_CODES = {
251265
HIDDEN: 1 << 0, // Make the object hidden. (Like it wasn't there at all)
252266
CLICKABLE: 1 << 1, // Make the object clickable by the input devices

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

+85-2
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ import {
8888
LVGL_STATE_CODES,
8989
LVGL_REACTIVE_STATES,
9090
LVGL_REACTIVE_FLAGS,
91-
LV_EVENT_CHECKED_STATE_CHANGED
91+
LV_EVENT_CHECKED_STATE_CHANGED,
92+
LVGL_SCROLL_SNAP
9293
} from "project-editor/lvgl/lvgl-constants";
9394
import { LVGLPropertyInfo } from "project-editor/lvgl/style-catalog";
9495

@@ -228,6 +229,8 @@ export class LVGLWidget extends Widget {
228229
widgetFlags: string;
229230
flagScrollbarMode: string;
230231
flagScrollDirection: string;
232+
scrollSnapX: string;
233+
scrollSnapY: string;
231234

232235
checkedState: string | boolean;
233236
checkedStateType: LVGLPropertyType;
@@ -467,6 +470,56 @@ export class LVGLWidget extends Widget {
467470
enumDisallowUndefined: false,
468471
propertyGridGroup: flagsGroup
469472
},
473+
{
474+
name: "scrollSnapX",
475+
displayName: "Scroll snap X",
476+
type: PropertyType.Enum,
477+
enumItems: [
478+
{
479+
id: "none",
480+
label: "NONE"
481+
},
482+
{
483+
id: "start",
484+
label: "START"
485+
},
486+
{
487+
id: "end",
488+
label: "END"
489+
},
490+
{
491+
id: "center",
492+
label: "CENTER"
493+
}
494+
],
495+
enumDisallowUndefined: false,
496+
propertyGridGroup: flagsGroup
497+
},
498+
{
499+
name: "scrollSnapY",
500+
displayName: "Scroll snap Y",
501+
type: PropertyType.Enum,
502+
enumItems: [
503+
{
504+
id: "none",
505+
label: "NONE"
506+
},
507+
{
508+
id: "start",
509+
label: "START"
510+
},
511+
{
512+
id: "end",
513+
label: "END"
514+
},
515+
{
516+
id: "center",
517+
label: "CENTER"
518+
}
519+
],
520+
enumDisallowUndefined: false,
521+
propertyGridGroup: flagsGroup
522+
},
470523
...makeLvglExpressionProperty(
471524
"checkedState",
472525
"boolean",
@@ -881,6 +934,8 @@ export class LVGLWidget extends Widget {
881934
heightUnit: "px",
882935
flagScrollbarMode: "",
883936
flagScrollDirection: "",
937+
scrollSnapX: "",
938+
scrollSnapY: "",
884939
hiddenFlagType: "literal",
885940
clickableFlagType: "literal",
886941
checkedStateType: "literal",
@@ -1013,6 +1068,8 @@ export class LVGLWidget extends Widget {
10131068
clickableFlagType: observable,
10141069
flagScrollbarMode: observable,
10151070
flagScrollDirection: observable,
1071+
scrollSnapX: observable,
1072+
scrollSnapY: observable,
10161073
checkedState: observable,
10171074
checkedStateType: observable,
10181075
disabledState: observable,
@@ -1369,6 +1426,20 @@ export class LVGLWidget extends Widget {
13691426
);
13701427
}
13711428

1429+
if (this.scrollSnapX) {
1430+
runtime.wasm._lvglSetScrollSnapX(
1431+
obj,
1432+
LVGL_SCROLL_SNAP[this.scrollSnapX]
1433+
);
1434+
}
1435+
1436+
if (this.scrollSnapY) {
1437+
runtime.wasm._lvglSetScrollSnapY(
1438+
obj,
1439+
LVGL_SCROLL_SNAP[this.scrollSnapY]
1440+
);
1441+
}
1442+
13721443
// add/clear states
13731444
{
13741445
const added =
@@ -1648,7 +1719,19 @@ export class LVGLWidget extends Widget {
16481719

16491720
if (this.flagScrollDirection) {
16501721
build.line(
1651-
`lv_obj_set_scroll_dir(obj, LV_DIR_${this.flagScrollDirection.toUpperCase()});`
1722+
`lv_obj_set_scroll_snap_x(obj, LV_DIR_${this.flagScrollDirection.toUpperCase()});`
1723+
);
1724+
}
1725+
1726+
if (this.scrollSnapX) {
1727+
build.line(
1728+
`lv_obj_set_scroll_snap_x(obj, LV_SCROLL_SNAP_${this.scrollSnapX.toUpperCase()});`
1729+
);
1730+
}
1731+
1732+
if (this.scrollSnapY) {
1733+
build.line(
1734+
`lv_obj_set_scroll_snap_y(obj, LV_SCROLL_SNAP_${this.scrollSnapY.toUpperCase()});`
16521735
);
16531736
}
16541737

0 commit comments

Comments
 (0)