Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] BeginTabItem missing possibility to set Flags without open/close ref bool. #34

Open
CaptainTimberTim opened this issue Mar 24, 2022 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@CaptainTimberTim
Copy link

Hi,
I just had the problem that the BeginTabItem cannot be called easily with flags enabled, if you don't want the open/close tab feature.
In the C version of ImGui this can be done by passing a nullpointer as the p_open param. But as C# does not allow this in normal code (as far as I know?), there would need to be an additional overload without the "ref bool p_open" param.

For me I now solved this by copying the generated implementation of the imguiNET and changing it by just passing null.

public static bool BeginTabItem(string label, ImGuiTabItemFlags flags)
{
    byte* native_label;
    int label_byteCount = 0;
    if (label != null)
    {
        label_byteCount = Encoding.UTF8.GetByteCount(label);
        if (label_byteCount > 2048)
        {
            native_label = (byte*)Marshal.AllocHGlobal(label_byteCount + 1);
        }
        else
        {
            byte* native_label_stackBytes = stackalloc byte[label_byteCount + 1];
            native_label = native_label_stackBytes;
        }
        int native_label_offset = GetUtf8(label, native_label, label_byteCount);
        native_label[native_label_offset] = 0;
    }
    else { native_label = null; }
    byte ret = ImGuiNative.igBeginTabItem(native_label, null, flags);
    if (label_byteCount > 2048)
    {
        Marshal.FreeHGlobal((IntPtr)native_label);
    }
    return ret != 0;
}

private static int GetUtf8(string s, byte* utf8Bytes, int utf8ByteCount)
{
    fixed (char* utf16Ptr = s)
    {
        return Encoding.UTF8.GetBytes(utf16Ptr, s.Length, utf8Bytes, utf8ByteCount);
    }
}
@CaptainTimberTim CaptainTimberTim added the bug Something isn't working label Mar 24, 2022
@psydack
Copy link
Owner

psydack commented Mar 27, 2022

Hello there.

This is awesome.

If you want to make a merge request in our custom ImGui.Net project , I would really appreciate.

Edit: I will use that to remember to change the code generator.

Thank you.

@psydack psydack added enhancement New feature or request and removed bug Something isn't working labels Apr 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants