Imgui: make ImGui window dynamically fit glfw window

Created on 6 Dec 2016  Â·  5Comments  Â·  Source: ocornut/imgui

Hi,

Is it possible to make ImGui windows fit e.g the "glfwCreateWindow", and adjust accordingly when the latter window is resized?

Regards,

p.

Most helpful comment

Agreed. This is not directly related to ImGui.
If someone else needs this functionality, here is how I was able to get the C-style glfw callback to trigger my member function (and resize accordingly with ImGui::SetNextWindowSize.)

gui::init() {
    ....
    glfwSetWindowUserPointer(window_, this);
    glfwSetWindowSizeCallback(window_, resize_callback);
    ....
}

void resize_callback(GLFWwindow * window, int width, int height)
{
    auto g = static_cast<gui *>(glfwGetWindowUserPointer(window));
    g->window_resize(width, height);
}

All 5 comments

Call SetNextWindowPos() and SetNextWindowSize() every frame before creating your imgui window.

On 6 Dec 2016, at 07:35, Petter Wahlman notifications@github.com wrote:

Hi,

Is it possible to make ImGui windows fit e.g the "glfwCreateWindow", and adjust accordingly when the latter window is resized?

Regards,

p.

―
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or mute the thread.

Wow, quick response!

Very impressive, thank you!

I am still unsure what values to put in SetNextWindowSize(), as GetWindowWidth et al. does not seem to reflect the GL window width (and does not change when I resize this window).

ImGui::GetWindowWidth() retrieve the width of the current ImGui window that was Begin-ed into.

Retrieving your GL window size is out of the scope of ImGui. See your glfw documentation.

Agreed. This is not directly related to ImGui.
If someone else needs this functionality, here is how I was able to get the C-style glfw callback to trigger my member function (and resize accordingly with ImGui::SetNextWindowSize.)

gui::init() {
    ....
    glfwSetWindowUserPointer(window_, this);
    glfwSetWindowSizeCallback(window_, resize_callback);
    ....
}

void resize_callback(GLFWwindow * window, int width, int height)
{
    auto g = static_cast<gui *>(glfwGetWindowUserPointer(window));
    g->window_resize(width, height);
}
Was this page helpful?
0 / 5 - 0 ratings

Related issues

namuda picture namuda  Â·  3Comments

bogdaNNNN1 picture bogdaNNNN1  Â·  3Comments

Folling picture Folling  Â·  3Comments

inflex picture inflex  Â·  3Comments

BlackWatersInc picture BlackWatersInc  Â·  3Comments