Separators don't stay inside columns #759

Closed
opened 2016-08-01 00:37:57 +00:00 by forrestthewoods · 10 comments
forrestthewoods commented 2016-08-01 00:37:57 +00:00 (Migrated from github.com)

I have two columns with stuff. In the second column I call ImGui::Separator(). I expect this separator to be contained strictly within the second column. It shouldn't go inside column one at all. However it cuts across the whole child.

image

Sample code:

ImGui::Begin("column test");
ImGui::Columns(2);
ImGui::Text("column 1");
ImGui::Text("foo");
ImGui::Text("bar");
ImGui::Text("baz");
ImGui::NextColumn();
ImGui::Text("Column 2 - high");
ImGui::Separator();
ImGui::Text("Column 2 - low");
ImGui::End();
I have two columns with stuff. In the second column I call `ImGui::Separator()`. I expect this separator to be contained strictly within the second column. It shouldn't go inside column one at all. However it cuts across the whole child. ![image](https://cloud.githubusercontent.com/assets/8474974/17280458/469b7b3c-5745-11e6-8fd5-74bb7fe383d2.png) Sample code: ``` ImGui::Begin("column test"); ImGui::Columns(2); ImGui::Text("column 1"); ImGui::Text("foo"); ImGui::Text("bar"); ImGui::Text("baz"); ImGui::NextColumn(); ImGui::Text("Column 2 - high"); ImGui::Separator(); ImGui::Text("Column 2 - low"); ImGui::End(); ```
ocornut commented 2016-08-01 06:36:31 +00:00 (Migrated from github.com)

Hi Forrest,

I don't have a good answer right now. Separator() needs to be improved with various options but I would like to wait until more serious work is done on the Columns api to change that together, and not just hastily add options to Separator. As you can see on the picture the borders are generally fugly/lacking here.

You can draw your own separator with, e.g.

ImDrawList*   draw_list = GetWindowDrawList();
ImVec2 p = GetCursorScreenPos();
draw_list->AddLine(ImVec2(p.x - 9999, p.y), ImVec2(p.x + 9999, p.y),  ImGui::GetColorU32(ImGuiCol_Border));

A clipping rectangle is active within the column so that would be enough.

Or just copy the code Separator() into your own version e.g. SeparatorEx(bool span_columns) (the source file will need to include imgui_internal.h) and comment out the lines doing the PopClipRect()/PushColumnClipRect() or test with a boolean.

Loosely related to #697, #513, #205

Hi Forrest, I don't have a good answer right now. Separator() needs to be improved with various options but I would like to wait until more serious work is done on the Columns api to change that together, and not just hastily add options to Separator. As you can see on the picture the borders are generally fugly/lacking here. You can draw your own separator with, e.g. ``` ImDrawList* draw_list = GetWindowDrawList(); ImVec2 p = GetCursorScreenPos(); draw_list->AddLine(ImVec2(p.x - 9999, p.y), ImVec2(p.x + 9999, p.y), ImGui::GetColorU32(ImGuiCol_Border)); ``` A clipping rectangle is active within the column so that would be enough. Or just copy the code Separator() into your own version e.g. SeparatorEx(bool span_columns) (the source file will need to include `imgui_internal.h`) and comment out the lines doing the PopClipRect()/PushColumnClipRect() or test with a boolean. Loosely related to #697, #513, #205
forrestthewoods commented 2016-08-06 06:04:40 +00:00 (Migrated from github.com)

ImGui::GetColorU32 is declared in imgui.h. And it's declared/implemented as an inline function in imgui_internal.h.

My VS2015 project compiles in debug but fails to link in release. Which is kinda super weird. If I comment out the imgui.h declarations (which have no matching implementation) both debug and release fail. The imgui.h declaration has default parameter float alpha_mul = 1.0f which the internal version does not.

The debug version is somehow calling the inlined internal function with the default parameter of the declared from the non-internal? Wat? O_o

Commenting out the imgui.h version causes imgui to not compile. As neither of the two overloads match any of the calls. Then adding the default parameter to the internal declaration and it compiles as you'd expect. Minus the function not being exposed to external code.

So.... should GetColorU32 be implemented inlined with a default parameter in imgui.h? That fixes everything. But this whole tale was so weird I wanted to spell it out.

ImGui::GetColorU32 is declared in imgui.h. And it's declared/implemented as an inline function in imgui_internal.h. My VS2015 project compiles in debug but fails to link in release. Which is kinda super weird. If I comment out the imgui.h declarations (which have no matching implementation) both debug and release fail. The imgui.h declaration has default parameter `float alpha_mul = 1.0f` which the internal version does not. The debug version is somehow calling the inlined internal function with the default parameter of the declared from the non-internal? [Wat](https://www.destroyallsoftware.com/talks/wat)? O_o Commenting out the imgui.h version causes imgui to not compile. As neither of the two overloads match any of the calls. Then adding the default parameter to the internal declaration and it compiles as you'd expect. Minus the function not being exposed to external code. So.... should GetColorU32 be implemented inlined with a default parameter in imgui.h? That fixes everything. But this whole tale was so weird I wanted to spell it out.
ocornut commented 2016-08-06 07:08:54 +00:00 (Migrated from github.com)

Sorry this is indeed a messed, weird tale. Lots of the color related code has been in need of work.
They are the same functions, but it's illegal to declare the default value a second time. I get this with VS2010:
Error 1 error C2572: 'ImGui::GetColorU32' : redefinition of default parameter : parameter 2 imgui_internal.h 706
And you tell me it works with 2015 but we are in dangerous territory.

It was shuffled this way to ensure it was kept inline for internal code. First time I hear of a compiler not liking it. Looking into it now.

Sorry this is indeed a messed, weird tale. Lots of the color related code has been in need of work. They are the same functions, but it's illegal to declare the default value a second time. I get this with VS2010: `Error 1 error C2572: 'ImGui::GetColorU32' : redefinition of default parameter : parameter 2 imgui_internal.h 706` And you tell me it works with 2015 but we are in dangerous territory. It was shuffled this way to ensure it was kept inline for internal code. First time I hear of a compiler not liking it. Looking into it now.
ocornut commented 2016-08-06 07:23:39 +00:00 (Migrated from github.com)

Let me know if the last commit fixes it. Sorry! (Also, I've been meaning to remove that conversion anyway so the code taking the enum will end pulling values from an u32 array eventually. )

Let me know if the last commit fixes it. Sorry! (Also, I've been meaning to remove that conversion anyway so the code taking the enum will end pulling values from an u32 array eventually. )
forrestthewoods commented 2016-08-06 21:16:42 +00:00 (Migrated from github.com)

Fixed!

Fixed!
djdeath commented 2017-11-23 00:44:01 +00:00 (Migrated from github.com)

Sorry to pile on this bug, I was trying to use columns and separators and they don't seem to mix well :)
columns

This is the code I wrote to generate this :

if (ImGui::CollapsingHeader("Test"))               
{                                                  
    ImGui::Columns(3);                             
    ImGui::Text("Column1");                        
    ImGui::Separator();                            
    ImGui::Text("content");                        
                                                   
    ImGui::NextColumn();                           
    ImGui::Text("Column2");                        
    ImGui::Separator();                            
    ImGui::Text("content");                        
                                                   
    ImGui::NextColumn();                           
    ImGui::Text("Column3");                        
    ImGui::Separator();                            
    ImGui::Text("content");                        
                                                   
    ImGui::NextColumn();                           
}

I'm not sure whether that's expected, or just a result of the current state of columns.
Just documenting the issue (not urgently in need of a fix).

Sorry to pile on this bug, I was trying to use columns and separators and they don't seem to mix well :) ![columns](https://user-images.githubusercontent.com/434333/33155284-380680d2-cfe7-11e7-8291-bf68ff8d091f.png) This is the code I wrote to generate this : ``` if (ImGui::CollapsingHeader("Test")) { ImGui::Columns(3); ImGui::Text("Column1"); ImGui::Separator(); ImGui::Text("content"); ImGui::NextColumn(); ImGui::Text("Column2"); ImGui::Separator(); ImGui::Text("content"); ImGui::NextColumn(); ImGui::Text("Column3"); ImGui::Separator(); ImGui::Text("content"); ImGui::NextColumn(); } ``` I'm not sure whether that's expected, or just a result of the current state of columns. Just documenting the issue (not urgently in need of a fix).
djdeath commented 2017-11-23 00:51:26 +00:00 (Migrated from github.com)

Actually this produce a more sensible result :

if (ImGui::CollapsingHeader("Test")) 
{                                    
    ImGui::BeginChild("##top");      
                                     
    ImGui::Columns(3);               
    ImGui::BeginChild("##1");        
    ImGui::Text("Column1");          
    ImGui::Separator();              
    ImGui::Text("content");          
    ImGui::EndChild();               
                                     
    ImGui::NextColumn();             
    ImGui::BeginChild("##2");        
    ImGui::Text("Column2");          
    ImGui::Separator();              
    ImGui::Text("content");          
    ImGui::EndChild();               
                                     
    ImGui::NextColumn();             
    ImGui::BeginChild("##3");        
    ImGui::Text("Column3");          
    ImGui::Separator();              
    ImGui::Text("content");          
    ImGui::EndChild();               
                                     
    ImGui::EndChild();               
}                                    

But then the height of one of the child interacts weirdly with the CollapsingHeader (admittedly I don't care much for my use case).

Actually this produce a more sensible result : ``` if (ImGui::CollapsingHeader("Test")) { ImGui::BeginChild("##top"); ImGui::Columns(3); ImGui::BeginChild("##1"); ImGui::Text("Column1"); ImGui::Separator(); ImGui::Text("content"); ImGui::EndChild(); ImGui::NextColumn(); ImGui::BeginChild("##2"); ImGui::Text("Column2"); ImGui::Separator(); ImGui::Text("content"); ImGui::EndChild(); ImGui::NextColumn(); ImGui::BeginChild("##3"); ImGui::Text("Column3"); ImGui::Separator(); ImGui::Text("content"); ImGui::EndChild(); ImGui::EndChild(); } ``` But then the height of one of the child interacts weirdly with the CollapsingHeader (admittedly I don't care much for my use case).
ocornut commented 2017-11-23 15:01:06 +00:00 (Migrated from github.com)

That'll work but using BeginChild() for individual items is quite slow.
If you do it like the code in the demo window it'll also work:

ImGui::Columns(4, "mycolumns");
ImGui::Separator();
ImGui::Text("ID"); ImGui::NextColumn();
ImGui::Text("Name"); ImGui::NextColumn();
ImGui::Text("Path"); ImGui::NextColumn();
ImGui::Text("Hovered"); ImGui::NextColumn();
ImGui::Separator();
That'll work but using `BeginChild()` for individual items is quite slow. If you do it like the code in the demo window it'll also work: ``` ImGui::Columns(4, "mycolumns"); ImGui::Separator(); ImGui::Text("ID"); ImGui::NextColumn(); ImGui::Text("Name"); ImGui::NextColumn(); ImGui::Text("Path"); ImGui::NextColumn(); ImGui::Text("Hovered"); ImGui::NextColumn(); ImGui::Separator(); ```
ocornut commented 2023-10-03 13:23:16 +00:00 (Migrated from github.com)

Thread necromancy: closing this as since 2019 you can technically call SeparatorEx() without the ImGuiSeparatorFlags_SpanAllColumns call to do it. Since we have since then largely phased Columns() there wasn't a necessity to expose this at higher-level in the API.

Thread necromancy: closing this as since 2019 you can technically call `SeparatorEx()` without the `ImGuiSeparatorFlags_SpanAllColumns` call to do it. Since we have since then largely phased `Columns()` there wasn't a necessity to expose this at higher-level in the API.
forrestthewoods commented 2023-10-04 05:48:18 +00:00 (Migrated from github.com)

whoa. blast from the past :)

whoa. blast from the past :)
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
ocornut/imgui#759
No description provided.