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

Drawing one widget over others widgets ? #1236

Closed
itamago opened this issue Jul 18, 2017 · 3 comments
Closed

Drawing one widget over others widgets ? #1236

itamago opened this issue Jul 18, 2017 · 3 comments

Comments

@itamago
Copy link

itamago commented Jul 18, 2017

Hello,

I may have a strange question which is not very easy to explain with a classic usecase :

  • I would like to draw several widgets in a ChildWindow, let's say 1 combo + 1 dragint.
  • And I would like to draw a BIG text over the whole ChildWindow, covering the combo and the dragint.

How do you correctly reset the cursor position as if the combo and the dragint were not drawn ?
Are there some side-effects, like the combo+dragint will not contribute to extend the ChildWindow's size ?

Thanks for your help

@ocornut
Copy link
Owner

ocornut commented Jul 18, 2017

Hello Pacome,
I am not sure I understand your problem exactly.

  • Would you like the Combo/DragInt to ignore inputs when the "Big Text" is displayed, or not?

I imagine what you are trying to do is display a big "DISABLED" thingie and block other inputs? Also see #211. Right now in your situation the simplest/dumb way to disable all inputs would be to draw a big InvisibleButton FIRST in the child window that would steal the inputs from the subsequent widgets. That is, until we add widespread support for #211.

Currently ChildWindow never have automatic size so the contribution of the combo/dragint will only affect the scrollbar. Internally the variable that will lead to calculate the content size of a window is window->DC.CursorMaxPos, we more or less do CursorPosMax = Max(CursorPos, CursorMaxPos) in function such as ItemSize() (it's expressed in a different way in that function but that's the idea).

@itamago
Copy link
Author

itamago commented Jul 18, 2017

Exact, I would like to display something like "Disabled".
Understood, I will try that today. Thanks !!

@itamago itamago closed this as completed Jul 18, 2017
@itamago
Copy link
Author

itamago commented Jul 18, 2017

For those who are interested in disabling the content of a ChildWindow, here is some code to be modified but giving a rough idea of how to do it :

ImVec2	g_disableChildCursorPos;
ImVec2	g_disableChildTotalSize;

void DisableChildBegin()
{
	g_disableChildCursorPos = ImGui::GetCurrentWindow()->DC.CursorPos;
	g_disableChildTotalSize = ImGui::GetContentRegionAvail();
	ImGui::InvisibleButton("disableID", g_disableChildTotalSize);
	ImGui::GetCurrentWindow()->DC.CursorPos = g_disableChildCursorPos;
}

void DisableChildEnd(const ImColor & colorBg, const ImColor & colorText, const char* text)
{
	ImGui::GetCurrentWindow()->DC.CursorPos = m_disableChildCursorPos;
	ImGui::PushStyleColor(ImGuiCol_Text, colorBg);
	ImGui::TextWithBackground(ImGuiAlign_Center | ImGuiAlign_VCenter, g_disableChildTotalSize, colorText, false, "%s", text);
	ImGui::PopStyleColor();
}

And an example of usage :

ImGui::BeginChild("Test", ImVec2(graphWidth, graphHeight), true);
DisableChildBegin();
ImGui::Combo(...);
ImGui::DragInt(...);
DisableChildEnd(colorBg, colorText, "Disabled");
ImGui::EndChild();

Implementation of ImGui::TextWithBackground is missing, but you can easily guess what it does :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants