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

[Renderers/IMGUI] Create minimal ImDrawList example #97

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

THISISAGOODNAME
Copy link

Inspired by #69

@nicbarker
Copy link
Owner

This is a super cool idea and I will check it out, but just as a heads up I think we'll likely clone in imgui & sokol rather than include them inside the repo 👍

@nicbarker nicbarker changed the title Create minimal ImDrawList example [Renderers/IMGUI] Create minimal ImDrawList example Dec 25, 2024
@nicbarker
Copy link
Owner

I just had a look at this and unfortunately I can't get it to compile on my mac out of the box, will try again tomorrow 🙂

@THISISAGOODNAME
Copy link
Author

@nicbarker Sorry, I forgot to link cocoa and openGL on mac platform. Updated.

@nicbarker nicbarker force-pushed the main branch 2 times, most recently from 4fd677e to 338852b Compare January 14, 2025 08:46
@nicbarker
Copy link
Owner

Hey @THISISAGOODNAME, I just updated to latest and there's something odd going on with clang & cmake on mac. I'm getting errors along the lines of unknown type name 'NSString' from sokol - I suspect it's attempting to import the obj-c headers as C/C++. I'll have another look at this when I have time 🙂

@illusion0001
Copy link

Found a few things needed for new api to compile.

  • Clay_Arena doesn't have label anymore, so Clay_CreateArenaWithCapacityAndMemory is preferred instead (taken from example).
  • measureText callback needed userdata param (I provided 0 here).
Clay_Dimensions measureText(Clay_StringSlice text, Clay_TextElementConfig* config, uintptr_t userData)
{
    ImVec2 size = ImGui::CalcTextSize(text.chars, nullptr);
    return (Clay_Dimensions)
    {
        .width = size.x,
        .height = size.y,
    };
}
void initClay()
{
    uint64_t totalMemorySize = Clay_MinMemorySize();
    Clay_Arena clayMemory = Clay_CreateArenaWithCapacityAndMemory(totalMemorySize, (char*)malloc(totalMemorySize));
    Clay_Initialize(clayMemory, Clay_Dimensions{
        1280, 720 }, Clay_ErrorHandler{ HandleClayErrors });
    Clay_SetMeasureTextFunction(measureText, 0);
    Clay_Initialize(clayMemory, (Clay_Dimensions)
    {
        1280, 720
    }, { errorCallback, 0 });
}

Optionally, you can use GetForegroundDrawList to avoid imgui creating a window for it. (p should be 0 so it starts at top left!

void render(Clay_RenderCommandArray renderCommands)
{
    ImDrawList* draw_list = ImGui::GetForegroundDrawList();
    // start from 0,0
    static ImVec2 p = {};
    //...
}

image

@illusion0001
Copy link

illusion0001 commented Jan 31, 2025

Here is demo document rendered using this PR and adjustments from this file https://github.com/KosmosisDire/VoxyEnginePlus/blob/8665459f1c394a299e6144af4e9e180f9faebcb7/app-framework/src/clayui/elements/helper/clay-imgui-renderer.hpp
for mouse, you may use ImGui IO for it.

    ImGuiIO& io = ImGui::GetIO();
    ImVec2 mousePosition = io.MousePos;
    ImVec2 scrollDelta = { io.MouseWheel ,io.MouseWheel };

image
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants