mirror of
https://github.com/ocornut/imgui.git
synced 2024-11-12 02:00:58 +01:00
Internal: InputTextEx: tweaked a bit of code (should be a no-op)
This commit is contained in:
parent
f1f321d3f6
commit
73fa6509a5
@ -4303,7 +4303,7 @@ void ImGui::Render()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Calculate text size. Text can be multi-line. Optionally ignore text after a ## marker.
|
// Calculate text size. Text can be multi-line. Optionally ignore text after a ## marker.
|
||||||
// CalcTextSize("") should return ImVec2(0.0f, GImGui->FontSize)
|
// CalcTextSize("") should return ImVec2(0.0f, g.FontSize)
|
||||||
ImVec2 ImGui::CalcTextSize(const char* text, const char* text_end, bool hide_text_after_double_hash, float wrap_width)
|
ImVec2 ImGui::CalcTextSize(const char* text, const char* text_end, bool hide_text_after_double_hash, float wrap_width)
|
||||||
{
|
{
|
||||||
ImGuiContext& g = *GImGui;
|
ImGuiContext& g = *GImGui;
|
||||||
|
@ -3404,11 +3404,14 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_
|
|||||||
BeginGroup();
|
BeginGroup();
|
||||||
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);
|
||||||
ImVec2 size = CalcItemSize(size_arg, CalcItemWidth(), (is_multiline ? g.FontSize * 8.0f : label_size.y) + style.FramePadding.y*2.0f); // Arbitrary default of 8 lines high for multi-line
|
const ImVec2 frame_size = CalcItemSize(size_arg, CalcItemWidth(), (is_multiline ? g.FontSize * 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 ImVec2 total_size = ImVec2(frame_size.x + (label_size.x > 0.0f ? style.ItemInnerSpacing.x + label_size.x : 0.0f), frame_size.y);
|
||||||
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));
|
|
||||||
|
const ImRect frame_bb(window->DC.CursorPos, window->DC.CursorPos + frame_size);
|
||||||
|
const ImRect total_bb(frame_bb.Min, frame_bb.Min + total_size);
|
||||||
|
|
||||||
ImGuiWindow* draw_window = window;
|
ImGuiWindow* draw_window = window;
|
||||||
|
ImVec2 inner_size = frame_size;
|
||||||
if (is_multiline)
|
if (is_multiline)
|
||||||
{
|
{
|
||||||
if (!ItemAdd(total_bb, id, &frame_bb))
|
if (!ItemAdd(total_bb, id, &frame_bb))
|
||||||
@ -3423,9 +3426,9 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_
|
|||||||
EndGroup();
|
EndGroup();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
draw_window = GetCurrentWindow();
|
draw_window = g.CurrentWindow; // Child window
|
||||||
draw_window->DC.NavLayerActiveMaskNext |= draw_window->DC.NavLayerCurrentMask; // This is to ensure that EndChild() will display a navigation highlight
|
draw_window->DC.NavLayerActiveMaskNext |= draw_window->DC.NavLayerCurrentMask; // This is to ensure that EndChild() will display a navigation highlight
|
||||||
size.x -= draw_window->ScrollbarSizes.x;
|
inner_size.x -= draw_window->ScrollbarSizes.x;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -3914,7 +3917,7 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_
|
|||||||
RenderFrame(frame_bb.Min, frame_bb.Max, GetColorU32(ImGuiCol_FrameBg), true, style.FrameRounding);
|
RenderFrame(frame_bb.Min, frame_bb.Max, GetColorU32(ImGuiCol_FrameBg), true, style.FrameRounding);
|
||||||
}
|
}
|
||||||
|
|
||||||
const ImVec4 clip_rect(frame_bb.Min.x, frame_bb.Min.y, frame_bb.Min.x + size.x, frame_bb.Min.y + size.y); // Not using frame_bb.Max because we have adjusted size
|
const ImVec4 clip_rect(frame_bb.Min.x, frame_bb.Min.y, frame_bb.Min.x + inner_size.x, frame_bb.Min.y + inner_size.y); // Not using frame_bb.Max because we have adjusted size
|
||||||
ImVec2 draw_pos = is_multiline ? draw_window->DC.CursorPos : frame_bb.Min + style.FramePadding;
|
ImVec2 draw_pos = is_multiline ? draw_window->DC.CursorPos : frame_bb.Min + style.FramePadding;
|
||||||
ImVec2 text_size(0.0f, 0.0f);
|
ImVec2 text_size(0.0f, 0.0f);
|
||||||
|
|
||||||
@ -3995,7 +3998,7 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_
|
|||||||
|
|
||||||
// Store text height (note that we haven't calculated text width at all, see GitHub issues #383, #1224)
|
// Store text height (note that we haven't calculated text width at all, see GitHub issues #383, #1224)
|
||||||
if (is_multiline)
|
if (is_multiline)
|
||||||
text_size = ImVec2(size.x, line_count * g.FontSize);
|
text_size = ImVec2(inner_size.x, line_count * g.FontSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Scroll
|
// Scroll
|
||||||
@ -4004,11 +4007,11 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_
|
|||||||
// Horizontal scroll in chunks of quarter width
|
// Horizontal scroll in chunks of quarter width
|
||||||
if (!(flags & ImGuiInputTextFlags_NoHorizontalScroll))
|
if (!(flags & ImGuiInputTextFlags_NoHorizontalScroll))
|
||||||
{
|
{
|
||||||
const float scroll_increment_x = size.x * 0.25f;
|
const float scroll_increment_x = inner_size.x * 0.25f;
|
||||||
if (cursor_offset.x < state->ScrollX)
|
if (cursor_offset.x < state->ScrollX)
|
||||||
state->ScrollX = (float)(int)ImMax(0.0f, cursor_offset.x - scroll_increment_x);
|
state->ScrollX = (float)(int)ImMax(0.0f, cursor_offset.x - scroll_increment_x);
|
||||||
else if (cursor_offset.x - size.x >= state->ScrollX)
|
else if (cursor_offset.x - inner_size.x >= state->ScrollX)
|
||||||
state->ScrollX = (float)(int)(cursor_offset.x - size.x + scroll_increment_x);
|
state->ScrollX = (float)(int)(cursor_offset.x - inner_size.x + scroll_increment_x);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -4021,8 +4024,8 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_
|
|||||||
float scroll_y = draw_window->Scroll.y;
|
float scroll_y = draw_window->Scroll.y;
|
||||||
if (cursor_offset.y - g.FontSize < scroll_y)
|
if (cursor_offset.y - g.FontSize < scroll_y)
|
||||||
scroll_y = ImMax(0.0f, cursor_offset.y - g.FontSize);
|
scroll_y = ImMax(0.0f, cursor_offset.y - g.FontSize);
|
||||||
else if (cursor_offset.y - size.y >= scroll_y)
|
else if (cursor_offset.y - inner_size.y >= scroll_y)
|
||||||
scroll_y = cursor_offset.y - size.y;
|
scroll_y = cursor_offset.y - inner_size.y;
|
||||||
draw_pos.y += (draw_window->Scroll.y - scroll_y); // Manipulate cursor pos immediately avoid a frame of lag
|
draw_pos.y += (draw_window->Scroll.y - scroll_y); // Manipulate cursor pos immediately avoid a frame of lag
|
||||||
draw_window->Scroll.y = scroll_y;
|
draw_window->Scroll.y = scroll_y;
|
||||||
}
|
}
|
||||||
@ -4093,7 +4096,7 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_
|
|||||||
{
|
{
|
||||||
// Render text only (no selection, no cursor)
|
// Render text only (no selection, no cursor)
|
||||||
if (is_multiline)
|
if (is_multiline)
|
||||||
text_size = ImVec2(size.x, InputTextCalcTextLenAndLineCount(buf_display, &buf_display_end) * g.FontSize); // We don't need width
|
text_size = ImVec2(inner_size.x, InputTextCalcTextLenAndLineCount(buf_display, &buf_display_end) * g.FontSize); // We don't need width
|
||||||
else if (!is_displaying_hint && g.ActiveId == id)
|
else if (!is_displaying_hint && g.ActiveId == id)
|
||||||
buf_display_end = buf_display + state->CurLenA;
|
buf_display_end = buf_display + state->CurLenA;
|
||||||
else if (!is_displaying_hint)
|
else if (!is_displaying_hint)
|
||||||
|
Loading…
Reference in New Issue
Block a user