import React from "react"; import { observable, makeObservable } from "mobx"; import { makeDerivedClassInfo } from "project-editor/core/object"; import { Project, ProjectType } from "project-editor/project/project"; import { specificGroup } from "project-editor/ui-components/PropertyGrid/groups"; import { LVGLWidget } from "./internal"; import { makeLvglExpressionProperty } from "../expression-property"; import type { LVGLCode } from "project-editor/lvgl/to-lvgl-code"; //////////////////////////////////////////////////////////////////////////////// export class LVGLCheckboxWidget extends LVGLWidget { text: string; textType: string; static classInfo = makeDerivedClassInfo(LVGLWidget.classInfo, { enabledInComponentPalette: (projectType: ProjectType) => projectType === ProjectType.LVGL, componentPaletteGroupName: "!1Input", properties: [ ...makeLvglExpressionProperty( "text", "string", "input", ["literal", "translated-literal"], { propertyGridGroup: specificGroup } ) ], beforeLoadHook: ( object: LVGLCheckboxWidget, jsObject: Partial ) => { if (!jsObject.textType) { jsObject.textType = "literal"; } }, defaultValue: { left: 0, top: 0, width: 105, widthUnit: "content", height: 20, heightUnit: "content", clickableFlag: true, text: "Checkbox", textType: "literal" }, icon: ( ), lvgl: (widget: LVGLCheckboxWidget, project: Project) => { return { parts: ["MAIN", "INDICATOR"], defaultFlags: project.settings.general.lvglVersion == "9.0" ? "CHECKABLE|CLICKABLE|CLICK_FOCUSABLE|GESTURE_BUBBLE|PRESS_LOCK|SCROLL_CHAIN_HOR|SCROLL_CHAIN_VER|SCROLL_ELASTIC|SCROLL_MOMENTUM|SCROLL_ON_FOCUS|SCROLL_WITH_ARROW|SNAPPABLE" : "CHECKABLE|CLICKABLE|CLICK_FOCUSABLE|GESTURE_BUBBLE|PRESS_LOCK|SCROLLABLE|SCROLL_CHAIN_HOR|SCROLL_CHAIN_VER|SCROLL_ELASTIC|SCROLL_MOMENTUM|SCROLL_ON_FOCUS|SCROLL_WITH_ARROW|SNAPPABLE", states: ["CHECKED", "DISABLED", "FOCUSED", "PRESSED"], oldInitFlags: "PRESS_LOCK|CLICK_FOCUSABLE|GESTURE_BUBBLE|SNAPPABLE|SCROLL_ON_FOCUS", oldDefaultFlags: "CLICKABLE|PRESS_LOCK|CLICK_FOCUSABLE|GESTURE_BUBBLE|SNAPPABLE|SCROLL_ON_FOCUS" }; } }); override makeEditable() { super.makeEditable(); makeObservable(this, { text: observable, textType: observable }); } override toLVGLCode(code: LVGLCode) { code.createObject("lv_checkbox_create"); code.callObjectFunction( "lv_checkbox_set_text", code.stringProperty(this.textType, this.text) ); } }