Skip to content

Commit

Permalink
Merge pull request #27 from psydack/feature/add-font-init-param
Browse files Browse the repository at this point in the history
Feature/add font init param
  • Loading branch information
psydack authored Jan 14, 2022
2 parents 27afa3f + 9938acd commit 40dcacc
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 8 deletions.
49 changes: 48 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,46 @@ private unsafe int CustomCallback(ImGuiInputTextCallbackData* data)
```
![image](https://user-images.githubusercontent.com/961971/120383734-a1ad4880-c2fb-11eb-87e1-398d5e7aac97.png)

Custom font

[Thanks](https://github.com/psydack/uimgui/pull/24)
[Check here for more information](https://github.com/ocornut/imgui/blob/master/docs/FONTS.md)

- First create a method with ImGuiIOPtr like this
```cs
public void AddJapaneseFont(ImGuiIOPtr io)
{
// you can put on StreamingAssetsFolder and call from there like:
//string fontPath = $"{Application.streamingAssetsPath}/NotoSansCJKjp - Medium.otf";
string fontPath = "D:\\Users\\rofli.souza\\Desktop\\NotoSansCJKjp-Medium.otf";
io.Fonts.AddFontFromFileTTF(fontPath, 18, null, io.Fonts.GetGlyphRangesJapanese());

// you can create a configs and do a lot of stuffs
//ImFontConfig fontConfig = default;
//ImFontConfigPtr fontConfigPtr = new ImFontConfigPtr(&fontConfig);
//fontConfigPtr.MergeMode = true;
//io.Fonts.AddFontDefault(fontConfigPtr);
//int[] icons = { 0xf000, 0xf3ff, 0 };
//fixed (void* iconsPtr = icons)
//{
// io.Fonts.AddFontFromFileTTF("fontawesome-webfont.ttf", 18.0f, fontConfigPtr, (System.IntPtr)iconsPtr);
//}
}
```
- Assign the object that contain these method in UImGui script
![image](https://user-images.githubusercontent.com/961971/149441417-54b319c8-30e7-40dd-aa56-edaede47543d.png)
- Call an awesome Text to text:
```cs
if (ImGui.Begin("ウィンドウテスト"))
{
ImGui.Text("こんにちは!テスト");

ImGui.End();
}
```
![image](https://user-images.githubusercontent.com/961971/149443777-38f439f5-5aca-4188-a21b-32274e901382.png)
Yay!

You can [see more samples here](https://pthom.github.io/imgui_manual_online/manual/imgui_manual.html).

Using URP
Expand All @@ -295,7 +335,12 @@ Using URP

Using HDRP
-------
- When using the ``High Definition Render Pipeline``, add a custom render pass and select "DearImGuiPass" injected after post processing.
- When using the ``High Definition Render Pipeline``;
- Add a script called Custom Pass Volume anywhere on your scene;
- Add "DearImGuiPass"
- Update Injection Point to before or after post processing.
- Good to go.
Any doubts [see this link](https://docs.unity3d.com/Packages/[email protected]/manual/Custom-Pass.html)

Using Built in
-------
Expand All @@ -314,6 +359,8 @@ Issue: Already using ``System.Runtime.CompilerServices.Unsafe.dll`` will cause t
Resolution: add ``UIMGUI_REMOVE_UNSAFE_DLL`` on Project Settings > Player > Other Settings > Script define symbols > Apply > Restart Unity Editor.

Issue: ImPlot isn't work right.

Issue: Font atlas crash. There's no fix. Use callback for custom font instead

Credits
-------
Expand Down
8 changes: 5 additions & 3 deletions Source/Texture/TextureManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Unity.Collections;
using Unity.Collections.LowLevel.Unsafe;
using UnityEngine;
using UnityEngine.Events;
using UTexture = UnityEngine.Texture;

namespace UImGui.Texture
Expand Down Expand Up @@ -101,7 +102,7 @@ private IntPtr RegisterTexture(UTexture texture)
return id;
}

public void BuildFontAtlas(ImGuiIOPtr io, in FontAtlasConfigAsset settings, UnityEngine.Events.UnityEvent custom)
public void BuildFontAtlas(ImGuiIOPtr io, in FontAtlasConfigAsset settings, UnityEvent<ImGuiIOPtr> custom)
{
if (io.Fonts.IsBuilt())
{
Expand All @@ -117,13 +118,14 @@ public void BuildFontAtlas(ImGuiIOPtr io, in FontAtlasConfigAsset settings, Unit
{
if (custom.GetPersistentEventCount() > 0)
{
custom.Invoke();
custom.Invoke(io);
}
else
{
io.Fonts.AddFontDefault();
io.Fonts.Build();
}

io.Fonts.Build();
return;
}

Expand Down
6 changes: 3 additions & 3 deletions Source/UImGui.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
using UImGui.Platform;
using UImGui.Renderer;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.Rendering;
#if HAS_HDRP
#endif


namespace UImGui
{
Expand Down Expand Up @@ -62,7 +62,7 @@ public class UImGui : MonoBehaviour
};

[SerializeField]
private UnityEngine.Events.UnityEvent _fontCustomInitializer;
private UnityEvent<ImGuiIOPtr> _fontCustomInitializer;

[SerializeField]
private FontAtlasConfigAsset _fontAtlasConfiguration = null;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "com.psydack.uimgui",
"displayName": "UImGui",
"version": "4.0.1",
"version": "4.1.0",
"description": "A Unity wrapper for ImGui",
"unity": "2019.4",
"dependencies": {
Expand Down

0 comments on commit 40dcacc

Please sign in to comment.