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

BeginMenu with columns #1149

Closed
q-depot opened this issue May 19, 2017 · 2 comments
Closed

BeginMenu with columns #1149

q-depot opened this issue May 19, 2017 · 2 comments

Comments

@q-depot
Copy link

q-depot commented May 19, 2017

Hi,

The columns don't seem to be working inside a menu, I reckon there is an issue with the resize so the content is clipped, If I use the border when I drag the handle it jumps.

if( ui::BeginMenu( "Endpoints" ) )
{
    if (ImGui::BeginMenu("New Endpoint"))
    {
        ImGui::Text( "Create Endpoint" );
        ImGui::Button("create");
        ImGui::EndMenu();
    }
	ImGui::Columns(4, "endpoints-view", false);
	ImGui::Separator();

	ImGui::Text( "Protocol" );	ImGui::NextColumn();
	ImGui::Text( "Name" );		ImGui::NextColumn();
	ImGui::Text( "Ip" );		ImGui::NextColumn();
	ImGui::Text( "Port" );		ImGui::NextColumn();

	ImGui::Separator();

	for( auto &ep : NodeEndpoint::getAll() )
	{
		ImGui::Text( ep->getProtocol().c_str() );								ImGui::NextColumn();
		ImGui::Text( ep->getName().c_str() );									ImGui::NextColumn();
		ImGui::Text( ep->getIp().c_str() );										ImGui::NextColumn();
		ImGui::Text( ep->isOsc() ? to_string(ep->getPort()).c_str() : " " );	ImGui::NextColumn();
	}

	ImGui::Columns(1);

    ui::EndMenu();
}
@ocornut
Copy link
Owner

ocornut commented May 19, 2017

Thanks. I won't have to time to look at it right away, Columns are notoriously in need for a rewrite for many different reasons.

Not, I'm not sure exactly which bug you are referring too, with your repro

        ImGui::Begin("Bug #1149");
        if( ImGui::BeginMenu( "Endpoints" ) )
        {
            if (ImGui::BeginMenu("New Endpoint"))
            {
                ImGui::Text( "Create Endpoint" );
                ImGui::Button("create");
                ImGui::EndMenu();
            }
            ImGui::Columns(4, "endpoints-view", false);
            ImGui::Separator();

            ImGui::Text( "Protocol" );	ImGui::NextColumn();
            ImGui::Text( "Name" );		ImGui::NextColumn();
            ImGui::Text( "Ip" );		ImGui::NextColumn();
            ImGui::Text( "Port" );		ImGui::NextColumn();

            ImGui::Separator();

            for (int n = 0; n < 10; n++)
            {
                ImGui::Text( "blah" ); ImGui::NextColumn();
                ImGui::Text( "this is a name" ); ImGui::NextColumn();
                ImGui::Text( "192.168.255.255" ); ImGui::NextColumn();
                ImGui::Text( "1234" ); ImGui::NextColumn();
            }

            ImGui::Columns(1);
            ImGui::EndMenu();
        }
        ImGui::End();

I get:
image

Which is visibly clipped, so arguably a bug from user's point of view, but not news as Columns do not have any sizing policy at the moment, so the whole columns set is spreading within available space.

As a ugly workaround to explicitly enlarge the menu you use, e.g.

        if( ImGui::BeginMenu( "Endpoints" ) )
        {
            float x = ImGui::GetCursorPosX();
            ImGui::SetCursorPosX(400.0f);
            ImGui::SetCursorPosX(x);

As pointed out, adding the columns separator gives odd resizing behavior.

At the moment I would suggest using SameLine() with known X positions to simulate cheap columns (but that would limit your field size). Sorry it's not great :(

@ocornut ocornut added layout and removed bug labels Apr 8, 2019
@ocornut
Copy link
Owner

ocornut commented Dec 8, 2020

Closing this as

Equivalent test with Tables.
Note that it requires ImGuiTableFlags_ColumnsWidthFixed policy because the Stretch policy uses available space.

ImGui::Begin("Bug #1149");
if (ImGui::BeginMenu("Endpoints"))
{
    if (ImGui::BeginMenu("New Endpoint"))
    {
        ImGui::Text("Create Endpoint");
        ImGui::Button("create");
        ImGui::EndMenu();
    }

    if (ImGui::BeginTable("endpoints-view", 4, ImGuiTableFlags_ColumnsWidthFixed | ImGuiTableFlags_Borders))
    {
        ImGui::TableNextColumn(); ImGui::TableHeader("Protocol");
        ImGui::TableNextColumn(); ImGui::TableHeader("Name");
        ImGui::TableNextColumn(); ImGui::TableHeader("Ip");
        ImGui::TableNextColumn(); ImGui::TableHeader("Port");
        for (int n = 0; n < 10; n++)
        {
            ImGui::TableNextColumn(); ImGui::Text("blah");
            ImGui::TableNextColumn(); ImGui::Text("this is a name");
            ImGui::TableNextColumn(); ImGui::Text("192.168.255.255");
            ImGui::TableNextColumn(); ImGui::Text("1234");
        }
        ImGui::EndTable();
    }
    ImGui::EndMenu();
}
ImGui::End();

image

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

No branches or pull requests

2 participants