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

how to render in background? #4588

Closed
gucio321 opened this issue Sep 27, 2021 · 4 comments
Closed

how to render in background? #4588

gucio321 opened this issue Sep 27, 2021 · 4 comments
Labels

Comments

@gucio321
Copy link

Version/Branch of Dear ImGui:

Version: master
Branch: master

Back-end/Renderer/Compiler/OS

Back-ends: imgui_impl_sdl.cpp + imgui_impl_opengl3.cpp
Operating System: Fedora 34

My Issue/Question:

Hi,
I'm going to measure widget width (#3714) and align it.
I'm able to do so rendering one widget two times with the following steps:

  • save cursor position
  • push temporaty ID
  • render widget (with 0 alpha)
  • save its size
  • pop id
  • set cursor position to x = (availableRegionW - itemWidth), y = start pos.Y
  • render widget

the problem is, that this first (invisible) widget is rendered in foreground?... and covers this second (visible).
The solution is to put the visible widget inside of Child.
my question is: is it possible to do it another way so that the second widget could be rendered in a normal way (without any other steps before)

Screenshots/Video

with steps above (without Push..Alpha to show both buttons):
image
when mouse over the common region of both buttons
image
with child (mouse over common region of two buttons)
image

Standalone, minimal, complete and verifiable example: (see #2261)

// Here's some code anyone can copy and paste to reproduce your issue
        {
            ImGui::Begin("Hello, world!");

            struct foo {
                    bool btn() { return ImGui::Button("btn",ImVec2{200,20}); };
            } btn;

            ImVec2 start = ImGui::GetCursorPos();
            ImVec2 size;

            ImGui::PushID("someotherid");
            ImGui::PushStyleVar(ImGuiStyleVar_Alpha, 0);
            if (btn.btn() ) {
                    std::cout << "btn 1 (invisible) pressed\n";
            };
            ImGui::PopStyleVar();
            ImGui::PopID();

            size = ImGui::GetItemRectSize();
            ImVec2 available = ImGui::GetContentRegionMax();
            start.x = (available.x-size.x)/2;
            ImGui::SetCursorPos(start);

            if (ImGui::BeginChild("container")) {
                if (btn.btn()){
                    std::cout << "btn 1 pressed\n";
                }
            }
            ImGui::EndChild();

            ImGui::End();
        }


@ocornut
Copy link
Owner

ocornut commented Sep 29, 2021

This scream like XY Problem please start by describing what you are trying to do in the first place.

It also doesn't make sense to do any of that if your button has a fixed size of (200,20) so your code is not adequately representing your problem. The solution is likely that you should be able to tell the compute of a widget yourself given they are pretty standardized.

@gucio321
Copy link
Author

@ocornut thanx for your reply!
I'm going to add a common method for aligning widgets (in fact for getting its widths).
I'm reffering to this comment: #3714 (comment)

@gucio321
Copy link
Author

well, so as I can read:

  • If there are other solutions you've already ruled out, share why you've ruled them out. This gives more information about your requirements.
  • just render widget with 0 alpha in default position, get its size, move cursor back, add dummy, render centered widget.
    the problem was, that the second widget (e.g. button) (both widgets has the same id) wasn't return true on user interaction. Instead, user was able to interact with this invisible widget
  • well, so lets try to PushID for this invisible widget, but now, it seems that the first widget convers the visible so that the visible one is unable to be interacted.

the solution I really need is to render my first widget behind other imgui widgets to be able to safely measure it.

@ocornut ocornut added the layout label Sep 30, 2021
@ocornut
Copy link
Owner

ocornut commented Sep 30, 2021

That's not really possible (other than output the "first" widget in a dummy window then hide the window...).
What we are missing a dummy layout mode where ItemSize() would record size and ItemAdd() always return false. This is desirable for many other features and we'll do it eventually (It's one of the last thing missing to allow #846 to be an independent extension).

@ocornut ocornut closed this as completed Nov 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants