Skip to content

Commit

Permalink
Implemented: [LVGL] Show "Code identifier" in Page and Widget propert…
Browse files Browse the repository at this point in the history
…ies #633
  • Loading branch information
mvladic committed Nov 13, 2024
1 parent f2356a9 commit 555f423
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 2 deletions.
29 changes: 28 additions & 1 deletion packages/project-editor/features/page/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@ import {
isDashboardProject,
isLVGLProject
} from "project-editor/project/project-type-traits";
import { Project, findStyle } from "project-editor/project/project";
import {
NamingConvention,
Project,
findStyle,
getName
} from "project-editor/project/project";

import type {
IResizeHandler,
Expand Down Expand Up @@ -212,6 +217,20 @@ export class Page extends Flow {
_lvglObj: number | undefined;
_lvglUserWidgetOfPageCopy: LVGLUserWidgetWidget;

get codeIdentifier() {
const codeIdentifier = getName(
"",
this.name,
NamingConvention.UnderscoreLowerCase
);

if (codeIdentifier == this.name) {
return undefined;
}

return codeIdentifier;
}

constructor() {
super();

Expand Down Expand Up @@ -296,6 +315,14 @@ export class Page extends Flow {
},
propertyGridGroup: generalGroup
},
{
name: "codeIdentifier",
type: PropertyType.String,
propertyGridGroup: generalGroup,
computed: true,
formText: `This identifier will be used in the generated source code in the "Objects" struct. It is different from the "Name" above because in the source code we are following "lowercase with underscore" naming convention.`,
disabled: (object: Page) => object.codeIdentifier == undefined
},
{
name: "description",
type: PropertyType.MultilineText,
Expand Down
31 changes: 30 additions & 1 deletion packages/project-editor/lvgl/widgets/Base.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ import {
ProjectType,
findAction,
findLvglStyle,
Project
Project,
NamingConvention,
getName
} from "project-editor/project/project";

import type {
Expand Down Expand Up @@ -527,6 +529,24 @@ export class LVGLWidget extends Widget {
_xScroll2: number = 0;
_yScroll2: number = 0;

get codeIdentifier() {
if (!this.identifier) {
return undefined;
}

const codeIdentifier = getName(
"",
this.identifier,
NamingConvention.UnderscoreLowerCase
);

if (codeIdentifier == this.identifier) {
return undefined;
}

return codeIdentifier;
}

static classInfo = makeDerivedClassInfo(Widget.classInfo, {
enabledInComponentPalette: (projectType: ProjectType) =>
projectType === ProjectType.LVGL,
Expand All @@ -550,6 +570,15 @@ export class LVGLWidget extends Widget {
propertyGridGroup: generalGroup,
disabled: object => object instanceof LVGLScreenWidget // LVGLScreenWidget is using Page name as identifier
},
{
name: "codeIdentifier",
type: PropertyType.String,
propertyGridGroup: generalGroup,
computed: true,
formText: `This identifier will be used in the generated source code in the "Objects" struct. It is different from the "Name" above because in the source code we are following "lowercase with underscore" naming convention.`,
disabled: (object: LVGLWidget) =>
object.codeIdentifier == undefined
},
{
name: "left",
type: PropertyType.Number,
Expand Down

0 comments on commit 555f423

Please sign in to comment.