|
@@ -410,9 +410,19 @@ void ImGui::ShowDemoWindow(bool* p_open)
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- // Most "big" widgets share a common width settings by default. See 'Demo->Layout->Widgets Width' for details.
|
|
|
- ImGui::PushItemWidth(ImGui::GetFontSize() * -12); // e.g. Leave a fixed amount of width for labels (by passing a negative value), the rest goes to widgets.
|
|
|
- //ImGui::PushItemWidth(-ImGui::GetWindowWidth() * 0.35f); // e.g. Use 2/3 of the space for widgets and 1/3 for labels (right align)
|
|
|
+ // Most framed widgets share a common width settings. Remaining width is used for the label.
|
|
|
+ // The width of the frame may be changed with PushItemWidth() or SetNextItemWidth().
|
|
|
+ // - Positive value for absolute size, negative value for right-alignment.
|
|
|
+ // - The default value is about GetWindowWidth() * 0.65f.
|
|
|
+ // - See 'Demo->Layout->Widgets Width' for details.
|
|
|
+ // Here we change the frame width based on how much width we want to give to the label.
|
|
|
+ const float label_width_base = ImGui::GetFontSize() * 12; // Some amount of width for label, based on font size.
|
|
|
+ const float label_width_max = ImGui::GetContentRegionAvail().x * 0.40f; // ...but always leave some room for framed widgets.
|
|
|
+ const float label_width = IM_MIN(label_width_base, label_width_max);
|
|
|
+ ImGui::PushItemWidth(-label_width); // Right-align: framed items will leave 'label_width' available for the label.
|
|
|
+ //ImGui::PushItemWidth(ImGui::GetContentRegionAvail().x * 0.40f); // e.g. Use 40% width for framed widgets, leaving 60% width for labels.
|
|
|
+ //ImGui::PushItemWidth(-ImGui::GetContentRegionAvail().x * 0.40f); // e.g. Use 40% width for labels, leaving 60% width for framed widgets.
|
|
|
+ //ImGui::PushItemWidth(ImGui::GetFontSize() * -12); // e.g. Use XXX width for labels, leaving the rest for framed widgets.
|
|
|
|
|
|
// Menu Bar
|
|
|
DemoWindowMenuBar(&demo_data);
|
|
@@ -4426,6 +4436,17 @@ static void DemoWindowLayout()
|
|
|
}
|
|
|
ImGui::PopItemWidth();
|
|
|
|
|
|
+ ImGui::Text("SetNextItemWidth/PushItemWidth(-Min(GetContentRegionAvail().x * 0.40f, GetFontSize() * 12))");
|
|
|
+ ImGui::PushItemWidth(-IM_MIN(ImGui::GetFontSize() * 12, ImGui::GetContentRegionAvail().x * 0.40f));
|
|
|
+ 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(-FLT_MIN)");
|