Open vprimachenko opened 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.
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 Do you have the code publicly available? I'd be interested in using this feature
@eric556 Not right now but I will look into this again and maybe do a pull request.
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.
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.
Hi, does anyone have an implementation of this publicly available?
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 :-)
Something new about implementing the viewports?
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.
I tried but it doesnt work, thats why i dropped a comment here, can you give it a go?
Can you please describe what doesn't work? I don't have the time to try it out soon myself, unfortunately.
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.
Also, ImGui::GetIO().ConfigFlags & ImGuiConfigFlags_ViewportsEnable
returns 0 and I see that the comment for ImGuiConfigFlags_ViewportsEnable
says:
Edit: I added those flags in imgui-SFML.cpp
and now i get:
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. :)
I'm no way this advanced, but I'll give it a go, thanks for reaching out for this.
@eliasdaler were you able to start it?
@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)
Hey is this feature going to be released?, I would be a huge addition to the library, supporting viewports.
5 years and nothing... Crazy.
consider adding support for the upcoming
viewports
feature of ImGui