Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
mvladic committed Apr 10, 2024
1 parent e738b3a commit e62e917
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 27 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"author": "Envox <eez@envox.hr>",
"description": "Cross-platform visual development tool and SCPI instrument controller",
"homepage": "https://www.envox.hr/eez/studio/studio-introduction.html",
"version": "0.12.0",
"version": "0.13.0",
"revision": "1",
"license": "GPL-3.0-only",
"repository": "https://github.com/eez-open/studio",
Expand Down
5 changes: 4 additions & 1 deletion packages/project-editor/lvgl/page-runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -752,7 +752,10 @@ export class LVGLStylesEditorRuntime extends LVGLPageRuntime {
// also, set useStyle
runInAction(() => {
for (const lvglWidget of this.lvglWidgetsMap.values()) {
const flags = lvglWidget.flags.split("|");
const flags =
lvglWidget.flags.trim() != ""
? lvglWidget.flags.split("|")
: [];

const i = flags.indexOf("HIDDEN");
if (i != -1) {
Expand Down
24 changes: 15 additions & 9 deletions packages/project-editor/lvgl/style-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,22 +87,28 @@ export function getStateBuildCode(state: string) {
export function getSelectorCode(partStr: string, statesStr: string) {
const partCode = getPartCode(partStr);

const statesCode = statesStr
.split("|")
.reduce((previousCode: number, currentStateStr: string) => {
return previousCode | getStateCode(currentStateStr);
}, 0);
const statesCode =
statesStr.trim() != ""
? statesStr
.split("|")
.reduce((previousCode: number, currentStateStr: string) => {
return previousCode | getStateCode(currentStateStr);
}, 0)
: 0;

return partCode | statesCode;
}

export function getSelectorBuildCode(partStr: string, statesStr: string) {
const partCode = getPartBuildCode(partStr);

const statesCode = statesStr
.split("|")
.map(state => getStateBuildCode(state))
.join(" | ");
const statesCode =
statesStr.trim() != ""
? statesStr
.split("|")
.map(state => getStateBuildCode(state))
.join(" | ")
: "0";

return `${partCode} | ${statesCode}`;
}
Expand Down
18 changes: 12 additions & 6 deletions packages/project-editor/lvgl/widget-common.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,12 @@ export const LVGLWidgetFlagsProperty = observer(
return;
}

const flagsArr = (
widget.flags || ""
).split("|");
const flagsArr =
widget.flags.trim() != ""
? widget.flags.split(
"|"
)
: [];
if (
flagsArr.indexOf(
flagName
Expand Down Expand Up @@ -275,9 +278,12 @@ export const LVGLWidgetStatesProperty = observer(
return;
}

const statesArr = (
widget.states || ""
).split("|");
const statesArr =
widget.states.trim() != ""
? widget.states.split(
"|"
)
: [];
if (
statesArr.indexOf(
stateName
Expand Down
53 changes: 43 additions & 10 deletions packages/project-editor/lvgl/widgets.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,13 @@ export const statesGroup: IPropertyGridGroupDefinition = {

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

function changes<T>(defaults: T[], arr: T[]) {
function changes<T extends string>(defaults: T[], arr: T[]) {
const added: T[] = [];
const cleared: T[] = [];

defaults = defaults.filter(x => x.trim() != "");
arr = arr.filter(x => x.trim() != "");

for (const x of arr) {
if (defaults.indexOf(x) == -1) {
added.push(x);
Expand Down Expand Up @@ -1193,7 +1196,10 @@ export class LVGLWidget extends Widget {
}

get allFlags() {
const flags = this.flags.split("|") as (keyof typeof LVGL_FLAG_CODES)[];
const flags =
this.flags.trim() != ""
? (this.flags.split("|") as (keyof typeof LVGL_FLAG_CODES)[])
: [];

LVGL_REACTIVE_FLAGS.forEach(flag => {
const propName = flag.toLowerCase() + "Flag";
Expand Down Expand Up @@ -1295,8 +1301,14 @@ export class LVGLWidget extends Widget {
// add/clear flags
{
const { added, cleared } = changes(
(lvglClassInfoProperties.defaultFlags ?? "").split("|"),
this.allFlags.split("|") as (keyof typeof LVGL_FLAG_CODES)[]
lvglClassInfoProperties.defaultFlags.trim() != ""
? lvglClassInfoProperties.defaultFlags.split("|")
: [],
this.allFlags.trim() != ""
? (this.allFlags.split(
"|"
) as (keyof typeof LVGL_FLAG_CODES)[])
: []
);

if (added.length > 0) {
Expand Down Expand Up @@ -1351,8 +1363,15 @@ export class LVGLWidget extends Widget {
// add/clear states
{
const { added, cleared } = changes(
(lvglClassInfoProperties.defaultStates ?? "").split("|"),
this.allStates.split("|") as (keyof typeof LVGL_STATE_CODES)[]
lvglClassInfoProperties.defaultStates &&
lvglClassInfoProperties.defaultStates.trim() != ""
? lvglClassInfoProperties.defaultStates.split("|")
: [],
this.allStates.trim() != ""
? (this.allStates.split(
"|"
) as (keyof typeof LVGL_STATE_CODES)[])
: []
);

if (added.length > 0) {
Expand Down Expand Up @@ -1514,9 +1533,16 @@ export class LVGLWidget extends Widget {

// add/clear flags
{
console.log("allFlags", this.allFlags);
const { added, cleared } = changes(
(lvglClassInfoProperties.defaultFlags ?? "").split("|"),
this.allFlags.split("|") as (keyof typeof LVGL_FLAG_CODES)[]
lvglClassInfoProperties.defaultFlags.trim() != ""
? lvglClassInfoProperties.defaultFlags.split("|")
: [],
this.allFlags.trim() != ""
? (this.allFlags.split(
"|"
) as (keyof typeof LVGL_FLAG_CODES)[])
: []
);

if (added.length > 0) {
Expand All @@ -1539,8 +1565,15 @@ export class LVGLWidget extends Widget {
// add/clear states
{
const { added, cleared } = changes(
(lvglClassInfoProperties.defaultStates ?? "").split("|"),
this.allStates.split("|") as (keyof typeof LVGL_STATE_CODES)[]
lvglClassInfoProperties.defaultStates &&
lvglClassInfoProperties.defaultStates.trim() != ""
? lvglClassInfoProperties.defaultStates.split("|")
: [],
this.allStates.trim() != ""
? (this.allStates.split(
"|"
) as (keyof typeof LVGL_STATE_CODES)[])
: []
);

if (added.length > 0) {
Expand Down

0 comments on commit e62e917

Please sign in to comment.