mirror of
https://github.com/Drezil/imgui.git
synced 2025-07-06 04:58:47 +02:00
Added SetNextItemWidth() helper to avoid using PushItemWidth/PopItemWidth() for single items.
This commit is contained in:
@ -550,9 +550,8 @@ static void ShowDemoWindowWidgets()
|
||||
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::SetNextItemWidth(-1);
|
||||
//ImGui::ListBox("##listbox2", &listbox_item_current2, listbox_items, IM_ARRAYSIZE(listbox_items), 4);
|
||||
//ImGui::PopItemWidth();
|
||||
}
|
||||
|
||||
ImGui::TreePop();
|
||||
@ -1052,7 +1051,8 @@ static void ShowDemoWindowWidgets()
|
||||
};
|
||||
static int func_type = 0, display_count = 70;
|
||||
ImGui::Separator();
|
||||
ImGui::PushItemWidth(100); ImGui::Combo("func", &func_type, "Sin\0Saw\0"); ImGui::PopItemWidth();
|
||||
ImGui::SetNextItemWidth(100);
|
||||
ImGui::Combo("func", &func_type, "Sin\0Saw\0");
|
||||
ImGui::SameLine();
|
||||
ImGui::SliderInt("Sample count", &display_count, 1, 400);
|
||||
float (*func)(void*, int) = (func_type == 0) ? Funcs::Sin : Funcs::Saw;
|
||||
@ -1667,9 +1667,8 @@ static void ShowDemoWindowLayout()
|
||||
static int line = 50;
|
||||
bool goto_line = ImGui::Button("Goto");
|
||||
ImGui::SameLine();
|
||||
ImGui::PushItemWidth(100);
|
||||
ImGui::SetNextItemWidth(100);
|
||||
goto_line |= ImGui::InputInt("##Line", &line, 0, 0, ImGuiInputTextFlags_EnterReturnsTrue);
|
||||
ImGui::PopItemWidth();
|
||||
|
||||
// Child 1: no border, enable horizontal scrollbar
|
||||
{
|
||||
@ -1740,35 +1739,36 @@ static void ShowDemoWindowLayout()
|
||||
|
||||
if (ImGui::TreeNode("Widgets Width"))
|
||||
{
|
||||
// Use SetNextItemWidth() to set the width of a single upcoming item.
|
||||
// Use PushItemWidth()/PopItemWidth() to set the width of a group of items.
|
||||
static float f = 0.0f;
|
||||
ImGui::Text("PushItemWidth(100)");
|
||||
ImGui::Text("SetNextItemWidth/PushItemWidth(100)");
|
||||
ImGui::SameLine(); HelpMarker("Fixed width.");
|
||||
ImGui::PushItemWidth(100);
|
||||
ImGui::SetNextItemWidth(100);
|
||||
ImGui::DragFloat("float##1", &f);
|
||||
ImGui::PopItemWidth();
|
||||
|
||||
ImGui::Text("PushItemWidth(GetWindowWidth() * 0.5f)");
|
||||
ImGui::Text("SetNextItemWidth/PushItemWidth(GetWindowWidth() * 0.5f)");
|
||||
ImGui::SameLine(); HelpMarker("Half of window width.");
|
||||
ImGui::PushItemWidth(ImGui::GetWindowWidth() * 0.5f);
|
||||
ImGui::SetNextItemWidth(ImGui::GetWindowWidth() * 0.5f);
|
||||
ImGui::DragFloat("float##2", &f);
|
||||
ImGui::PopItemWidth();
|
||||
|
||||
ImGui::Text("PushItemWidth(GetContentRegionAvailWidth() * 0.5f)");
|
||||
ImGui::Text("SetNextItemWidth/PushItemWidth(GetContentRegionAvailWidth() * 0.5f)");
|
||||
ImGui::SameLine(); HelpMarker("Half of available width.\n(~ right-cursor_pos)\n(works within a column set)");
|
||||
ImGui::PushItemWidth(ImGui::GetContentRegionAvailWidth() * 0.5f);
|
||||
ImGui::SetNextItemWidth(ImGui::GetContentRegionAvailWidth() * 0.5f);
|
||||
ImGui::DragFloat("float##3", &f);
|
||||
ImGui::PopItemWidth();
|
||||
|
||||
ImGui::Text("PushItemWidth(-100)");
|
||||
ImGui::Text("SetNextItemWidth/PushItemWidth(-100)");
|
||||
ImGui::SameLine(); HelpMarker("Align to right edge minus 100");
|
||||
ImGui::PushItemWidth(-100);
|
||||
ImGui::SetNextItemWidth(-100);
|
||||
ImGui::DragFloat("float##4", &f);
|
||||
ImGui::PopItemWidth();
|
||||
|
||||
ImGui::Text("PushItemWidth(-1)");
|
||||
// Demonstrate using PushItemWidth to surround three items. Calling SetNextItemWidth() before each of them would have the same effect.
|
||||
ImGui::Text("SetNextItemWidth/PushItemWidth(-1)");
|
||||
ImGui::SameLine(); HelpMarker("Align to right edge");
|
||||
ImGui::PushItemWidth(-1);
|
||||
ImGui::DragFloat("float##5", &f);
|
||||
ImGui::DragFloat("float##5a", &f);
|
||||
ImGui::DragFloat("float##5b", &f);
|
||||
ImGui::DragFloat("float##5c", &f);
|
||||
ImGui::PopItemWidth();
|
||||
|
||||
ImGui::TreePop();
|
||||
@ -2241,9 +2241,8 @@ static void ShowDemoWindowPopups()
|
||||
{
|
||||
if (ImGui::Selectable("Set to zero")) value = 0.0f;
|
||||
if (ImGui::Selectable("Set to PI")) value = 3.1415f;
|
||||
ImGui::PushItemWidth(-1);
|
||||
ImGui::SetNextItemWidth(-1);
|
||||
ImGui::DragFloat("##Value", &value, 0.1f, 0.0f, 0.0f);
|
||||
ImGui::PopItemWidth();
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
|
||||
@ -2968,7 +2967,7 @@ void ImGui::ShowStyleEditor(ImGuiStyle* ref)
|
||||
}
|
||||
ImGui::LogFinish();
|
||||
}
|
||||
ImGui::SameLine(); ImGui::PushItemWidth(120); ImGui::Combo("##output_type", &output_dest, "To Clipboard\0To TTY\0"); ImGui::PopItemWidth();
|
||||
ImGui::SameLine(); ImGui::SetNextItemWidth(120); ImGui::Combo("##output_type", &output_dest, "To Clipboard\0To TTY\0");
|
||||
ImGui::SameLine(); ImGui::Checkbox("Only Modified Colors", &output_only_modified);
|
||||
|
||||
static ImGuiTextFilter filter;
|
||||
@ -3807,12 +3806,11 @@ static void ShowExampleAppPropertyEditor(bool* p_open)
|
||||
ImGui::AlignTextToFramePadding();
|
||||
ImGui::TreeNodeEx("Field", ImGuiTreeNodeFlags_Leaf | ImGuiTreeNodeFlags_NoTreePushOnOpen | ImGuiTreeNodeFlags_Bullet, "Field_%d", i);
|
||||
ImGui::NextColumn();
|
||||
ImGui::PushItemWidth(-1);
|
||||
ImGui::SetNextItemWidth(-1);
|
||||
if (i >= 5)
|
||||
ImGui::InputFloat("##value", &dummy_members[i], 1.0f);
|
||||
else
|
||||
ImGui::DragFloat("##value", &dummy_members[i], 0.01f);
|
||||
ImGui::PopItemWidth();
|
||||
ImGui::NextColumn();
|
||||
}
|
||||
ImGui::PopID();
|
||||
@ -3952,10 +3950,10 @@ static void ShowExampleAppConstrainedResize(bool* p_open)
|
||||
if (ImGui::Button("200x200")) { ImGui::SetWindowSize(ImVec2(200, 200)); } ImGui::SameLine();
|
||||
if (ImGui::Button("500x500")) { ImGui::SetWindowSize(ImVec2(500, 500)); } ImGui::SameLine();
|
||||
if (ImGui::Button("800x200")) { ImGui::SetWindowSize(ImVec2(800, 200)); }
|
||||
ImGui::PushItemWidth(200);
|
||||
ImGui::SetNextItemWidth(200);
|
||||
ImGui::Combo("Constraint", &type, desc, IM_ARRAYSIZE(desc));
|
||||
ImGui::SetNextItemWidth(200);
|
||||
ImGui::DragInt("Lines", &display_lines, 0.2f, 1, 100);
|
||||
ImGui::PopItemWidth();
|
||||
ImGui::Checkbox("Auto-resize", &auto_resize);
|
||||
for (int i = 0; i < display_lines; i++)
|
||||
ImGui::Text("%*sHello, sailor! Making this line long enough for the example.", i * 4, "");
|
||||
@ -4401,7 +4399,7 @@ void ShowExampleAppDocuments(bool* p_open)
|
||||
if (ImGui::BeginPopupModal("Save?"))
|
||||
{
|
||||
ImGui::Text("Save change to the following items?");
|
||||
ImGui::PushItemWidth(-1.0f);
|
||||
ImGui::SetNextItemWidth(-1.0f);
|
||||
if (ImGui::ListBoxHeader("##", close_queue_unsaved_documents, 6))
|
||||
{
|
||||
for (int n = 0; n < close_queue.Size; n++)
|
||||
|
Reference in New Issue
Block a user