Skip to content

The element doesn't want to be selected #6186

@ghost

Description

Hello.
I am trying to select item from table but it's not selecting. When i change the text, all works.
https://user-images.githubusercontent.com/126063817/220577306-297fc741-b451-45b8-87f9-d48530200867.mp4
Here is a code:

bool openned = false;

struct n {
	string first;
	string second;
};

vector<n> items;
int current_index = 0;

void gui::Render() noexcept
{
	ImGui::ShowDemoWindow();
	if (!openned) {
		ImGui::SetNextWindowSize(ImVec2(800, 600));
		ImGui::SetNextWindowPos(ImVec2(10, 10));
		for (int i = 0; i < 5; i++) {
			n newdata = {"blah", "blah"};
			items.push_back(newdata);
		}
		openned = true;
	}

	ImGui::Begin("bug?");

	char first[128];
	strcpy_s(first, items[current_index].first.c_str());
	if (ImGui::InputText("First Name", first, IM_ARRAYSIZE(first))) {
		items[current_index].first = (string)first;
	}

	char second[128];
	strcpy_s(second, items[current_index].second.c_str());
	if (ImGui::InputText("Last Name", second, IM_ARRAYSIZE(second))) {
		items[current_index].second = (string)second;
	}

	if (ImGui::BeginTable("##table", 2, ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_Borders)) {
		ImGui::TableNextColumn(); ImGui::TableHeader("First Name");
		ImGui::TableNextColumn(); ImGui::TableHeader("Last Name");
		for (size_t i = 0; i < items.size(); i++) {
			ImGui::TableNextRow();
			ImGui::TableNextColumn();
			bool is_selected = (current_index == i);
			if (ImGui::Selectable(items[i].first.c_str(), is_selected, ImGuiSelectableFlags_SpanAllColumns)) {                            
				current_index = i;
			}   	
			ImGui::TableNextColumn();	
			ImGui::Text(items[i].second.c_str());
		}
		ImGui::EndTable();
	}

	ImGui::End();
}

Is this a bug or did I make an error in the code? Thank you

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions