| 9 | PartList::~PartList() {} |
| 10 | |
| 11 | void PartList::Draw(const char *title, bool *p_open, Board *board) { |
| 12 | // TODO: export / fix dimensions & behaviour |
| 13 | int width = 400; |
| 14 | int height = 640; |
| 15 | |
| 16 | ImGui::SetNextWindowSize(ImVec2(width, height)); |
| 17 | ImGui::Begin(title, p_open); |
| 18 | |
| 19 | ImGui::Columns(1, "part_infos"); |
| 20 | ImGui::Separator(); |
| 21 | |
| 22 | ImGui::Text("Name"); |
| 23 | ImGui::NextColumn(); |
| 24 | ImGui::Separator(); |
| 25 | |
| 26 | if (board) { |
| 27 | auto parts = board->Components(); |
| 28 | |
| 29 | static int selected = -1; |
| 30 | std::string part_name = ""; |
| 31 | ImGuiListClipper clipper; |
| 32 | clipper.Begin(parts.size()); |
| 33 | while (clipper.Step()) { |
| 34 | for (int i = clipper.DisplayStart; i < clipper.DisplayEnd; i++) { |
| 35 | part_name = parts[i]->name; |
| 36 | |
| 37 | if (ImGui::Selectable(part_name.c_str(), selected == i, ImGuiSelectableFlags_AllowDoubleClick)) { |
| 38 | selected = i; |
| 39 | if (ImGui::IsMouseDoubleClicked(0)) { |
| 40 | cbNetSelected_(part_name.c_str()); |
| 41 | } |
| 42 | } |
| 43 | ImGui::NextColumn(); |
| 44 | } |
| 45 | } |
| 46 | clipper.End(); |
| 47 | } |
| 48 | ImGui::Columns(1); |
| 49 | ImGui::Separator(); |
| 50 | |
| 51 | if (ImGui::IsWindowHovered() && keyBindings.isPressed("CloseDialog")) { |
| 52 | *p_open = false; |
| 53 | } |
| 54 | |
| 55 | ImGui::End(); |
| 56 | } |