mirror of
https://github.com/Drezil/imgui.git
synced 2024-11-15 01:17:00 +00:00
Honoring exact width passed to PushItemWidth(), previously it would add extra FramePadding.x*2 over that width. (ref #346)
If you had manual pixel-perfect alignment in place it might affect you.
This commit is contained in:
parent
8f0f71c7ba
commit
570a9dadc4
37
imgui.cpp
37
imgui.cpp
@ -148,6 +148,7 @@
|
||||
Here is a change-log of API breaking changes, if you are using one of the functions listed, expect to have to fix some code.
|
||||
Also read releases logs https://github.com/ocornut/imgui/releases for more details.
|
||||
|
||||
- 2016/01/23 (1.48) - fixed not honoring exact width passed to PushItemWidth(), previously it would add extra FramePadding.x*2 over that width. if you had manual pixel-perfect alignment in place it might affect you.
|
||||
- 2015/12/27 (1.48) - fixed ImDrawList::AddRect() which used to render a rectangle 1 px too large on each axis.
|
||||
- 2015/12/04 (1.47) - renamed Color() helpers to ValueColor() - dangerously named, rarely used and probably to be made obsolete.
|
||||
- 2015/08/29 (1.45) - with the addition of horizontal scrollbar we made various fixes to inconsistencies with dealing with cursor position.
|
||||
@ -4271,8 +4272,8 @@ static void PushMultiItemsWidths(int components, float w_full)
|
||||
const ImGuiStyle& style = GImGui->Style;
|
||||
if (w_full <= 0.0f)
|
||||
w_full = ImGui::CalcItemWidth();
|
||||
const float w_item_one = ImMax(1.0f, (float)(int)((w_full - (style.FramePadding.x*2.0f + style.ItemInnerSpacing.x) * (components-1)) / (float)components));
|
||||
const float w_item_last = ImMax(1.0f, (float)(int)(w_full - (w_item_one + style.FramePadding.x*2.0f + style.ItemInnerSpacing.x) * (components-1)));
|
||||
const float w_item_one = ImMax(1.0f, (float)(int)((w_full - (style.ItemInnerSpacing.x) * (components-1)) / (float)components));
|
||||
const float w_item_last = ImMax(1.0f, (float)(int)(w_full - (w_item_one + style.ItemInnerSpacing.x) * (components-1)));
|
||||
window->DC.ItemWidthStack.push_back(w_item_last);
|
||||
for (int i = 0; i < components-1; i++)
|
||||
window->DC.ItemWidthStack.push_back(w_item_one);
|
||||
@ -4293,9 +4294,8 @@ float ImGui::CalcItemWidth()
|
||||
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.
|
||||
ImGuiState& g = *GImGui;
|
||||
float width_to_right_edge = ImGui::GetContentRegionAvail().x;
|
||||
w = ImMax(1.0f, width_to_right_edge + w - g.Style.FramePadding.x * 2.0f);
|
||||
w = ImMax(1.0f, width_to_right_edge + w);
|
||||
}
|
||||
w = (float)(int)w;
|
||||
return w;
|
||||
@ -5155,8 +5155,8 @@ void ImGui::LabelTextV(const char* label, const char* fmt, va_list args)
|
||||
const float w = CalcItemWidth();
|
||||
|
||||
const ImVec2 label_size = CalcTextSize(label, NULL, true);
|
||||
const ImRect value_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w + style.FramePadding.x*2, label_size.y + style.FramePadding.y*2));
|
||||
const ImRect total_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w + style.FramePadding.x*2 + (label_size.x > 0.0f ? style.ItemInnerSpacing.x : 0.0f), style.FramePadding.y*2) + label_size);
|
||||
const ImRect value_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w, label_size.y + style.FramePadding.y*2));
|
||||
const ImRect total_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w + (label_size.x > 0.0f ? style.ItemInnerSpacing.x : 0.0f), style.FramePadding.y*2) + label_size);
|
||||
ItemSize(total_bb, style.FramePadding.y);
|
||||
if (!ItemAdd(total_bb, NULL))
|
||||
return;
|
||||
@ -5957,7 +5957,7 @@ bool ImGui::InputScalarAsWidgetReplacement(const ImRect& aabb, const char* label
|
||||
|
||||
char buf[32];
|
||||
DataTypeFormatString(data_type, data_ptr, decimal_precision, buf, IM_ARRAYSIZE(buf));
|
||||
bool value_changed = InputTextEx(label, buf, IM_ARRAYSIZE(buf), aabb.GetSize() - g.Style.FramePadding*2.0f, ImGuiInputTextFlags_CharsDecimal | ImGuiInputTextFlags_AutoSelectAll);
|
||||
bool value_changed = InputTextEx(label, buf, IM_ARRAYSIZE(buf), aabb.GetSize(), ImGuiInputTextFlags_CharsDecimal | ImGuiInputTextFlags_AutoSelectAll);
|
||||
if (g.ScalarAsInputTextId == 0)
|
||||
{
|
||||
// First frame
|
||||
@ -6158,7 +6158,7 @@ bool ImGui::SliderFloat(const char* label, float* v, float v_min, float v_max, c
|
||||
const float w = CalcItemWidth();
|
||||
|
||||
const ImVec2 label_size = CalcTextSize(label, NULL, true);
|
||||
const ImRect frame_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w, label_size.y) + style.FramePadding*2.0f);
|
||||
const ImRect frame_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w, label_size.y + style.FramePadding.y*2.0f));
|
||||
const ImRect total_bb(frame_bb.Min, frame_bb.Max + ImVec2(label_size.x > 0.0f ? style.ItemInnerSpacing.x + label_size.x : 0.0f, 0.0f));
|
||||
|
||||
// NB- we don't call ItemSize() yet because we may turn into a text edit box below
|
||||
@ -6249,7 +6249,6 @@ bool ImGui::VSliderFloat(const char* label, const ImVec2& size, float* v, float
|
||||
char value_buf[64];
|
||||
char* value_buf_end = value_buf + ImFormatString(value_buf, IM_ARRAYSIZE(value_buf), display_format, *v);
|
||||
RenderTextClipped(ImVec2(frame_bb.Min.x, frame_bb.Min.y + style.FramePadding.y), frame_bb.Max, value_buf, value_buf_end, NULL, ImGuiAlign_Center);
|
||||
|
||||
if (label_size.x > 0.0f)
|
||||
RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, frame_bb.Min.y + style.FramePadding.y), label);
|
||||
|
||||
@ -6456,7 +6455,7 @@ bool ImGui::DragFloat(const char* label, float* v, float v_speed, float v_min, f
|
||||
const float w = CalcItemWidth();
|
||||
|
||||
const ImVec2 label_size = CalcTextSize(label, NULL, true);
|
||||
const ImRect frame_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w, label_size.y) + style.FramePadding*2.0f);
|
||||
const ImRect frame_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w, label_size.y + style.FramePadding.y*2.0f));
|
||||
const ImRect inner_bb(frame_bb.Min + style.FramePadding, frame_bb.Max - style.FramePadding);
|
||||
const ImRect total_bb(frame_bb.Min, frame_bb.Max + ImVec2(label_size.x > 0.0f ? style.ItemInnerSpacing.x + label_size.x : 0.0f, 0.0f));
|
||||
|
||||
@ -6663,7 +6662,7 @@ void ImGui::PlotEx(ImGuiPlotType plot_type, const char* label, float (*values_ge
|
||||
|
||||
const ImVec2 label_size = CalcTextSize(label, NULL, true);
|
||||
if (graph_size.x == 0.0f)
|
||||
graph_size.x = CalcItemWidth() + (style.FramePadding.x * 2);
|
||||
graph_size.x = CalcItemWidth();
|
||||
if (graph_size.y == 0.0f)
|
||||
graph_size.y = label_size.y + (style.FramePadding.y * 2);
|
||||
|
||||
@ -6804,7 +6803,7 @@ void ImGui::ProgressBar(float fraction, const ImVec2& size_arg, const char* over
|
||||
const ImGuiStyle& style = g.Style;
|
||||
|
||||
ImVec2 pos = window->DC.CursorPos;
|
||||
const ImRect bb(pos, pos + CalcItemSize(size_arg, CalcItemWidth() + style.FramePadding.x*2.0f, g.FontSize + style.FramePadding.y*2.0f));
|
||||
const ImRect bb(pos, pos + CalcItemSize(size_arg, CalcItemWidth(), g.FontSize + style.FramePadding.y*2.0f));
|
||||
ItemSize(bb, style.FramePadding.y);
|
||||
if (!ItemAdd(bb, NULL))
|
||||
return;
|
||||
@ -7215,9 +7214,9 @@ bool ImGui::InputTextEx(const char* label, char* buf, int buf_size, const ImVec2
|
||||
const bool is_editable = (flags & ImGuiInputTextFlags_ReadOnly) == 0;
|
||||
const bool is_password = (flags & ImGuiInputTextFlags_Password) != 0;
|
||||
|
||||
const ImVec2 label_size = ImGui::CalcTextSize(label, NULL, true);
|
||||
ImVec2 size = CalcItemSize(size_arg, CalcItemWidth(), is_multiline ? ImGui::GetTextLineHeight() * 8.0f : label_size.y); // Arbitrary default of 8 lines high for multi-line
|
||||
const ImRect frame_bb(window->DC.CursorPos, window->DC.CursorPos + size + style.FramePadding*2.0f);
|
||||
const ImVec2 label_size = CalcTextSize(label, NULL, true);
|
||||
ImVec2 size = CalcItemSize(size_arg, CalcItemWidth(), (is_multiline ? ImGui::GetTextLineHeight() * 8.0f : label_size.y) + style.FramePadding.y*2.0f); // Arbitrary default of 8 lines high for multi-line
|
||||
const ImRect frame_bb(window->DC.CursorPos, window->DC.CursorPos + size);
|
||||
const ImRect total_bb(frame_bb.Min, frame_bb.Max + ImVec2(label_size.x > 0.0f ? (style.ItemInnerSpacing.x + label_size.x) : 0.0f, 0.0f));
|
||||
|
||||
ImGuiWindow* draw_window = window;
|
||||
@ -7984,7 +7983,7 @@ bool ImGui::Combo(const char* label, int* current_item, bool (*items_getter)(voi
|
||||
const float w = CalcItemWidth();
|
||||
|
||||
const ImVec2 label_size = CalcTextSize(label, NULL, true);
|
||||
const ImRect frame_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w, label_size.y) + style.FramePadding*2.0f);
|
||||
const ImRect frame_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w, label_size.y + style.FramePadding.y*2.0f));
|
||||
const ImRect total_bb(frame_bb.Min, frame_bb.Max + ImVec2(label_size.x > 0.0f ? style.ItemInnerSpacing.x + label_size.x : 0.0f, 0.0f));
|
||||
ItemSize(total_bb, style.FramePadding.y);
|
||||
if (!ItemAdd(total_bb, &id))
|
||||
@ -8173,7 +8172,7 @@ bool ImGui::ListBoxHeader(const char* label, const ImVec2& size_arg)
|
||||
const ImVec2 label_size = CalcTextSize(label, NULL, true);
|
||||
|
||||
// Size default to hold ~7 items. Fractional number of items helps seeing that we can scroll down/up without looking at scrollbar.
|
||||
ImVec2 size = CalcItemSize(size_arg, CalcItemWidth() + style.FramePadding.x * 2.0f, ImGui::GetTextLineHeightWithSpacing() * 7.4f + style.ItemSpacing.y);
|
||||
ImVec2 size = CalcItemSize(size_arg, CalcItemWidth(), ImGui::GetTextLineHeightWithSpacing() * 7.4f + style.ItemSpacing.y);
|
||||
ImVec2 frame_size = ImVec2(size.x, ImMax(size.y, label_size.y));
|
||||
ImRect frame_bb(window->DC.CursorPos, window->DC.CursorPos + frame_size);
|
||||
ImRect bb(frame_bb.Min, frame_bb.Max + ImVec2(label_size.x > 0.0f ? style.ItemInnerSpacing.x + label_size.x : 0.0f, 0.0f));
|
||||
@ -8542,8 +8541,8 @@ bool ImGui::ColorEdit4(const char* label, float col[4], bool alpha)
|
||||
{
|
||||
// RGB/HSV 0..255 Sliders
|
||||
const float w_items_all = w_full - (square_sz + style.ItemInnerSpacing.x);
|
||||
const float w_item_one = ImMax(1.0f, (float)(int)((w_items_all - (style.FramePadding.x*2.0f + style.ItemInnerSpacing.x) * (components-1)) / (float)components));
|
||||
const float w_item_last = ImMax(1.0f, (float)(int)(w_items_all - (w_item_one + style.FramePadding.x*2.0f + style.ItemInnerSpacing.x) * (components-1)));
|
||||
const float w_item_one = ImMax(1.0f, (float)(int)((w_items_all - (style.ItemInnerSpacing.x) * (components-1)) / (float)components));
|
||||
const float w_item_last = ImMax(1.0f, (float)(int)(w_items_all - (w_item_one + style.ItemInnerSpacing.x) * (components-1)));
|
||||
|
||||
const bool hide_prefix = (w_item_one <= CalcTextSize("M:999").x);
|
||||
const char* ids[4] = { "##X", "##Y", "##Z", "##W" };
|
||||
|
Loading…
Reference in New Issue
Block a user