mirror of
https://github.com/Drezil/imgui.git
synced 2025-07-04 12:08:47 +02:00
Clarify usage of right-aligned items in Layout>Widgets Width. Tweaks FAQ, added missing syntax coloring.
This commit is contained in:
@ -308,8 +308,8 @@ void ImGui::ShowDemoWindow(bool* p_open)
|
||||
|
||||
// Most "big" widgets share a common width settings by default. See 'Demo->Layout->Widgets Width' for details.
|
||||
|
||||
// e.g. Use 2/3 of the space for widgets and 1/3 for labels (default)
|
||||
//ImGui::PushItemWidth(ImGui::GetWindowWidth() * 0.65f);
|
||||
// e.g. Use 2/3 of the space for widgets and 1/3 for labels (right align)
|
||||
//ImGui::PushItemWidth(-ImGui::GetWindowWidth() * 0.35f);
|
||||
|
||||
// e.g. Leave a fixed amount of width for labels (by passing a negative value), the rest goes to widgets.
|
||||
ImGui::PushItemWidth(ImGui::GetFontSize() * -12);
|
||||
@ -476,6 +476,7 @@ void ImGui::ShowDemoWindow(bool* p_open)
|
||||
ShowDemoWindowMisc();
|
||||
|
||||
// End of ShowDemoWindow()
|
||||
ImGui::PopItemWidth();
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
@ -2170,34 +2171,69 @@ static void ShowDemoWindowLayout()
|
||||
// e.g. Using '20.0f * GetFontSize()' as width instead of '200.0f', etc.
|
||||
|
||||
static float f = 0.0f;
|
||||
static bool show_indented_items = true;
|
||||
ImGui::Checkbox("Show indented items", &show_indented_items);
|
||||
|
||||
ImGui::Text("SetNextItemWidth/PushItemWidth(100)");
|
||||
ImGui::SameLine(); HelpMarker("Fixed width.");
|
||||
ImGui::SetNextItemWidth(100);
|
||||
ImGui::DragFloat("float##1", &f);
|
||||
|
||||
ImGui::Text("SetNextItemWidth/PushItemWidth(GetWindowWidth() * 0.5f)");
|
||||
ImGui::SameLine(); HelpMarker("Half of window width.");
|
||||
ImGui::SetNextItemWidth(ImGui::GetWindowWidth() * 0.5f);
|
||||
ImGui::DragFloat("float##2", &f);
|
||||
|
||||
ImGui::Text("SetNextItemWidth/PushItemWidth(GetContentRegionAvail().x * 0.5f)");
|
||||
ImGui::SameLine(); HelpMarker("Half of available width.\n(~ right-cursor_pos)\n(works within a column set)");
|
||||
ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x * 0.5f);
|
||||
ImGui::DragFloat("float##3", &f);
|
||||
ImGui::PushItemWidth(100);
|
||||
ImGui::DragFloat("float##1b", &f);
|
||||
if (show_indented_items)
|
||||
{
|
||||
ImGui::Indent();
|
||||
ImGui::DragFloat("float (indented)##1b", &f);
|
||||
ImGui::Unindent();
|
||||
}
|
||||
ImGui::PopItemWidth();
|
||||
|
||||
ImGui::Text("SetNextItemWidth/PushItemWidth(-100)");
|
||||
ImGui::SameLine(); HelpMarker("Align to right edge minus 100");
|
||||
ImGui::SetNextItemWidth(-100);
|
||||
ImGui::DragFloat("float##4", &f);
|
||||
ImGui::PushItemWidth(-100);
|
||||
ImGui::DragFloat("float##2a", &f);
|
||||
if (show_indented_items)
|
||||
{
|
||||
ImGui::Indent();
|
||||
ImGui::DragFloat("float (indented)##2b", &f);
|
||||
ImGui::Unindent();
|
||||
}
|
||||
ImGui::PopItemWidth();
|
||||
|
||||
ImGui::Text("SetNextItemWidth/PushItemWidth(GetContentRegionAvail().x * 0.5f)");
|
||||
ImGui::SameLine(); HelpMarker("Half of available width.\n(~ right-cursor_pos)\n(works within a column set)");
|
||||
ImGui::PushItemWidth(ImGui::GetContentRegionAvail().x * 0.5f);
|
||||
ImGui::DragFloat("float##3a", &f);
|
||||
if (show_indented_items)
|
||||
{
|
||||
ImGui::Indent();
|
||||
ImGui::DragFloat("float (indented)##3b", &f);
|
||||
ImGui::Unindent();
|
||||
}
|
||||
ImGui::PopItemWidth();
|
||||
|
||||
ImGui::Text("SetNextItemWidth/PushItemWidth(-GetContentRegionAvail().x * 0.5f)");
|
||||
ImGui::SameLine(); HelpMarker("Align to right edge minus half");
|
||||
ImGui::PushItemWidth(-ImGui::GetContentRegionAvail().x * 0.5f);
|
||||
ImGui::DragFloat("float##4a", &f);
|
||||
if (show_indented_items)
|
||||
{
|
||||
ImGui::Indent();
|
||||
ImGui::DragFloat("float (indented)##4b", &f);
|
||||
ImGui::Unindent();
|
||||
}
|
||||
ImGui::PopItemWidth();
|
||||
|
||||
// Demonstrate using PushItemWidth to surround three items.
|
||||
// Calling SetNextItemWidth() before each of them would have the same effect.
|
||||
ImGui::Text("SetNextItemWidth/PushItemWidth(-1)");
|
||||
ImGui::Text("SetNextItemWidth/PushItemWidth(-FLT_MIN)");
|
||||
ImGui::SameLine(); HelpMarker("Align to right edge");
|
||||
ImGui::PushItemWidth(-1);
|
||||
ImGui::PushItemWidth(-FLT_MIN);
|
||||
ImGui::DragFloat("##float5a", &f);
|
||||
ImGui::DragFloat("##float5b", &f);
|
||||
ImGui::DragFloat("##float5c", &f);
|
||||
if (show_indented_items)
|
||||
{
|
||||
ImGui::Indent();
|
||||
ImGui::DragFloat("float (indented)##5b", &f);
|
||||
ImGui::Unindent();
|
||||
}
|
||||
ImGui::PopItemWidth();
|
||||
|
||||
ImGui::TreePop();
|
||||
|
Reference in New Issue
Block a user