@@ -92,6 +92,7 @@ import type { AssetsMap } from "eez-studio-types";
9292import { isDashboardProject } from "project-editor/project/project-type-traits" ;
9393import type { LVGLStyle } from "project-editor/lvgl/style" ;
9494import { BuildEezGuiLite } from "project-editor/eez-gui-lite/build" ;
95+ import { ColorFormat } from "project-editor/features/style/color-format" ;
9596
9697export { DummyDataBuffer , DataBuffer } from "project-editor/build/data-buffer" ;
9798
@@ -101,6 +102,8 @@ export class Assets {
101102 projects : Project [ ] ;
102103
103104 globalVariables : Variable [ ] ;
105+ nativeGlobalVariables : Variable [ ] ;
106+
104107 actions : Action [ ] ;
105108 pages : ( Page | undefined ) [ ] ;
106109 styles : Style [ ] ;
@@ -343,6 +346,7 @@ export class Assets {
343346 // than native
344347 ...nativeVariables
345348 ] ;
349+ this . nativeGlobalVariables = nativeVariables ;
346350
347351 //
348352 // actions
@@ -616,86 +620,111 @@ export class Assets {
616620 return this . getAssetIndex ( object , propertyName , findPage , this . pages ) ;
617621 }
618622
623+ styleCache : any ;
624+
619625 doGetStyleIndex (
620626 project : Project ,
621627 styleNameOrObject : string | Style
622628 ) : number {
623- if ( typeof styleNameOrObject === "string" ) {
624- const styleName = styleNameOrObject ;
629+ const find = ( ) => {
630+ if ( typeof styleNameOrObject === "string" ) {
631+ const styleName = styleNameOrObject ;
632+
633+ for ( let i = 0 ; i < this . styles . length ; i ++ ) {
634+ const style = this . styles [ i ] ;
635+ if ( style && style . name == styleName ) {
636+ return this . projectStore . masterProject ? - ( i + 1 ) : i + 1 ;
637+ }
638+ }
625639
626- for ( let i = 0 ; i < this . styles . length ; i ++ ) {
627- const style = this . styles [ i ] ;
628- if ( style && style . name == styleName ) {
629- return this . projectStore . masterProject ? - ( i + 1 ) : i + 1 ;
640+ const style = findStyle ( project , styleName ) ;
641+ if ( style ) {
642+ if ( style . id != undefined ) {
643+ return style . id ;
644+ }
645+
646+ const isMasterProjectStyle =
647+ this . projectStore . masterProject &&
648+ getProject ( style ) == this . projectStore . masterProject ;
649+ if ( isMasterProjectStyle ) {
650+ this . projectStore . outputSectionsStore . write (
651+ Section . OUTPUT ,
652+ MessageType . WARNING ,
653+ `master project style without ID can not be used` ,
654+ style
655+ ) ;
656+ } else {
657+ this . styles . push ( style ) ;
658+ return this . projectStore . masterProject
659+ ? - this . styles . length
660+ : this . styles . length ;
661+ }
662+ }
663+ } else {
664+ const style = styleNameOrObject ;
665+
666+ const parentStyle = style . parentStyle ;
667+ if ( parentStyle ) {
668+ if ( style . compareTo ( parentStyle ) ) {
669+ if ( style . id != undefined ) {
670+ return style . id ;
671+ }
672+ return this . doGetStyleIndex ( project , parentStyle . name ) ;
673+ }
630674 }
631- }
632675
633- const style = findStyle ( project , styleName ) ;
634- if ( style ) {
635- if ( style . id != undefined ) {
636- return style . id ;
676+ for ( let i = 0 ; i < this . styles . length ; i ++ ) {
677+ const s = this . styles [ i ] ;
678+ if ( s && style . compareTo ( s ) ) {
679+ return this . projectStore . masterProject ? - ( i + 1 ) : i + 1 ;
680+ }
637681 }
638682
639683 const isMasterProjectStyle =
640684 this . projectStore . masterProject &&
641685 getProject ( style ) == this . projectStore . masterProject ;
642686 if ( isMasterProjectStyle ) {
643- this . projectStore . outputSectionsStore . write (
644- Section . OUTPUT ,
645- MessageType . WARNING ,
646- `master project style without ID can not be used` ,
647- style
648- ) ;
687+ if ( style . id ) {
688+ return style . id ;
689+ } else {
690+ this . projectStore . outputSectionsStore . write (
691+ Section . OUTPUT ,
692+ MessageType . WARNING ,
693+ `master project style without ID can not be used` ,
694+ style
695+ ) ;
696+ }
649697 } else {
650698 this . styles . push ( style ) ;
651699 return this . projectStore . masterProject
652700 ? - this . styles . length
653701 : this . styles . length ;
654702 }
655703 }
656- } else {
657- const style = styleNameOrObject ;
658704
659- const parentStyle = style . parentStyle ;
660- if ( parentStyle ) {
661- if ( style . compareTo ( parentStyle ) ) {
662- if ( style . id != undefined ) {
663- return style . id ;
664- }
665- return this . doGetStyleIndex ( project , parentStyle . name ) ;
666- }
667- }
705+ return 0 ;
706+ }
668707
669- for ( let i = 0 ; i < this . styles . length ; i ++ ) {
670- const s = this . styles [ i ] ;
671- if ( s && style . compareTo ( s ) ) {
672- return this . projectStore . masterProject ? - ( i + 1 ) : i + 1 ;
673- }
674- }
708+ if ( ! this . styleCache ) {
709+ this . styleCache = new Map ( ) ;
710+ }
675711
676- const isMasterProjectStyle =
677- this . projectStore . masterProject &&
678- getProject ( style ) == this . projectStore . masterProject ;
679- if ( isMasterProjectStyle ) {
680- if ( style . id ) {
681- return style . id ;
682- } else {
683- this . projectStore . outputSectionsStore . write (
684- Section . OUTPUT ,
685- MessageType . WARNING ,
686- `master project style without ID can not be used` ,
687- style
688- ) ;
689- }
690- } else {
691- this . styles . push ( style ) ;
692- return this . projectStore . masterProject
693- ? - this . styles . length
694- : this . styles . length ;
695- }
712+ let projectMap = this . styleCache . get ( project ) ;
713+ if ( ! projectMap ) {
714+ projectMap = new Map ( ) ;
715+ this . styleCache . set ( project , projectMap ) ;
696716 }
697717
698- return 0 ;
718+ let styleIndex = projectMap . get ( styleNameOrObject ) ;
719+ if ( styleIndex != undefined ) {
720+ return styleIndex ;
721+ }
722+
723+ styleIndex = find ( ) ;
724+
725+ projectMap . set ( styleNameOrObject , styleIndex ) ;
726+
727+ return styleIndex ;
699728 }
700729
701730 getStyleIndex ( object : any , propertyName : string ) : number {
@@ -851,6 +880,12 @@ export class Assets {
851880 | "borderColor"
852881 ) {
853882 let color = getStyleProperty ( style , propertyName , false ) ;
883+ if ( color != "transparent" ) {
884+ const colorFormat = ColorFormat . parse ( color , this . projectStore . project ) ;
885+ if ( ! colorFormat . isUsingThemeColor ) {
886+ color = colorFormat . getHexString ( ) ;
887+ }
888+ }
854889 return this . getColorIndexFromColorValue ( color ) ;
855890 }
856891
@@ -1095,6 +1130,15 @@ export class Assets {
10951130 flowState . flowWidgetDataIndexes . set ( path , index ) ;
10961131 flowState . flowWidgetFromDataIndex . set ( index , widget ) ;
10971132 }
1133+
1134+ if ( this . projectStore . projectTypeTraits . isFirmware ) {
1135+ let expression = getProperty ( widget , propertyName ) . trim ( ) ;
1136+ const globalVariableIndex = this . nativeGlobalVariables . findIndex ( globalVariable => globalVariable . name == expression ) ;
1137+ if ( globalVariableIndex != - 1 ) {
1138+ return globalVariableIndex + 1 ;
1139+ }
1140+ }
1141+
10981142 return - ( index + 1 ) ;
10991143 }
11001144
@@ -1397,9 +1441,9 @@ function buildHeaderData(
13971441 dataBuffer . writeUint8Array ( tag ) ;
13981442
13991443 // projectMajorVersion
1400- dataBuffer . writeUint8 ( 3 ) ; // PROJECT MAJOR VERSION: 3
1444+ dataBuffer . writeUint8 ( 3 ) ;
14011445 // projectMinorVersion
1402- dataBuffer . writeUint8 ( 0 ) ; // PROJECT MINOR VERSION: 0
1446+ dataBuffer . writeUint8 ( assets . projectStore . project . settings . general . colorBpp == "16" ? 0 : 1 ) ;
14031447
14041448 // assetsType
14051449 dataBuffer . writeUint8 ( assets . projectStore . projectTypeTraits . id ) ;
@@ -1448,7 +1492,10 @@ function buildLanguages(assets: Assets, dataBuffer: DataBuffer) {
14481492 ) ;
14491493}
14501494
1451- export async function buildGuiAssetsData ( assets : Assets ) {
1495+ export async function buildGuiAssetsData (
1496+ assets : Assets ,
1497+ option : "check" | "buildAssets" | "buildFiles"
1498+ ) {
14521499 const dataBuffer = new DataBuffer ( assets . utf8Support ) ;
14531500
14541501 // settings
@@ -1465,7 +1512,7 @@ export async function buildGuiAssetsData(assets: Assets) {
14651512 // fonts
14661513 await buildGuiFontsData ( assets , dataBuffer ) ;
14671514 // bitmaps
1468- await buildGuiBitmapsData ( assets , dataBuffer ) ;
1515+ await buildGuiBitmapsData ( assets , dataBuffer , option ) ;
14691516 }
14701517 // colorsDefinition
14711518 buildGuiColors ( assets , dataBuffer ) ;
@@ -1657,7 +1704,7 @@ export async function buildAssets(
16571704 ) {
16581705 // build all assets as single data chunk
16591706 const { uncompressedData, compressedData } = await buildGuiAssetsData (
1660- assets
1707+ assets , option
16611708 ) ;
16621709
16631710 if ( option != "buildAssets" ) {
0 commit comments