Calculate default item width given value passed to PushItemWidth() or SetNextItemWidth(). The SetNextItemWidth() data is generally cleared/consumed by ItemAdd() or NextItemData.ClearFlags()
| 12256 | // Calculate default item width given value passed to PushItemWidth() or SetNextItemWidth(). |
| 12257 | // The SetNextItemWidth() data is generally cleared/consumed by ItemAdd() or NextItemData.ClearFlags() |
| 12258 | float ImGui::CalcItemWidth() |
| 12259 | { |
| 12260 | ImGuiContext& g = *GImGui; |
| 12261 | ImGuiWindow* window = g.CurrentWindow; |
| 12262 | float w; |
| 12263 | if (g.NextItemData.HasFlags & ImGuiNextItemDataFlags_HasWidth) |
| 12264 | w = g.NextItemData.Width; |
| 12265 | else |
| 12266 | w = window->DC.ItemWidth; |
| 12267 | if (w < 0.0f) |
| 12268 | { |
| 12269 | float region_avail_x = GetContentRegionAvail().x; |
| 12270 | w = ImMax(1.0f, region_avail_x + w); |
| 12271 | } |
| 12272 | w = IM_TRUNC(w); |
| 12273 | return w; |
| 12274 | } |
| 12275 | |
| 12276 | // [Internal] Calculate full item size given user provided 'size' parameter and default width/height. Default width is often == CalcItemWidth(). |
| 12277 | // Those two functions CalcItemWidth vs CalcItemSize are awkwardly named because they are not fully symmetrical. |