MenuItem() draft for popups, with Selected option (wip #126)

docking
ocornut 10 years ago
parent c36172ebef
commit f46557d2d6

@ -7220,6 +7220,41 @@ bool ImGui::ListBox(const char* label, int* current_item, bool (*items_getter)(v
return value_changed;
}
bool ImGui::MenuItem(const char* label, const char* shortcut, bool selected)
{
(void)shortcut; // FIXME-MENU: Shortcut are not supported yet. Argument is reserved.
ImGuiState& g = *GImGui;
ImGuiWindow* window = GetCurrentWindow();
if (window->SkipItems)
return false;
ImVec2 pos = ImGui::GetCursorScreenPos();
const ImVec2 label_size = CalcTextSize(label, NULL, true);
const float symbol_spacing = (float)(int)(g.FontSize * 1.50f + 0.5f);
const float w = ImMax(label_size.x + symbol_spacing, window->Pos.x + ImGui::GetContentRegionMax().x - window->DC.CursorPos.x); // Feedback to next frame
bool ret = ImGui::Selectable(label, false, ImVec2(w, 0.0f));
if (selected)
{
pos.x = window->Pos.x + ImGui::GetContentRegionMax().x - g.FontSize;
RenderCheckMark(pos, window->Color(ImGuiCol_Text));
}
return ret;
}
bool ImGui::MenuItem(const char* label, const char* shortcut, bool* p_selected)
{
if (ImGui::MenuItem(label, shortcut, p_selected ? *p_selected : false))
{
if (p_selected)
*p_selected = !*p_selected;
return true;
}
return false;
}
// A little colored square. Return true when clicked.
bool ImGui::ColorButton(const ImVec4& col, bool small_height, bool outline_border)
{
@ -10007,23 +10042,26 @@ void ImGui::ShowTestWindow(bool* opened)
ImGui::TreePop();
}
if (ImGui::TreeNode("Popup"))
if (ImGui::TreeNode("Popup, Menus"))
{
static bool popup_open = false;
static int selected_fish = -1;
const char* fishes[] = { "Bream", "Haddock", "Mackerel", "Pollock", "Tilefish" };
const char* names[] = { "BreamXYZA", "Haddk", "Mackerel", "Pollock", "Tilefish" };
static bool toggles[] = { true, false, false, false, false };
{
static bool popup_open = false;
if (ImGui::Button("Select.."))
popup_open = true;
ImGui::SameLine();
ImGui::Text(selected_fish == -1 ? "<None>" : fishes[selected_fish]);
ImGui::Text(selected_fish == -1 ? "<None>" : names[selected_fish]);
if (popup_open)
{
ImGui::BeginPopup(&popup_open);
ImGui::Text("Aquarium");
ImGui::Separator();
for (int i = 0; i < IM_ARRAYSIZE(fishes); i++)
for (int i = 0; i < IM_ARRAYSIZE(names); i++)
{
if (ImGui::Selectable(fishes[i], false))
if (ImGui::Selectable(names[i]))
{
selected_fish = i;
popup_open = false;
@ -10031,6 +10069,21 @@ void ImGui::ShowTestWindow(bool* opened)
}
ImGui::EndPopup();
}
}
{
static bool popup_open = false;
if (ImGui::Button("Toggle.."))
popup_open = true;
if (popup_open)
{
ImGui::BeginPopup(&popup_open);
for (int i = 0; i < IM_ARRAYSIZE(names); i++)
if (ImGui::MenuItem(names[i], "", &toggles[i]))
popup_open = false;
ImGui::EndPopup();
}
}
ImGui::TreePop();
}

@ -357,6 +357,11 @@ namespace ImGui
IMGUI_API bool ListBoxHeader(const char* label, int items_count, int height_in_items = -1); // "
IMGUI_API void ListBoxFooter(); // terminate the scrolling region
// Widgets: Menus
// FIXME-WIP: v1.39 in development
IMGUI_API bool MenuItem(const char* label, const char* shortcut = NULL, bool selected = NULL); // bool enabled = true
IMGUI_API bool MenuItem(const char* label, const char* shortcut, bool* p_selected); // bool enabled = true
// Widgets: Value() Helpers. Output single value in "name: value" format (tip: freely declare your own within the ImGui namespace!)
IMGUI_API void Value(const char* prefix, bool b);
IMGUI_API void Value(const char* prefix, int v);

Loading…
Cancel
Save