@@ -640,31 +640,49 @@ proc `<`*(date1, date2: TomlDateTime): bool =
640
640
elif date1.time.get ().subsecond < date2.time.get ().subsecond:
641
641
result = true
642
642
643
- proc strObjWithoutFieldNames * [T: object ](obj: T, withoutName = false ): string =
644
- if not withoutName:
643
+ proc str * (x: float32 , exportKind: ExportKind ): string =
644
+ case exportKind
645
+ of Nim , Cpp , CSharp :
646
+ $ x & 'f'
647
+ else :
648
+ $ x
649
+
650
+ proc str * (obj: object , exportKind: ExportKind , objName = true , fieldNames = true ): string =
651
+ # # Modified version of dollars.`$`(object)
652
+
653
+ if objName:
645
654
result = $ typeof obj
646
-
655
+
647
656
result .add " ("
657
+
648
658
var count = 0
659
+
649
660
for name, field in obj.fieldPairs:
650
661
if count > 0 : result .add " , "
662
+
663
+ if fieldNames:
664
+ result .add (name)
665
+ result .add (" : " )
666
+
651
667
inc count
652
668
653
669
when compiles ($ field):
654
- when field isnot string and field isnot seq and compiles (field.isNil):
670
+ when field isnot ( string or seq ) and compiles (field.isNil):
655
671
if field.isNil: result .add " nil"
656
- else : result .addQuoted (field)
672
+ else :
673
+ when compiles (result .add field.str (exportKind)):
674
+ result .add field.str (exportKind)
675
+ else :
676
+ result .addQuoted (field)
657
677
else :
658
- result .addQuoted (field)
659
- else :
678
+ when compiles (result .add field.str (exportKind)):
679
+ result .add field.str (exportKind)
680
+ else :
681
+ result .addQuoted (field) else :
660
682
result .add (" ..." )
661
683
662
684
result .add " )"
663
685
664
- proc strObjWithFieldNames * [T: object ](obj: T): string =
665
- result = $ typeof obj
666
- result .add $ obj
667
-
668
686
proc formatTemplate * (style: ImGuiStyle , themeName: string , exportKind: ExportKind , author, description, forkedFrom = " " , tags = newSeq [string ]()): string =
669
687
result =
670
688
case exportKind
@@ -725,11 +743,11 @@ proc formatTemplate*(style: ImGuiStyle, themeName: string, exportKind: ExportKin
725
743
when field is ImVec2 :
726
744
case exportKind
727
745
of Cpp :
728
- body.add (field.strObjWithoutFieldNames ( ))
746
+ body.add (field.str (exportKind, fieldNames = false ))
729
747
of CSharp :
730
- body.add (" new Vector2" & field.strObjWithoutFieldNames ( true ))
748
+ body.add (" new Vector2" & field.str (exportKind, objName = false , fieldNames = false ))
731
749
of Nim :
732
- body.add (field.strObjWithFieldNames ( ))
750
+ body.add (field.str (exportKind ))
733
751
of ImStyle , Publish :
734
752
body.add ('[' & $ field.x & " , " & $ field.y & ']' )
735
753
elif field is enum :
@@ -741,7 +759,7 @@ proc formatTemplate*(style: ImGuiStyle, themeName: string, exportKind: ExportKin
741
759
of ImStyle , Publish :
742
760
body.add ('"' & $ field & '"' )
743
761
elif field is float32 :
744
- body.add ($ field)
762
+ body.add (field. str (exportKind) )
745
763
746
764
if exportKind in {Cpp , CSharp }:
747
765
body.add (';' )
@@ -760,11 +778,11 @@ proc formatTemplate*(style: ImGuiStyle, themeName: string, exportKind: ExportKin
760
778
let colVec = style.colors[ord col]
761
779
case exportKind
762
780
of Cpp :
763
- body.add (& " style.Colors[ImGuiCol_{ col} ] = { colVec.strObjWithoutFieldNames ( )} ; " )
781
+ body.add (& " style.Colors[ImGuiCol_{ col} ] = { colVec.str (exportKind, fieldNames = false )} ; " )
764
782
of CSharp :
765
- body.add (& " style.Colors[(int)ImGuiCol.{ col} ] = new Vector4{ colVec.strObjWithoutFieldNames ( true )} ; " )
783
+ body.add (& " style.Colors[(int)ImGuiCol.{ col} ] = new Vector4{ colVec.str (exportKind, objName = false , fieldNames = false )} ; " )
766
784
of Nim :
767
- body.add (& " style.colors[ord ImGuiCol.{ col} ] = { colVec.strObjWithFieldNames ( )} " )
785
+ body.add (& " style.colors[ord ImGuiCol.{ col} ] = { colVec.str (exportKind )} " )
768
786
of ImStyle , Publish :
769
787
if exportKind == Publish :
770
788
body.add (" " ) # Indentation
0 commit comments