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

Imgui test engine cant find BeginChildEx because of '/' #68

Open
MajorPainTheCactus opened this issue Jan 29, 2025 · 3 comments
Open

Imgui test engine cant find BeginChildEx because of '/' #68

MajorPainTheCactus opened this issue Jan 29, 2025 · 3 comments

Comments

@MajorPainTheCactus
Copy link

BeginChildEx cant be found because the child window name contains a '/'. If I change these lines in BegindChildEx:

    if (name)
        ImFormatStringToTempBuffer(&temp_window_name, NULL, "%s/%s_%08X", parent_window->Name, name, id);
    else
        ImFormatStringToTempBuffer(&temp_window_name, NULL, "%/%08X", parent_window->Name, id);

to

    if (name)
        ImFormatStringToTempBuffer(&temp_window_name, NULL, "%s_%s_%08X", parent_window->Name, name, id);
    else
        ImFormatStringToTempBuffer(&temp_window_name, NULL, "%s_%08X", parent_window->Name, id);

i.e replace the slash with an underscore then ImGuiTestContext::ItemInfo can find the child window and doesn't chop off the name_id part.

ImGuiTestItemInfo ImGuiTestContext::ItemInfo(ImGuiTestRef ref, ImGuiTestOpFlags flags)

This is important for scrolling as otherwise items off screen in child windows can't be found as the current work around of serarching via **/name doesn't work.

This has allowed me to do this to scroll the item onto screen in the test framework:

		ImGuiWindow* window = ImGui::FindWindowByName(file_dialog);

		constexpr const char* child = "##files";

		ImGuiID id = window->GetID(child);

		std::string  child_name = std::format("{}_{}_{:08X}", file_dialog, child, id);

		ctx.SetRef(child_name.c_str());

		ctx.ScrollToItemY(std::format("##folder_{}", folder).c_str());

There is also a line in
ImGuiTestItemInfo ImGuiTestContext::WindowInfo(ImGuiTestRef ref, ImGuiTestOpFlags flags)
that needs to be changed here:

                ImGuiID child_window_id = 0;
                ImGuiWindow* child_window = NULL;
                {
                    // Child: Attempt 1: Try to BeginChild(const char*) variant and mimic its logic.
                    Str128 child_window_full_name;
#if (IMGUI_VERSION_NUM >= 18996) && (IMGUI_VERSION_NUM < 18999)
                    if (window_idstack_back == window->ID)
                    {
                        child_window_full_name.setf("%s/%s", window->Name, part_name.c_str());
                    }
                    else
#endif
                    {
                        ImGuiID child_item_id = GetID(part_name.c_str(), window_idstack_back);
****                        child_window_full_name.setf("%s_%s_%08X", window->Name, part_name.c_str(), child_item_id);  ****
@ocornut
Copy link
Owner

ocornut commented Jan 29, 2025

I would like to change the mangling of child windows indeed.

However,

This has allowed me to do this to scroll the item onto screen in the test framework:

ImGuiWindow* window = ImGui::FindWindowByName(file_dialog);
constexpr const char* child = "##files";
ImGuiID id = window->GetID(child);
std::string  child_name = std::format("{}_{}_{:08X}", file_dialog, child, id);
ctx.SetRef(child_name.c_str());
ctx.ScrollToItemY(std::format("##folder_{}", folder).c_str());

You should be able to use, e.g.

ctx->SetRef(ctx->WindowInfo("//FileDialog/##files")->Window);
ctx->ScrollToItemY(....);

@MajorPainTheCactus
Copy link
Author

Oh ok so that will presumably add the hash at the end of //FileDialog/##files ? Great to know I'll try it out. Thanks

@ocornut
Copy link
Owner

ocornut commented Jan 30, 2025

Yes, WindowInfo() is designed to handling mangling of child window names.
But I still intend to find a way to redesign this.

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

No branches or pull requests

2 participants