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

Embedding a window as a ChildWindow #1800

Closed
phed opened this issue May 6, 2018 · 5 comments
Closed

Embedding a window as a ChildWindow #1800

phed opened this issue May 6, 2018 · 5 comments

Comments

@phed
Copy link

phed commented May 6, 2018

Is it possible to embed a window into another one?
I was happy to find that I could use child windows to create paned layouts, and that you could build on these windows with ::BeginChild(id) with the same ID later.
However, is there a way to embed a window that has been created with ::Begin(id) into a child-window in a similar manner? Reason is that I want to re-use code that creates regular windows..

Not very important, but I feel like there's a trick I am missing.

@ocornut
Copy link
Owner

ocornut commented May 6, 2018

The trick is to call BeginChild instead of Begin...?

@phed
Copy link
Author

phed commented May 6, 2018

As I said it is a minor thing. But the obvious thing would be to signal to the embedded window that it should call BeginChild instead of Child. The trick I was looking for is having the first instance, the embedder, making this decision. Anyway, I am now settling on just adding a boolean to the arguments of the window-functions , like hexeditor(id, ..., show, child) now.

@ocornut
Copy link
Owner

ocornut commented May 6, 2018 via email

@ocornut
Copy link
Owner

ocornut commented Jul 1, 2018

@phed: are you happy with this, can we close the thread or it is still an open topic for you?
Thanks.

@phed
Copy link
Author

phed commented Jul 4, 2018

Oh sorry, I was happy with the answer. Just close.
For completeness sake, I'll include the code that I am using project-wide to handle all sorts of window-cases. I do not really suggest anyone use this, but I am happy with it.

namespace ImGuiExt {
    enum ImGuiExtWindowMode {
        ImGuiExtWindowMode_Invalid,
        ImGuiExtWindowMode_Window,
        ImGuiExtWindowMode_ChildWindow,
        ImGuiExtWindowMode_Flat,
        ImGuiExtWindowMode_Fullscreen,
    };

    ImGuiExtWindowMode last_mode = ImGuiExtWindowMode_Invalid;

    bool Begin(const char* name, ImGuiExtWindowMode mode, bool *open = 0) {
        bool res = false;
        //const ImGuiWindowFlags background_flags = ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoBringToFrontOnFocus | ImGuiWindowFlags_NoResize;
        const ImGuiWindowFlags fullscreen_flags = ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_Modal;

        assert(last_mode == ImGuiExtWindowMode_Invalid);
        switch (mode) {
        case ImGuiExtWindowMode_Window:
            res = ImGui::Begin(name, open);
            break;
        case ImGuiExtWindowMode_ChildWindow:
            res = ImGui::BeginChild(name);
            break;
        case ImGuiExtWindowMode_Flat:
            break;
        case ImGuiExtWindowMode_Fullscreen:
            ImGui::SetNextWindowSize(ImGui::GetIO().DisplaySize);
            ImGui::SetNextWindowPos(ImVec2(0, 0));
            res = ImGui::Begin(name, 0, fullscreen_flags);
            break;
        default:
            assert(0);
        }
        last_mode = mode;
        return res;
    }
    void End() {
        switch (last_mode) {
        case ImGuiExtWindowMode_Fullscreen:
        case ImGuiExtWindowMode_Window:
            ImGui::End();
            break;
        case ImGuiExtWindowMode_ChildWindow:
            ImGui::EndChild();
            break;
        case ImGuiExtWindowMode_Flat:
            break;
        default:
            assert(0);
        }
        last_mode = ImGuiExtWindowMode_Invalid;
    }
}

@phed phed closed this as completed Jul 6, 2018
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

No branches or pull requests

2 participants