From f6a391c131d5aa4039b5505be01538bda1811d2c Mon Sep 17 00:00:00 2001 From: Martin Vladic Date: Sun, 10 Nov 2024 17:33:58 +0100 Subject: [PATCH] #628 --- packages/project-editor/lvgl/groups.tsx | 136 ++++++++++++++++++++++++ 1 file changed, 136 insertions(+) diff --git a/packages/project-editor/lvgl/groups.tsx b/packages/project-editor/lvgl/groups.tsx index 91650306..a9ac54a5 100644 --- a/packages/project-editor/lvgl/groups.tsx +++ b/packages/project-editor/lvgl/groups.tsx @@ -28,6 +28,11 @@ import { Checkbox } from "project-editor/ui-components/PropertyGrid/Checkbox"; import { ProjectEditor } from "project-editor/project-editor-interface"; import { IListNode, List, ListItem } from "eez-studio-ui/list"; import type { Widget } from "project-editor/flow/component"; +import { CodeEditor } from "eez-studio-ui/code-editor"; +import { Build, getName, NamingConvention } from "project-editor/build/helper"; +import { Icon } from "eez-studio-ui/icon"; +import { IconAction } from "eez-studio-ui/action"; +import { clipboard } from "electron"; //////////////////////////////////////////////////////////////////////////////// @@ -78,6 +83,130 @@ const DefaultGroupPropertyGridUI = observer( //////////////////////////////////////////////////////////////////////////////// +export const GroupImplementationInfoPropertyUI = observer( + class GroupImplementationInfoPropertyUI extends React.Component { + static contextType = ProjectContext; + declare context: React.ContextType; + + codeEditorRef = React.createRef(); + + componentDidMount() { + this.codeEditorRef.current?.resize(); + } + + componentDidUpdate() { + this.codeEditorRef.current?.resize(); + } + + get projectStore() { + return ProjectEditor.getProjectStore(this.group); + } + + get implementationLanguage() { + return this.projectStore.uiStateStore.implementationLanguage; + } + + get hasFlowSupport() { + return this.projectStore.projectTypeTraits.hasFlowSupport; + } + + get group() { + return this.props.objects[0] as LVGLGroup; + } + + get code() { + const group = this.group; + + const groupName = getName( + "", + group.name, + NamingConvention.UnderscoreLowerCase + ); + + const build = new Build(); + build.startBuild(); + + build.line(`#include "ui.h"`); + build.line( + `#include "screens.h" // pick group declarations from here` + ); + + build.line(""); + + build.line(`// you should initialize your input device`); + build.line(`// before calling "ui_create_groups()"`); + build.line("lv_indev_t *my_indev;"); + build.line("// ..."); + + build.line(""); + + build.line(`// call this before "ui_init()"`); + build.line(`ui_create_groups();`); + + build.line(""); + + build.line("// set group for your input device"); + build.line(`lv_indev_set_group(my_indev, groups.${groupName});`); + + build.line(""); + build.line("// ..."); + build.line(""); + + build.line(`ui_init();`); + + build.line(""); + + build.line("// ..."); + + return build.result; + } + + render() { + const code = this.code; + + return ( +
+
+
+ + TIP +
+
+ From your code you neeed to set a destination group + for a particular input device using + lv_indev_set_group. Below is an example code + that does that. +
+
+
+ { + clipboard.writeText(code); + }} + /> +
+
+ {}} + readOnly={true} + className="form-control" + minLines={2} + maxLines={50} + /> +
+ ); + } + } +); + +//////////////////////////////////////////////////////////////////////////////// + export class LVGLGroup extends EezObject { name: string; @@ -101,6 +230,13 @@ export class LVGLGroup extends EezObject { type: PropertyType.Any, computed: true, propertyGridColumnComponent: DefaultGroupPropertyGridUI + }, + { + name: "groupImplementationInfo", + type: PropertyType.Any, + computed: true, + propertyGridRowComponent: GroupImplementationInfoPropertyUI, + skipSearch: true } ], newItem: async (parent: IEezObject) => {