mirror of
https://github.com/Drezil/imgui.git
synced 2024-11-15 01:17:00 +00:00
Internals: Moved CalcItemSize next to CalcItemWidth, added comments to clarify their respective intent. Should have no side effect.
This commit is contained in:
parent
240dddff87
commit
9d4a893a77
31
imgui.cpp
31
imgui.cpp
@ -2973,19 +2973,6 @@ void ImGui::FocusableItemUnregister(ImGuiWindow* window)
|
|||||||
window->DC.FocusCounterTab--;
|
window->DC.FocusCounterTab--;
|
||||||
}
|
}
|
||||||
|
|
||||||
ImVec2 ImGui::CalcItemSize(ImVec2 size, float default_x, float default_y)
|
|
||||||
{
|
|
||||||
ImGuiContext& g = *GImGui;
|
|
||||||
ImVec2 content_max;
|
|
||||||
if (size.x < 0.0f || size.y < 0.0f)
|
|
||||||
content_max = g.CurrentWindow->Pos + GetContentRegionMax();
|
|
||||||
if (size.x <= 0.0f)
|
|
||||||
size.x = (size.x == 0.0f) ? default_x : ImMax(content_max.x - g.CurrentWindow->DC.CursorPos.x, 4.0f) + size.x;
|
|
||||||
if (size.y <= 0.0f)
|
|
||||||
size.y = (size.y == 0.0f) ? default_y : ImMax(content_max.y - g.CurrentWindow->DC.CursorPos.y, 4.0f) + size.y;
|
|
||||||
return size;
|
|
||||||
}
|
|
||||||
|
|
||||||
float ImGui::CalcWrapWidthForPos(const ImVec2& pos, float wrap_pos_x)
|
float ImGui::CalcWrapWidthForPos(const ImVec2& pos, float wrap_pos_x)
|
||||||
{
|
{
|
||||||
if (wrap_pos_x < 0.0f)
|
if (wrap_pos_x < 0.0f)
|
||||||
@ -5785,13 +5772,13 @@ void ImGui::PopItemWidth()
|
|||||||
window->DC.ItemWidth = window->DC.ItemWidthStack.empty() ? window->ItemWidthDefault : window->DC.ItemWidthStack.back();
|
window->DC.ItemWidth = window->DC.ItemWidthStack.empty() ? window->ItemWidthDefault : window->DC.ItemWidthStack.back();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Calculate default item width given value passed to PushItemWidth()
|
||||||
float ImGui::CalcItemWidth()
|
float ImGui::CalcItemWidth()
|
||||||
{
|
{
|
||||||
ImGuiWindow* window = GetCurrentWindowRead();
|
ImGuiWindow* window = GetCurrentWindowRead();
|
||||||
float w = window->DC.ItemWidth;
|
float w = window->DC.ItemWidth;
|
||||||
if (w < 0.0f)
|
if (w < 0.0f)
|
||||||
{
|
{
|
||||||
// Align to a right-side limit. We include 1 frame padding in the calculation because this is how the width is always used (we add 2 frame padding to it), but we could move that responsibility to the widget as well.
|
|
||||||
float width_to_right_edge = GetContentRegionAvail().x;
|
float width_to_right_edge = GetContentRegionAvail().x;
|
||||||
w = ImMax(1.0f, width_to_right_edge + w);
|
w = ImMax(1.0f, width_to_right_edge + w);
|
||||||
}
|
}
|
||||||
@ -5799,6 +5786,22 @@ float ImGui::CalcItemWidth()
|
|||||||
return w;
|
return w;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// [Internal] Calculate full item size given user provided 'size' parameter and default width/height. Default width is often == CalcItemWidth().
|
||||||
|
// Those two functions CalcItemWidth vs CalcItemSize are awkwardly named because they are not fully symmetrical.
|
||||||
|
// Note that only CalcItemWidth() is publicly exposed.
|
||||||
|
ImVec2 ImGui::CalcItemSize(ImVec2 size, float default_w, float default_h)
|
||||||
|
{
|
||||||
|
ImGuiWindow* window = GetCurrentWindowRead();
|
||||||
|
ImVec2 content_max;
|
||||||
|
if (size.x < 0.0f || size.y < 0.0f)
|
||||||
|
content_max = window->Pos + GetContentRegionMax();
|
||||||
|
if (size.x <= 0.0f)
|
||||||
|
size.x = (size.x == 0.0f) ? default_w : ImMax(content_max.x - window->DC.CursorPos.x, 4.0f) + size.x;
|
||||||
|
if (size.y <= 0.0f)
|
||||||
|
size.y = (size.y == 0.0f) ? default_h : ImMax(content_max.y - window->DC.CursorPos.y, 4.0f) + size.y;
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
void ImGui::SetCurrentFont(ImFont* font)
|
void ImGui::SetCurrentFont(ImFont* font)
|
||||||
{
|
{
|
||||||
ImGuiContext& g = *GImGui;
|
ImGuiContext& g = *GImGui;
|
||||||
|
@ -1438,7 +1438,7 @@ namespace ImGui
|
|||||||
IMGUI_API bool IsClippedEx(const ImRect& bb, ImGuiID id, bool clip_even_when_logged);
|
IMGUI_API bool IsClippedEx(const ImRect& bb, ImGuiID id, bool clip_even_when_logged);
|
||||||
IMGUI_API bool FocusableItemRegister(ImGuiWindow* window, ImGuiID id); // Return true if focus is requested
|
IMGUI_API bool FocusableItemRegister(ImGuiWindow* window, ImGuiID id); // Return true if focus is requested
|
||||||
IMGUI_API void FocusableItemUnregister(ImGuiWindow* window);
|
IMGUI_API void FocusableItemUnregister(ImGuiWindow* window);
|
||||||
IMGUI_API ImVec2 CalcItemSize(ImVec2 size, float default_x, float default_y);
|
IMGUI_API ImVec2 CalcItemSize(ImVec2 size, float default_w, float default_h);
|
||||||
IMGUI_API float CalcWrapWidthForPos(const ImVec2& pos, float wrap_pos_x);
|
IMGUI_API float CalcWrapWidthForPos(const ImVec2& pos, float wrap_pos_x);
|
||||||
IMGUI_API void PushMultiItemsWidths(int components, float width_full = 0.0f);
|
IMGUI_API void PushMultiItemsWidths(int components, float width_full = 0.0f);
|
||||||
IMGUI_API void PushItemFlag(ImGuiItemFlags option, bool enabled);
|
IMGUI_API void PushItemFlag(ImGuiItemFlags option, bool enabled);
|
||||||
|
@ -5440,6 +5440,9 @@ bool ImGui::Selectable(const char* label, bool* p_selected, ImGuiSelectableFlags
|
|||||||
// - ListBoxHeader()
|
// - ListBoxHeader()
|
||||||
// - ListBoxFooter()
|
// - ListBoxFooter()
|
||||||
//-------------------------------------------------------------------------
|
//-------------------------------------------------------------------------
|
||||||
|
// FIXME: This is an old API. We should redesign some of it, rename ListBoxHeader->BeginListBox, ListBoxFooter->EndListBox
|
||||||
|
// and promote using them over existing ListBox() functions, similarly to change with combo boxes.
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
|
||||||
// FIXME: In principle this function should be called BeginListBox(). We should rename it after re-evaluating if we want to keep the same signature.
|
// FIXME: In principle this function should be called BeginListBox(). We should rename it after re-evaluating if we want to keep the same signature.
|
||||||
// Helper to calculate the size of a listbox and display a label on the right.
|
// Helper to calculate the size of a listbox and display a label on the right.
|
||||||
|
Loading…
Reference in New Issue
Block a user