mirror of
https://github.com/Drezil/imgui.git
synced 2025-07-04 12:08:47 +02:00
Merge branch 'master' into viewport
# Conflicts: # examples/sdl_opengl2_example/main.cpp # examples/sdl_opengl3_example/main.cpp # examples/vulkan_example/main.cpp
This commit is contained in:
128
imgui_demo.cpp
128
imgui_demo.cpp
@ -321,37 +321,16 @@ void ImGui::ShowDemoWindow(bool* p_open)
|
||||
ImGui::EndTooltip();
|
||||
}
|
||||
|
||||
// Testing ImGuiOnceUponAFrame helper.
|
||||
//static ImGuiOnceUponAFrame once;
|
||||
//for (int i = 0; i < 5; i++)
|
||||
// if (once)
|
||||
// ImGui::Text("This will be displayed only once.");
|
||||
|
||||
ImGui::Separator();
|
||||
|
||||
ImGui::LabelText("label", "Value");
|
||||
|
||||
{
|
||||
// Simplified one-liner Combo() API, using values packed in a single constant string
|
||||
static int current_item_1 = 1;
|
||||
ImGui::Combo("combo", ¤t_item_1, "aaaa\0bbbb\0cccc\0dddd\0eeee\0\0");
|
||||
//ImGui::Combo("combo w/ array of char*", ¤t_item_2_idx, items, IM_ARRAYSIZE(items)); // Combo using proper array. You can also pass a callback to retrieve array value, no need to create/copy an array just for that.
|
||||
|
||||
// General BeginCombo() API, you have full control over your selection data and display type
|
||||
const char* items[] = { "AAAA", "BBBB", "CCCC", "DDDD", "EEEE", "FFFF", "GGGG", "HHHH", "IIII", "JJJJ", "KKKK", "LLLLLLL", "MMMM", "OOOOOOO", "PPPP", "QQQQQQQQQQ", "RRR", "SSSS" };
|
||||
static const char* current_item_2 = NULL;
|
||||
if (ImGui::BeginCombo("combo 2", current_item_2)) // The second parameter is the label previewed before opening the combo.
|
||||
{
|
||||
for (int n = 0; n < IM_ARRAYSIZE(items); n++)
|
||||
{
|
||||
bool is_selected = (current_item_2 == items[n]); // You can store your selection however you want, outside or inside your objects
|
||||
if (ImGui::Selectable(items[n], is_selected))
|
||||
current_item_2 = items[n];
|
||||
if (is_selected)
|
||||
ImGui::SetItemDefaultFocus(); // Set the initial focus when opening the combo (scrolling + for keyboard navigation support in the upcoming navigation branch)
|
||||
}
|
||||
ImGui::EndCombo();
|
||||
}
|
||||
// Using the _simplified_ one-liner Combo() api here
|
||||
const char* items[] = { "AAAA", "BBBB", "CCCC", "DDDD", "EEEE", "FFFF", "GGGG", "HHHH", "IIII", "JJJJ", "KKKK", "LLLLLLL", "MMMM", "OOOOOOO" };
|
||||
static int item_current = 0;
|
||||
ImGui::Combo("combo", &item_current, items, IM_ARRAYSIZE(items));
|
||||
ImGui::SameLine(); ShowHelpMarker("Refer to the \"Combo\" section below for an explanation of the full BeginCombo/EndCombo API, and demonstration of various flags.\n");
|
||||
}
|
||||
|
||||
{
|
||||
@ -394,25 +373,36 @@ void ImGui::ShowDemoWindow(bool* p_open)
|
||||
ImGui::SliderAngle("slider angle", &angle);
|
||||
}
|
||||
|
||||
static float col1[3] = { 1.0f,0.0f,0.2f };
|
||||
static float col2[4] = { 0.4f,0.7f,0.0f,0.5f };
|
||||
ImGui::ColorEdit3("color 1", col1);
|
||||
ImGui::SameLine(); ShowHelpMarker("Click on the colored square to open a color picker.\nRight-click on the colored square to show options.\nCTRL+click on individual component to input value.\n");
|
||||
{
|
||||
static float col1[3] = { 1.0f,0.0f,0.2f };
|
||||
static float col2[4] = { 0.4f,0.7f,0.0f,0.5f };
|
||||
ImGui::ColorEdit3("color 1", col1);
|
||||
ImGui::SameLine(); ShowHelpMarker("Click on the colored square to open a color picker.\nRight-click on the colored square to show options.\nCTRL+click on individual component to input value.\n");
|
||||
|
||||
ImGui::ColorEdit4("color 2", col2);
|
||||
ImGui::ColorEdit4("color 2", col2);
|
||||
}
|
||||
|
||||
const char* listbox_items[] = { "Apple", "Banana", "Cherry", "Kiwi", "Mango", "Orange", "Pineapple", "Strawberry", "Watermelon" };
|
||||
static int listbox_item_current = 1;
|
||||
ImGui::ListBox("listbox\n(single select)", &listbox_item_current, listbox_items, IM_ARRAYSIZE(listbox_items), 4);
|
||||
{
|
||||
// List box
|
||||
const char* listbox_items[] = { "Apple", "Banana", "Cherry", "Kiwi", "Mango", "Orange", "Pineapple", "Strawberry", "Watermelon" };
|
||||
static int listbox_item_current = 1;
|
||||
ImGui::ListBox("listbox\n(single select)", &listbox_item_current, listbox_items, IM_ARRAYSIZE(listbox_items), 4);
|
||||
|
||||
//static int listbox_item_current2 = 2;
|
||||
//ImGui::PushItemWidth(-1);
|
||||
//ImGui::ListBox("##listbox2", &listbox_item_current2, listbox_items, IM_ARRAYSIZE(listbox_items), 4);
|
||||
//ImGui::PopItemWidth();
|
||||
//static int listbox_item_current2 = 2;
|
||||
//ImGui::PushItemWidth(-1);
|
||||
//ImGui::ListBox("##listbox2", &listbox_item_current2, listbox_items, IM_ARRAYSIZE(listbox_items), 4);
|
||||
//ImGui::PopItemWidth();
|
||||
}
|
||||
|
||||
ImGui::TreePop();
|
||||
}
|
||||
|
||||
// Testing ImGuiOnceUponAFrame helper.
|
||||
//static ImGuiOnceUponAFrame once;
|
||||
//for (int i = 0; i < 5; i++)
|
||||
// if (once)
|
||||
// ImGui::Text("This will be displayed only once.");
|
||||
|
||||
if (ImGui::TreeNode("Trees"))
|
||||
{
|
||||
if (ImGui::TreeNode("Basic trees"))
|
||||
@ -570,8 +560,8 @@ void ImGui::ShowDemoWindow(bool* p_open)
|
||||
|
||||
if (ImGui::TreeNode("Images"))
|
||||
{
|
||||
ImGui::TextWrapped("Below we are displaying the font texture (which is the only texture we have access to in this demo). Use the 'ImTextureID' type as storage to pass pointers or identifier to your own texture data. Hover the texture for a zoomed view!");
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
ImGui::TextWrapped("Below we are displaying the font texture (which is the only texture we have access to in this demo). Use the 'ImTextureID' type as storage to pass pointers or identifier to your own texture data. Hover the texture for a zoomed view!");
|
||||
|
||||
// Here we are grabbing the font texture because that's the only one we have access to inside the demo code.
|
||||
// Remember that ImTextureID is just storage for whatever you want it to be, it is essentially a value that will be passed to the render function inside the ImDrawCmd structure.
|
||||
@ -590,14 +580,15 @@ void ImGui::ShowDemoWindow(bool* p_open)
|
||||
if (ImGui::IsItemHovered())
|
||||
{
|
||||
ImGui::BeginTooltip();
|
||||
float focus_sz = 32.0f;
|
||||
float focus_x = io.MousePos.x - pos.x - focus_sz * 0.5f; if (focus_x < 0.0f) focus_x = 0.0f; else if (focus_x > my_tex_w - focus_sz) focus_x = my_tex_w - focus_sz;
|
||||
float focus_y = io.MousePos.y - pos.y - focus_sz * 0.5f; if (focus_y < 0.0f) focus_y = 0.0f; else if (focus_y > my_tex_h - focus_sz) focus_y = my_tex_h - focus_sz;
|
||||
ImGui::Text("Min: (%.2f, %.2f)", focus_x, focus_y);
|
||||
ImGui::Text("Max: (%.2f, %.2f)", focus_x + focus_sz, focus_y + focus_sz);
|
||||
ImVec2 uv0 = ImVec2((focus_x) / my_tex_w, (focus_y) / my_tex_h);
|
||||
ImVec2 uv1 = ImVec2((focus_x + focus_sz) / my_tex_w, (focus_y + focus_sz) / my_tex_h);
|
||||
ImGui::Image(my_tex_id, ImVec2(128,128), uv0, uv1, ImColor(255,255,255,255), ImColor(255,255,255,128));
|
||||
float region_sz = 32.0f;
|
||||
float region_x = io.MousePos.x - pos.x - region_sz * 0.5f; if (region_x < 0.0f) region_x = 0.0f; else if (region_x > my_tex_w - region_sz) region_x = my_tex_w - region_sz;
|
||||
float region_y = io.MousePos.y - pos.y - region_sz * 0.5f; if (region_y < 0.0f) region_y = 0.0f; else if (region_y > my_tex_h - region_sz) region_y = my_tex_h - region_sz;
|
||||
float zoom = 4.0f;
|
||||
ImGui::Text("Min: (%.2f, %.2f)", region_x, region_y);
|
||||
ImGui::Text("Max: (%.2f, %.2f)", region_x + region_sz, region_y + region_sz);
|
||||
ImVec2 uv0 = ImVec2((region_x) / my_tex_w, (region_y) / my_tex_h);
|
||||
ImVec2 uv1 = ImVec2((region_x + region_sz) / my_tex_w, (region_y + region_sz) / my_tex_h);
|
||||
ImGui::Image(my_tex_id, ImVec2(region_sz * zoom, region_sz * zoom), uv0, uv1, ImColor(255,255,255,255), ImColor(255,255,255,128));
|
||||
ImGui::EndTooltip();
|
||||
}
|
||||
ImGui::TextWrapped("And now some textured buttons..");
|
||||
@ -616,6 +607,49 @@ void ImGui::ShowDemoWindow(bool* p_open)
|
||||
ImGui::TreePop();
|
||||
}
|
||||
|
||||
if (ImGui::TreeNode("Combo"))
|
||||
{
|
||||
// Expose flags as checkbox for the demo
|
||||
static ImGuiComboFlags flags = 0;
|
||||
ImGui::CheckboxFlags("ImGuiComboFlags_PopupAlignLeft", (unsigned int*)&flags, ImGuiComboFlags_PopupAlignLeft);
|
||||
if (ImGui::CheckboxFlags("ImGuiComboFlags_NoArrowButton", (unsigned int*)&flags, ImGuiComboFlags_NoArrowButton))
|
||||
flags &= ~ImGuiComboFlags_NoPreview; // Clear the other flag, as we cannot combine both
|
||||
if (ImGui::CheckboxFlags("ImGuiComboFlags_NoPreview", (unsigned int*)&flags, ImGuiComboFlags_NoPreview))
|
||||
flags &= ~ImGuiComboFlags_NoArrowButton; // Clear the other flag, as we cannot combine both
|
||||
|
||||
// General BeginCombo() API, you have full control over your selection data and display type.
|
||||
// (your selection data could be an index, a pointer to the object, an id for the object, a flag stored in the object itself, etc.)
|
||||
const char* items[] = { "AAAA", "BBBB", "CCCC", "DDDD", "EEEE", "FFFF", "GGGG", "HHHH", "IIII", "JJJJ", "KKKK", "LLLLLLL", "MMMM", "OOOOOOO" };
|
||||
static const char* item_current = items[0]; // Here our selection is a single pointer stored outside the object.
|
||||
if (ImGui::BeginCombo("combo 1", item_current, flags)) // The second parameter is the label previewed before opening the combo.
|
||||
{
|
||||
for (int n = 0; n < IM_ARRAYSIZE(items); n++)
|
||||
{
|
||||
bool is_selected = (item_current == items[n]);
|
||||
if (ImGui::Selectable(items[n], is_selected))
|
||||
item_current = items[n];
|
||||
if (is_selected)
|
||||
ImGui::SetItemDefaultFocus(); // Set the initial focus when opening the combo (scrolling + for keyboard navigation support in the upcoming navigation branch)
|
||||
}
|
||||
ImGui::EndCombo();
|
||||
}
|
||||
|
||||
// Simplified one-liner Combo() API, using values packed in a single constant string
|
||||
static int item_current_2 = 0;
|
||||
ImGui::Combo("combo 2 (one-liner)", &item_current_2, "aaaa\0bbbb\0cccc\0dddd\0eeee\0\0");
|
||||
|
||||
// Simplified one-liner Combo() using an array of const char*
|
||||
static int item_current_3 = -1; // If the selection isn't within 0..count, Combo won't display a preview
|
||||
ImGui::Combo("combo 3 (array)", &item_current_3, items, IM_ARRAYSIZE(items));
|
||||
|
||||
// Simplified one-liner Combo() using an accessor function
|
||||
struct FuncHolder { static bool ItemGetter(void* data, int idx, const char** out_str) { *out_str = ((const char**)data)[idx]; return true; } };
|
||||
static int item_current_4 = 0;
|
||||
ImGui::Combo("combo 4 (function)", &item_current_4, &FuncHolder::ItemGetter, items, IM_ARRAYSIZE(items));
|
||||
|
||||
ImGui::TreePop();
|
||||
}
|
||||
|
||||
if (ImGui::TreeNode("Selectables"))
|
||||
{
|
||||
// Selectable() has 2 overloads:
|
||||
|
Reference in New Issue
Block a user