Skip to content

Commit

Permalink
allow one extra font to be configured in the ImGuiNode properties
Browse files Browse the repository at this point in the history
  • Loading branch information
pkdawson committed Sep 19, 2022
1 parent 31e9636 commit c9f1ac0
Showing 1 changed file with 27 additions and 3 deletions.
30 changes: 27 additions & 3 deletions addons/imgui-godot/ImGuiNode.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Godot;
using ImGuiNET;
using System;

public partial class ImGuiNode : Node2D
{
Expand All @@ -9,6 +10,15 @@ public partial class ImGuiNode : Node2D
[Export]
public float FontSize = 16.0f;

[Export]
public FontFile ExtraFont = null;

[Export]
public float ExtraFontSize = 16.0f;

[Export(PropertyHint.Enum, "Korean,Japanese,ChineseFull,ChineseSimplifiedCommon,Cyrillic,Thai,Vietnamese")]
public string ExtraFontGlyphRange = "Japanese";

[Export]
public bool IncludeDefaultFont = true;

Expand All @@ -20,10 +30,24 @@ public virtual void Init(ImGuiIOPtr io)
if (Font is not null)
{
ImGuiGD.AddFont(Font, FontSize);
if (IncludeDefaultFont)
io.Fonts.AddFontDefault();
if (ExtraFont is not null)
{
IntPtr gr = ExtraFontGlyphRange switch
{
"Korean" => io.Fonts.GetGlyphRangesKorean(),
"Japanese" => io.Fonts.GetGlyphRangesJapanese(),
"ChineseFull" => io.Fonts.GetGlyphRangesChineseFull(),
"ChineseSimplifiedCommon" => io.Fonts.GetGlyphRangesChineseSimplifiedCommon(),
"Cyrillic" => io.Fonts.GetGlyphRangesCyrillic(),
"Thai" => io.Fonts.GetGlyphRangesThai(),
"Vietnamese" => io.Fonts.GetGlyphRangesVietnamese(),
_ => throw new Exception("invalid glyph range")
};
ImGuiGD.AddFontMerge(ExtraFont, ExtraFontSize, gr);
}
}
else

if (IncludeDefaultFont)
{
io.Fonts.AddFontDefault();
}
Expand Down

0 comments on commit c9f1ac0

Please sign in to comment.