0

It just dawned on me that with ImGui

if(CollapsingHeader("MyHeader"))
{
    if(Button("B"))
    {
      // Do stuff
    }
}

Results in a different rendering than:

if(CollapsingHeader("MyHeader"))
{
}
if(Button("B"))
{
      // Do stuff
}

With the first the button is nested in the header, with the second it is outside the header. How on earth can ImGui tell that in the first version the button function is nested within the if but that in the second it isn't?

Makogan
  • 8,208
  • 7
  • 44
  • 112
  • 1
    This has nothing to do with the library you use, and everything to do with the C++ language syntax. The first fragment calls `Button("B")` only if `CollapsingHeader("MyHeader")` returns `true`, and runs `Do stuff` only if both return `true`. The second fragment ignores the result of `CollapsingHeader("MyHeader")`, and runs `Do stuff` if `Button("B")` returns `true`, regardless of what `CollapsingHeader("MyHeader")` returns. These are two different programs doing two different things. – Igor Tandetnik Nov 25 '20 at 23:43
  • I am an idiot, you are right. I have been programming for too long today. – Makogan Nov 25 '20 at 23:50

0 Answers0