Skip to content

Commit a7e1243

Browse files
Merge pull request #15 from Patitotective/devel
2 parents 2298b87 + 5097469 commit a7e1243

File tree

3 files changed

+38
-20
lines changed

3 files changed

+38
-20
lines changed

ImThemes.nimble

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Package
22

3-
version = "0.2.5"
3+
version = "0.2.6"
44
author = "Patitotective"
55
description = "ImThemes is a Dear ImGui theme designer and browser written in Nim"
66
license = "MIT"

config.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# App
22
name = "ImThemes"
33
comment = "ImThemes is a Dear ImGui theme designer and browser written in Nim"
4-
version = "0.2.5"
4+
version = "0.2.6"
55
website = "https://github.com/Patitotective/ImThemes"
66
authors = ["Patitotective <https://github.com/Patitotective>"]
77
categories = ["Utility"]

src/utils.nim

+36-18
Original file line numberDiff line numberDiff line change
@@ -640,31 +640,49 @@ proc `<`*(date1, date2: TomlDateTime): bool =
640640
elif date1.time.get().subsecond < date2.time.get().subsecond:
641641
result = true
642642

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:
645654
result = $typeof obj
646-
655+
647656
result.add "("
657+
648658
var count = 0
659+
649660
for name, field in obj.fieldPairs:
650661
if count > 0: result.add ", "
662+
663+
if fieldNames:
664+
result.add(name)
665+
result.add(": ")
666+
651667
inc count
652668

653669
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):
655671
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)
657677
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:
660682
result.add("...")
661683

662684
result.add ")"
663685

664-
proc strObjWithFieldNames*[T: object](obj: T): string =
665-
result = $typeof obj
666-
result.add $obj
667-
668686
proc formatTemplate*(style: ImGuiStyle, themeName: string, exportKind: ExportKind, author, description, forkedFrom = "", tags = newSeq[string]()): string =
669687
result =
670688
case exportKind
@@ -725,11 +743,11 @@ proc formatTemplate*(style: ImGuiStyle, themeName: string, exportKind: ExportKin
725743
when field is ImVec2:
726744
case exportKind
727745
of Cpp:
728-
body.add(field.strObjWithoutFieldNames())
746+
body.add(field.str(exportKind, fieldNames = false))
729747
of CSharp:
730-
body.add("new Vector2" & field.strObjWithoutFieldNames(true))
748+
body.add("new Vector2" & field.str(exportKind, objName = false, fieldNames = false))
731749
of Nim:
732-
body.add(field.strObjWithFieldNames())
750+
body.add(field.str(exportKind))
733751
of ImStyle, Publish:
734752
body.add('[' & $field.x & ", " & $field.y & ']')
735753
elif field is enum:
@@ -741,7 +759,7 @@ proc formatTemplate*(style: ImGuiStyle, themeName: string, exportKind: ExportKin
741759
of ImStyle, Publish:
742760
body.add('"' & $field & '"')
743761
elif field is float32:
744-
body.add($field)
762+
body.add(field.str(exportKind))
745763

746764
if exportKind in {Cpp, CSharp}:
747765
body.add(';')
@@ -760,11 +778,11 @@ proc formatTemplate*(style: ImGuiStyle, themeName: string, exportKind: ExportKin
760778
let colVec = style.colors[ord col]
761779
case exportKind
762780
of Cpp:
763-
body.add(&"style.Colors[ImGuiCol_{col}] = {colVec.strObjWithoutFieldNames()};")
781+
body.add(&"style.Colors[ImGuiCol_{col}] = {colVec.str(exportKind, fieldNames = false)};")
764782
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)};")
766784
of Nim:
767-
body.add(&"style.colors[ord ImGuiCol.{col}] = {colVec.strObjWithFieldNames()}")
785+
body.add(&"style.colors[ord ImGuiCol.{col}] = {colVec.str(exportKind)}")
768786
of ImStyle, Publish:
769787
if exportKind == Publish:
770788
body.add(" ") # Indentation

0 commit comments

Comments
 (0)