Open pixtur opened 2 years ago
Hi ... I just ran into this issue as well. To properly fix this issue we'll have to modify the code generator. But right now I don't have time to look into that so here's a very quick hack.
Just replace ImFontGlyph.gen.cs with this... it replaces the 3 packed variables with a single uint masked & shifted.
using System;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Text;
namespace ImGuiNET
{
public unsafe partial struct ImFontGlyph
{
/* Generated C#
public uint Colored;
public uint Visible;
public uint Codepoint;
*/
/* C Structure
unsigned int Colored : 1;
unsigned int Visible : 1;
unsigned int Codepoint : 30;
*/
//Begin Fix
public uint Packed;
//End Fix
public float AdvanceX;
public float X0;
public float Y0;
public float X1;
public float Y1;
public float U0;
public float V0;
public float U1;
public float V1;
}
public unsafe partial struct ImFontGlyphPtr
{
public ImFontGlyph* NativePtr { get; }
public ImFontGlyphPtr(ImFontGlyph* nativePtr) => NativePtr = nativePtr;
public ImFontGlyphPtr(IntPtr nativePtr) => NativePtr = (ImFontGlyph*)nativePtr;
public static implicit operator ImFontGlyphPtr(ImFontGlyph* nativePtr) => new ImFontGlyphPtr(nativePtr);
public static implicit operator ImFontGlyph* (ImFontGlyphPtr wrappedPtr) => wrappedPtr.NativePtr;
public static implicit operator ImFontGlyphPtr(IntPtr nativePtr) => new ImFontGlyphPtr(nativePtr);
/* Generated C#
public ref uint Colored => ref Unsafe.AsRef<uint>(&NativePtr->Colored);
public ref uint Visible => ref Unsafe.AsRef<uint>(&NativePtr->Visible);
public ref uint Codepoint => ref Unsafe.AsRef<uint>(&NativePtr->Codepoint);
*/
//Begin Fix
public bool Colored => (NativePtr->Packed & 1) == 1;
public bool Visible => ((NativePtr->Packed >> 1) & 1) == 1;
public uint Codepoint => NativePtr->Packed >> 2;
//End Fix
public ref float AdvanceX => ref Unsafe.AsRef<float>(&NativePtr->AdvanceX);
public ref float X0 => ref Unsafe.AsRef<float>(&NativePtr->X0);
public ref float Y0 => ref Unsafe.AsRef<float>(&NativePtr->Y0);
public ref float X1 => ref Unsafe.AsRef<float>(&NativePtr->X1);
public ref float Y1 => ref Unsafe.AsRef<float>(&NativePtr->Y1);
public ref float U0 => ref Unsafe.AsRef<float>(&NativePtr->U0);
public ref float V0 => ref Unsafe.AsRef<float>(&NativePtr->V0);
public ref float U1 => ref Unsafe.AsRef<float>(&NativePtr->U1);
public ref float V1 => ref Unsafe.AsRef<float>(&NativePtr->V1);
}
}
I believe it would be fixed by this: https://github.com/mellinoe/ImGui.NET/pull/245
I posted the following issue on the dear imgui repo: https://github.com/ocornut/imgui/issues/5020
As ocornut points out...
I'm not really sure to fix this in imgui.net so I'm not sure how to create a pull request.