Button() doesn't add frame padding an explicit size

This commit is contained in:
ocornut 2015-03-17 22:27:00 +00:00
parent 30bc952ac3
commit 2e63bf1d16

View File

@ -4110,8 +4110,8 @@ bool ImGui::Button(const char* label, const ImVec2& size_arg, bool repeat_when_h
const ImGuiID id = window->GetID(label); const ImGuiID id = window->GetID(label);
const ImVec2 label_size = CalcTextSize(label, NULL, true); const ImVec2 label_size = CalcTextSize(label, NULL, true);
const ImVec2 size(size_arg.x != 0.0f ? size_arg.x : label_size.x, size_arg.y != 0.0f ? size_arg.y : label_size.y); const ImVec2 size(size_arg.x != 0.0f ? size_arg.x : (label_size.x + style.FramePadding.x*2), size_arg.y != 0.0f ? size_arg.y : (label_size.y + style.FramePadding.y*2));
const ImGuiAabb bb(window->DC.CursorPos, window->DC.CursorPos + size + style.FramePadding*2.0f); const ImGuiAabb bb(window->DC.CursorPos, window->DC.CursorPos + size);
ItemSize(bb, style.FramePadding.y); ItemSize(bb, style.FramePadding.y);
if (!ItemAdd(bb, &id)) if (!ItemAdd(bb, &id))
return false; return false;
@ -4124,7 +4124,7 @@ bool ImGui::Button(const char* label, const ImVec2& size_arg, bool repeat_when_h
RenderFrame(bb.Min, bb.Max, col, true, style.FrameRounding); RenderFrame(bb.Min, bb.Max, col, true, style.FrameRounding);
const ImVec2 off = ImVec2(ImMax(0.0f, size.x - label_size.x) * 0.5f, ImMax(0.0f, size.y - label_size.y) * 0.5f); // Center (only applies if we explicitly gave a size bigger than the text size, which isn't the common path) const ImVec2 off = ImVec2(ImMax(0.0f, size.x - label_size.x) * 0.5f, ImMax(0.0f, size.y - label_size.y) * 0.5f); // Center (only applies if we explicitly gave a size bigger than the text size, which isn't the common path)
RenderTextClipped(bb.Min + style.FramePadding + off, label, NULL, &label_size, bb.Max); // Render clip (only applies if we explicitly gave a size smaller than the text size, which isn't the commmon path) RenderTextClipped(bb.Min + off, label, NULL, &label_size, bb.Max); // Render clip (only applies if we explicitly gave a size smaller than the text size, which isn't the commmon path)
return pressed; return pressed;
} }
@ -5584,9 +5584,9 @@ bool ImGui::InputFloat(const char* label, float *v, float step, float step_fast,
const ImGuiAabb frame_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w, label_size.y) + style.FramePadding*2.0f); const ImGuiAabb frame_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w, label_size.y) + style.FramePadding*2.0f);
ImGui::PushID(label); ImGui::PushID(label);
const float button_sz = window->FontSize(); const ImVec2 button_sz = ImVec2(window->FontSize(), window->FontSize()) + style.FramePadding * 2;
if (step > 0.0f) if (step > 0.0f)
ImGui::PushItemWidth(ImMax(1.0f, w - (button_sz + style.FramePadding.x*2.0f + style.ItemInnerSpacing.x)*2)); ImGui::PushItemWidth(ImMax(1.0f, w - (button_sz.x + style.ItemInnerSpacing.x)*2));
char buf[64]; char buf[64];
if (decimal_precision < 0) if (decimal_precision < 0)
@ -5606,13 +5606,13 @@ bool ImGui::InputFloat(const char* label, float *v, float step, float step_fast,
{ {
ImGui::PopItemWidth(); ImGui::PopItemWidth();
ImGui::SameLine(0, (int)style.ItemInnerSpacing.x); ImGui::SameLine(0, (int)style.ItemInnerSpacing.x);
if (ImGui::Button("-", ImVec2(button_sz,button_sz), true)) if (ImGui::Button("-", button_sz, true))
{ {
*v -= g.IO.KeyCtrl && step_fast > 0.0f ? step_fast : step; *v -= g.IO.KeyCtrl && step_fast > 0.0f ? step_fast : step;
value_changed = true; value_changed = true;
} }
ImGui::SameLine(0, (int)style.ItemInnerSpacing.x); ImGui::SameLine(0, (int)style.ItemInnerSpacing.x);
if (ImGui::Button("+", ImVec2(button_sz,button_sz), true)) if (ImGui::Button("+", button_sz, true))
{ {
*v += g.IO.KeyCtrl && step_fast > 0.0f ? step_fast : step; *v += g.IO.KeyCtrl && step_fast > 0.0f ? step_fast : step;
value_changed = true; value_changed = true;
@ -6707,7 +6707,7 @@ static void ItemSize(ImVec2 size, float text_offset_y)
window->DC.CursorMaxPos.x = ImMax(window->DC.CursorMaxPos.x, window->DC.CursorPosPrevLine.x); window->DC.CursorMaxPos.x = ImMax(window->DC.CursorMaxPos.x, window->DC.CursorPosPrevLine.x);
window->DC.CursorMaxPos.y = ImMax(window->DC.CursorMaxPos.y, window->DC.CursorPos.y); window->DC.CursorMaxPos.y = ImMax(window->DC.CursorMaxPos.y, window->DC.CursorPos.y);
//window->DrawList->AddCircle(window->DC.CursorMaxPos, 3.0f, 0xFF0000FF, 4); //window->DrawList->AddCircle(window->DC.CursorMaxPos, 3.0f, 0xFF0000FF, 4); // Debug
window->DC.PrevLineHeight = line_height; window->DC.PrevLineHeight = line_height;
window->DC.PrevLineTextBaseOffset = text_base_offset; window->DC.PrevLineTextBaseOffset = text_base_offset;