Skip to content

Commit

Permalink
Implemented: [LVGL] add translated literal to text Checkbox #631
Browse files Browse the repository at this point in the history
  • Loading branch information
mvladic committed Nov 13, 2024
1 parent 4a62634 commit 7c8bb65
Showing 1 changed file with 34 additions and 10 deletions.
44 changes: 34 additions & 10 deletions packages/project-editor/lvgl/widgets/Checkbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ import type { LVGLBuild } from "project-editor/lvgl/build";

import { LVGLWidget } from "./internal";
import { escapeCString, unescapeCString } from "../widget-common";
import { makeLvglExpressionProperty } from "../expression-property";

////////////////////////////////////////////////////////////////////////////////

export class LVGLCheckboxWidget extends LVGLWidget {
text: string;
textType: string;

static classInfo = makeDerivedClassInfo(LVGLWidget.classInfo, {
enabledInComponentPalette: (projectType: ProjectType) =>
Expand All @@ -25,13 +27,26 @@ export class LVGLCheckboxWidget extends LVGLWidget {
componentPaletteGroupName: "!1Input",

properties: [
{
name: "text",
type: PropertyType.String,
propertyGridGroup: specificGroup
}
...makeLvglExpressionProperty(
"text",
"string",
"input",
["literal", "translated-literal"],
{
propertyGridGroup: specificGroup
}
)
],

beforeLoadHook: (
object: LVGLCheckboxWidget,
jsObject: Partial<LVGLCheckboxWidget>
) => {
if (!jsObject.textType) {
jsObject.textType = "literal";
}
},

defaultValue: {
left: 0,
top: 0,
Expand All @@ -40,7 +55,8 @@ export class LVGLCheckboxWidget extends LVGLWidget {
height: 20,
heightUnit: "content",
clickableFlag: true,
text: "Checkbox"
text: "Checkbox",
textType: "literal"
},

icon: (
Expand Down Expand Up @@ -73,7 +89,7 @@ export class LVGLCheckboxWidget extends LVGLWidget {
override makeEditable() {
super.makeEditable();

makeObservable(this, { text: observable });
makeObservable(this, { text: observable, textType: observable });
}

override lvglCreateObj(
Expand All @@ -100,8 +116,16 @@ export class LVGLCheckboxWidget extends LVGLWidget {
}

override lvglBuildSpecific(build: LVGLBuild) {
build.line(
`lv_checkbox_set_text(obj, ${escapeCString(this.text ?? "")});`
);
if (this.textType == "literal") {
build.line(
`lv_checkbox_set_text(obj, ${escapeCString(this.text ?? "")});`
);
} else {
build.line(
`lv_checkbox_set_text(obj, _(${escapeCString(
this.text ?? ""
)}));`
);
}
}
}

0 comments on commit 7c8bb65

Please sign in to comment.