Show a combo box with a choice of sizing policies
| 5555 | |
| 5556 | // Show a combo box with a choice of sizing policies |
| 5557 | static void EditTableSizingFlags(ImGuiTableFlags* p_flags) |
| 5558 | { |
| 5559 | struct EnumDesc { ImGuiTableFlags Value; const char* Name; const char* Tooltip; }; |
| 5560 | static const EnumDesc policies[] = |
| 5561 | { |
| 5562 | { ImGuiTableFlags_None, "Default", "Use default sizing policy:\n- ImGuiTableFlags_SizingFixedFit if ScrollX is on or if host window has ImGuiWindowFlags_AlwaysAutoResize.\n- ImGuiTableFlags_SizingStretchSame otherwise." }, |
| 5563 | { ImGuiTableFlags_SizingFixedFit, "ImGuiTableFlags_SizingFixedFit", "Columns default to _WidthFixed (if resizable) or _WidthAuto (if not resizable), matching contents width." }, |
| 5564 | { ImGuiTableFlags_SizingFixedSame, "ImGuiTableFlags_SizingFixedSame", "Columns are all the same width, matching the maximum contents width.\nImplicitly disable ImGuiTableFlags_Resizable and enable ImGuiTableFlags_NoKeepColumnsVisible." }, |
| 5565 | { ImGuiTableFlags_SizingStretchProp, "ImGuiTableFlags_SizingStretchProp", "Columns default to _WidthStretch with weights proportional to their widths." }, |
| 5566 | { ImGuiTableFlags_SizingStretchSame, "ImGuiTableFlags_SizingStretchSame", "Columns default to _WidthStretch with same weights." } |
| 5567 | }; |
| 5568 | int idx; |
| 5569 | for (idx = 0; idx < IM_ARRAYSIZE(policies); idx++) |
| 5570 | if (policies[idx].Value == (*p_flags & ImGuiTableFlags_SizingMask_)) |
| 5571 | break; |
| 5572 | const char* preview_text = (idx < IM_ARRAYSIZE(policies)) ? policies[idx].Name + (idx > 0 ? strlen("ImGuiTableFlags") : 0) : ""; |
| 5573 | if (ImGui::BeginCombo("Sizing Policy", preview_text)) |
| 5574 | { |
| 5575 | for (int n = 0; n < IM_ARRAYSIZE(policies); n++) |
| 5576 | if (ImGui::Selectable(policies[n].Name, idx == n)) |
| 5577 | *p_flags = (*p_flags & ~ImGuiTableFlags_SizingMask_) | policies[n].Value; |
| 5578 | ImGui::EndCombo(); |
| 5579 | } |
| 5580 | ImGui::SameLine(); |
| 5581 | ImGui::TextDisabled("(?)"); |
| 5582 | if (ImGui::BeginItemTooltip()) |
| 5583 | { |
| 5584 | ImGui::PushTextWrapPos(ImGui::GetFontSize() * 50.0f); |
| 5585 | for (int m = 0; m < IM_ARRAYSIZE(policies); m++) |
| 5586 | { |
| 5587 | ImGui::Separator(); |
| 5588 | ImGui::Text("%s:", policies[m].Name); |
| 5589 | ImGui::Separator(); |
| 5590 | ImGui::SetCursorPosX(ImGui::GetCursorPosX() + ImGui::GetStyle().IndentSpacing * 0.5f); |
| 5591 | ImGui::TextUnformatted(policies[m].Tooltip); |
| 5592 | } |
| 5593 | ImGui::PopTextWrapPos(); |
| 5594 | ImGui::EndTooltip(); |
| 5595 | } |
| 5596 | } |
| 5597 | |
| 5598 | static void EditTableColumnsFlags(ImGuiTableColumnFlags* p_flags) |
| 5599 | { |