imgui-sfml icon indicating copy to clipboard operation
imgui-sfml copied to clipboard

viewport support

Open vprimachenko opened this issue 5 years ago • 19 comments

consider adding support for the upcoming viewports feature of ImGui

vprimachenko avatar Jan 02 '19 19:01 vprimachenko

Sure! I knew about this for a while, but I didn't want to work on it, because it's not in a release yet, so I'd have to constantly keep up to date and fix every breaking change, which is a bit difficult.

If you want, I can try to make it work in the state that viewports are now in ImGui in experimental branch, but if you can wait until it's in one of ImGui's releases + some additional time it will take me to implement (PRs are welcome, if you really need it :D), I'l try to implement it later.

eliasdaler avatar Jan 02 '19 23:01 eliasdaler

I tried that a few weeks ago and it wasn't that difficult. The biggest problem was to get the position of the render area relative to the desktop (main window only) without the window decoration.

gotocoffee1 avatar Jan 09 '19 17:01 gotocoffee1

@gotocoffee1 Do you have the code publicly available? I'd be interested in using this feature

eric556 avatar Jun 21 '19 04:06 eric556

@eric556 Not right now but I will look into this again and maybe do a pull request.

gotocoffee1 avatar Jun 25 '19 06:06 gotocoffee1

So I looked into the sample ports again and it seems that the platform has to be able to handle multiple monitors (right @ocornut ?), which is not supported by SFML.

gotocoffee1 avatar Jul 07 '19 12:07 gotocoffee1

You need to be able to create multiple windows and share the graphics context. Multiple monitor support is only a product of that. If sfml doesn’t naturally support that you could perfectly use a separate backend for the secondary windows.

ocornut avatar Jul 07 '19 13:07 ocornut

Hi, does anyone have an implementation of this publicly available?

FelipeCarlin avatar Jan 11 '20 19:01 FelipeCarlin

In my project I'm using imgui from docking branch with sfml. Docking functionality works, but i'm not able to create new windows. So im also waiting for this feature within imgui-SFML :-)

SebastianMilosz avatar Aug 19 '20 08:08 SebastianMilosz

Something new about implementing the viewports?

CosminPerRam avatar Jun 01 '22 09:06 CosminPerRam

I'm still not sure if I need to do anything on ImGui-SFML's side since you can have multiple ImGui contexts now and ImGui-SFML supports it.

eliasdaler avatar Jun 03 '22 15:06 eliasdaler

I tried but it doesnt work, thats why i dropped a comment here, can you give it a go?

CosminPerRam avatar Jun 04 '22 09:06 CosminPerRam

Can you please describe what doesn't work? I don't have the time to try it out soon myself, unfortunately.

eliasdaler avatar Jun 04 '22 22:06 eliasdaler

Sorry for not leaving an example straight up, here it is:

So I'm just taking the simple example from here and modifying it for multi viewports (as said here (at How can I enable Multi-viewports ?)), here is the resulting code:

#include "imgui.h" // necessary for ImGui::*, imgui-SFML.h doesn't include imgui.h

#include "imgui-SFML.h" // for ImGui::SFML::* functions and SFML-specific overloads

#include <SFML/Graphics/CircleShape.hpp>
#include <SFML/Graphics/RenderWindow.hpp>
#include <SFML/System/Clock.hpp>
#include <SFML/Window/Event.hpp>
#include <iostream>

int main() {
    sf::RenderWindow window(sf::VideoMode(640, 480), "ImGui + SFML = <3");
    window.setFramerateLimit(60);
    ImGui::SFML::Init(window);
    ImGui::GetIO().ConfigFlags |= ImGuiConfigFlags_ViewportsEnable; //added this! ---

    sf::CircleShape shape(100.f);
    shape.setFillColor(sf::Color::Green);

    sf::Clock deltaClock;
    while (window.isOpen()) {
        sf::Event event;
        while (window.pollEvent(event)) {
            ImGui::SFML::ProcessEvent(window, event);

            if (event.type == sf::Event::Closed) {
                window.close();
            }
        }

        ImGui::SFML::Update(window, deltaClock.restart());

        ImGui::ShowDemoWindow();

        ImGui::Begin("Hello, world!");
        ImGui::Button("Look at this pretty button");
        ImGui::End();

        window.clear();
        window.draw(shape);
        ImGui::SFML::Render(window);

        std::cout << (ImGui::GetIO().ConfigFlags & ImGuiConfigFlags_ViewportsEnable) << std::endl;

        if (ImGui::GetIO().ConfigFlags & ImGuiConfigFlags_ViewportsEnable) //added this! ---
        {
            ImGui::UpdatePlatformWindows();
            ImGui::RenderPlatformWindowsDefault();
        }

        window.display();
    }

    ImGui::SFML::Shutdown();

    return 0;
}

And i would be able to get the imgui windows outside of the main sfml window but i cant. image

Also, ImGui::GetIO().ConfigFlags & ImGuiConfigFlags_ViewportsEnable returns 0 and I see that the comment for ImGuiConfigFlags_ViewportsEnable says: image

Edit: I added those flags in imgui-SFML.cpp and now i get: image

CosminPerRam avatar Jun 05 '22 12:06 CosminPerRam

Yeah, now I see that it requires some additional coding which seems not very trivial... https://github.com/ocornut/imgui/blob/docking/backends/imgui_impl_sdl.cpp#L341 https://github.com/ocornut/imgui/blob/docking/backends/imgui_impl_sdl.cpp#L697

At best I could be able to start researching this next month... so if someone has more time and wants to implement this, I'd be more than happy to accept the PR. :)

eliasdaler avatar Jun 05 '22 21:06 eliasdaler

~~I'm no way this advanced, but I'll give it a go~~, thanks for reaching out for this.

CosminPerRam avatar Jun 05 '22 21:06 CosminPerRam

@eliasdaler were you able to start it?

ignotion avatar Dec 09 '22 15:12 ignotion

@ignotion, there's this PR: https://github.com/eliasdaler/imgui-sfml/pull/213 However, it needs testing (I wasn't able to do it, unfortunately)

eliasdaler avatar Dec 09 '22 16:12 eliasdaler

Hey is this feature going to be released?, I would be a huge addition to the library, supporting viewports.

PanAMD avatar Nov 07 '23 03:11 PanAMD