SFML / imgui-sfml

Dear ImGui backend for use with SFML
MIT License
1.13k stars 171 forks source link

viewport support #72

Open vprimachenko opened 5 years ago

vprimachenko commented 5 years ago

consider adding support for the upcoming viewports feature of ImGui

eliasdaler commented 5 years ago

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.

gotocoffee1 commented 5 years ago

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.

eric556 commented 5 years ago

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

gotocoffee1 commented 5 years ago

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

gotocoffee1 commented 5 years ago

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.

ocornut commented 5 years ago

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.

FelipeCarlin commented 4 years ago

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

SebastianMilosz commented 4 years ago

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 :-)

CosminPerRam commented 2 years ago

Something new about implementing the viewports?

eliasdaler commented 2 years ago

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.

CosminPerRam commented 2 years ago

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

eliasdaler commented 2 years ago

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

CosminPerRam commented 2 years ago

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

eliasdaler commented 2 years ago

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. :)

CosminPerRam commented 2 years ago

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

ignotion commented 1 year ago

@eliasdaler were you able to start it?

eliasdaler commented 1 year ago

@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)

PanAMD commented 11 months ago

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

anthony-sv commented 6 months ago

5 years and nothing... Crazy.