Better font wrappers, some style/naming revision, new wrappers

* Font -> NativeFont. Font is now a wrapper class for the NativeFont
  struct.
* FontAtlasWrapped -> FontAtlas, and FontAtlas -> NativeFontAtlas, in line
  with other native struct wrappers.
* [BREAKING CHANGE] Removed ImGui.LoadDefaultFont(). It is now available on FontAtlas along
  with other Font loading methods. This makes more sense w.r.t. the actual
  native interface.
  * Modified the SampleProgram to account for the above.
* New wrapper: ImGui.SetKeyboardFocusHere([int offset])
internals
Eric Mellino 8 years ago
parent a44f4a77e8
commit e832a590fa
  1. 2
      src/ImGui.NET.SampleProgram/SampleWindow.cs
  2. 12
      src/ImGui.NET/Font.cs
  3. 2
      src/ImGui.NET/FontAtlas.cs
  4. 28
      src/ImGui.NET/IO.cs
  5. 26
      src/ImGui.NET/ImGui.cs
  6. 34
      src/ImGui.NET/ImGuiNative.cs
  7. 2
      src/ImGui.NET/NativeIO.cs

@ -47,7 +47,7 @@ namespace ImGuiNET
_nativeWindow.KeyUp += OnKeyUp;
_nativeWindow.KeyPress += OnKeyPress;
ImGui.LoadDefaultFont();
ImGui.GetIO().FontAtlas.AddDefaultFont();
SetOpenTKKeyMappings();

@ -4,12 +4,22 @@ using System.Numerics;
namespace ImGuiNET
{
public unsafe class Font
{
public Font(NativeFont* nativePtr)
{
NativeFont = nativePtr;
}
public NativeFont* NativeFont { get; }
}
/// <summary>
/// Font runtime data and rendering.
/// ImFontAtlas automatically loads a default embedded font for you when you call GetTexDataAsAlpha8() or GetTexDataAsRGBA32().
/// </summary>
[StructLayout(LayoutKind.Sequential)]
public unsafe struct Font
public unsafe struct NativeFont
{
// Members: Settings

@ -13,7 +13,7 @@ namespace ImGuiNET
// 4. Call SetTexID(my_tex_id); and pass the pointer/identifier to your texture. This value will be passed back to you during rendering to identify the texture.
// 5. Call ClearTexData() to free textures memory on the heap.
[StructLayout(LayoutKind.Sequential)]
public unsafe struct FontAtlas
public unsafe struct NativeFontAtlas
{
// Members
// (Access texture data via GetTexData*() calls which will setup a default font for you.)

@ -14,7 +14,7 @@ namespace ImGuiNET
MouseDown = new MouseDownStates(nativePtr);
KeyMap = new KeyMap(_nativePtr);
KeysDown = new KeyDownStates(_nativePtr);
FontAtlas = new FontAtlasWrapped(_nativePtr->FontAtlas);
FontAtlas = new FontAtlas(_nativePtr->FontAtlas);
}
public NativeIO* GetNativePointer() => _nativePtr;
@ -86,7 +86,7 @@ namespace ImGuiNET
/// </summary>
public KeyDownStates KeysDown { get; }
public FontAtlasWrapped FontAtlas { get; }
public FontAtlas FontAtlas { get; }
public bool FontAllowUserScaling
{
@ -210,11 +210,11 @@ namespace ImGuiNET
}
}
public unsafe class FontAtlasWrapped
public unsafe class FontAtlas
{
private readonly FontAtlas* _atlasPtr;
private readonly NativeFontAtlas* _atlasPtr;
public FontAtlasWrapped(FontAtlas* atlasPtr)
public FontAtlas(NativeFontAtlas* atlasPtr)
{
_atlasPtr = atlasPtr;
}
@ -253,6 +253,24 @@ namespace ImGuiNET
{
ImGuiNative.ImFontAtlas_ClearTexData(_atlasPtr);
}
public Font AddDefaultFont()
{
NativeFont* nativeFontPtr = ImGuiNative.ImFontAtlas_AddFontDefault(_atlasPtr);
return new Font(nativeFontPtr);
}
public Font AddFontFromFileTTF(string fileName, float pixelSize)
{
NativeFont* nativeFontPtr = ImGuiNative.ImFontAtlas_AddFontFromFileTTF(_atlasPtr, fileName, pixelSize, IntPtr.Zero, null);
return new Font(nativeFontPtr);
}
public Font AddFontFromMemoryTTF(IntPtr ttfData, int ttfDataSize, float pixelSize)
{
NativeFont* nativeFontPtr = ImGuiNative.ImFontAtlas_AddFontFromMemoryTTF(_atlasPtr, ttfData.ToPointer(), ttfDataSize, pixelSize, IntPtr.Zero, null);
return new Font(nativeFontPtr);
}
}
public unsafe struct FontTextureData

@ -32,12 +32,6 @@ namespace ImGuiNET
return s_style;
}
public static unsafe void LoadDefaultFont()
{
NativeIO* ioPtr = ImGuiNative.igGetIO();
ImGuiNative.ImFontAtlas_AddFontDefault(ioPtr->FontAtlas);
}
public static void PushID(string id)
{
ImGuiNative.igPushIdStr(id);
@ -997,5 +991,25 @@ namespace ImGuiNET
{
ImGuiNative.igSetScrollHere(centerYRatio);
}
public static unsafe void PushFont(Font font)
{
ImGuiNative.igPushFont(font.NativeFont);
}
public static void PopFont()
{
ImGuiNative.igPopFont();
}
public static void SetKeyboardFocusHere()
{
ImGuiNative.igSetKeyboardFocusHere(0);
}
public static void SetKeyboardFocusHere(int offset)
{
ImGuiNative.igSetKeyboardFocusHere(offset);
}
}
}

@ -71,7 +71,7 @@ namespace ImGuiNET
[DllImport(cimguiLib)]
public static extern DrawList* igGetWindowDrawList();
[DllImport(cimguiLib)]
public static extern Font* igGetWindowFont();
public static extern NativeFont* igGetWindowFont();
[DllImport(cimguiLib)]
public static extern float igGetWindowFontSize();
[DllImport(cimguiLib)]
@ -147,7 +147,7 @@ namespace ImGuiNET
// Parameters stacks (shared)
[DllImport(cimguiLib)]
public static extern void igPushFont(Font* font);
public static extern void igPushFont(NativeFont* font);
[DllImport(cimguiLib)]
public static extern void igPopFont();
[DllImport(cimguiLib)]
@ -645,6 +645,12 @@ namespace ImGuiNET
public static extern float igGetTime();
[DllImport(cimguiLib)]
public static extern int igGetFrameCount();
internal static void igPushFont(object nativeFont)
{
throw new NotImplementedException();
}
[DllImport(cimguiLib)]
public static extern string igGetStyleColName(ColorTarget idx);
[DllImport(cimguiLib)]
@ -741,34 +747,34 @@ namespace ImGuiNET
[DllImport(cimguiLib)]
public static extern void ImFontAtlas_GetTexDataAsRGBA32(FontAtlas* atlas, byte** out_pixels, int* out_width, int* out_height, int* out_bytes_per_pixel);
public static extern void ImFontAtlas_GetTexDataAsRGBA32(NativeFontAtlas* atlas, byte** out_pixels, int* out_width, int* out_height, int* out_bytes_per_pixel);
[DllImport(cimguiLib)]
public static extern void ImFontAtlas_GetTexDataAsAlpha8(FontAtlas* atlas, byte** out_pixels, int* out_width, int* out_height, int* out_bytes_per_pixel);
public static extern void ImFontAtlas_GetTexDataAsAlpha8(NativeFontAtlas* atlas, byte** out_pixels, int* out_width, int* out_height, int* out_bytes_per_pixel);
[DllImport(cimguiLib)]
public static extern void ImFontAtlas_SetTexID(FontAtlas* atlas, void* tex);
public static extern void ImFontAtlas_SetTexID(NativeFontAtlas* atlas, void* tex);
[DllImport(cimguiLib)]
public static extern Font* ImFontAtlas_AddFont(FontAtlas* atlas, ref FontConfig font_cfg);
public static extern NativeFont* ImFontAtlas_AddFont(NativeFontAtlas* atlas, ref FontConfig font_cfg);
[DllImport(cimguiLib)]
public static extern Font* ImFontAtlas_AddFontDefault(FontAtlas* atlas, IntPtr font_cfg);
public static Font* ImFontAtlas_AddFontDefault(FontAtlas* atlas) { return ImFontAtlas_AddFontDefault(atlas, IntPtr.Zero); }
public static extern NativeFont* ImFontAtlas_AddFontDefault(NativeFontAtlas* atlas, IntPtr font_cfg);
public static NativeFont* ImFontAtlas_AddFontDefault(NativeFontAtlas* atlas) { return ImFontAtlas_AddFontDefault(atlas, IntPtr.Zero); }
[DllImport(cimguiLib)]
public static extern Font* ImFontAtlas_AddFontFromFileTTF(FontAtlas* atlas, string filename, float size_pixels, IntPtr font_cfg, char* glyph_ranges);
public static extern NativeFont* ImFontAtlas_AddFontFromFileTTF(NativeFontAtlas* atlas, string filename, float size_pixels, IntPtr font_cfg, char* glyph_ranges);
[DllImport(cimguiLib)]
public static extern Font* ImFontAtlas_AddFontFromMemoryTTF(FontAtlas* atlas, void* ttf_data, int ttf_size, float size_pixels, IntPtr font_cfg, char* glyph_ranges);
public static extern NativeFont* ImFontAtlas_AddFontFromMemoryTTF(NativeFontAtlas* atlas, void* ttf_data, int ttf_size, float size_pixels, IntPtr font_cfg, char* glyph_ranges);
[DllImport(cimguiLib)]
public static extern Font* ImFontAtlas_AddFontFromMemoryCompressedTTF(FontAtlas* atlas, void* compressed_ttf_data, int compressed_ttf_size, float size_pixels, FontConfig* font_cfg, char* glyph_ranges);
public static extern NativeFont* ImFontAtlas_AddFontFromMemoryCompressedTTF(NativeFontAtlas* atlas, void* compressed_ttf_data, int compressed_ttf_size, float size_pixels, FontConfig* font_cfg, char* glyph_ranges);
[DllImport(cimguiLib)]
public static extern Font* ImFontAtlas_AddFontFromMemoryCompressedBase85TTF(FontAtlas* atlas, string compressed_ttf_data_base85, float size_pixels, FontConfig* font_cfg, char* glyph_ranges);
public static extern NativeFont* ImFontAtlas_AddFontFromMemoryCompressedBase85TTF(NativeFontAtlas* atlas, string compressed_ttf_data_base85, float size_pixels, FontConfig* font_cfg, char* glyph_ranges);
[DllImport(cimguiLib)]
public static extern void ImFontAtlas_ClearTexData(FontAtlas* atlas);
public static extern void ImFontAtlas_ClearTexData(NativeFontAtlas* atlas);
[DllImport(cimguiLib)]
public static extern void ImFontAtlas_Clear(FontAtlas* atlas);
public static extern void ImFontAtlas_Clear(NativeFontAtlas* atlas);
[DllImport(cimguiLib)]

@ -77,7 +77,7 @@ namespace ImGuiNET
/// Load and assemble one or more fonts into a single tightly packed texture. Output to Fonts array.
/// Default value: [auto]
/// </summary>
public FontAtlas* FontAtlas;
public NativeFontAtlas* FontAtlas;
/// <summary>
/// Global scale all fonts.
/// Default value: 1.0f.

Loading…
Cancel
Save