mirror of
https://github.com/Drezil/imgui.git
synced 2025-07-06 04:58:47 +02:00
Merge branch 'master' into docking
# Conflicts: # imgui.cpp # imgui_internal.h
This commit is contained in:
@ -132,7 +132,7 @@ static ImVec2 InputTextCalcTextSizeW(const ImWchar* text_begin, const
|
||||
// - BulletTextV()
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
void ImGui::TextUnformatted(const char* text, const char* text_end)
|
||||
void ImGui::TextEx(const char* text, const char* text_end, ImGuiTextFlags flags)
|
||||
{
|
||||
ImGuiWindow* window = GetCurrentWindow();
|
||||
if (window->SkipItems)
|
||||
@ -146,7 +146,7 @@ void ImGui::TextUnformatted(const char* text, const char* text_end)
|
||||
|
||||
const ImVec2 text_pos(window->DC.CursorPos.x, window->DC.CursorPos.y + window->DC.CurrentLineTextBaseOffset);
|
||||
const float wrap_pos_x = window->DC.TextWrapPos;
|
||||
const bool wrap_enabled = wrap_pos_x >= 0.0f;
|
||||
const bool wrap_enabled = (wrap_pos_x >= 0.0f);
|
||||
if (text_end - text > 2000 && !wrap_enabled)
|
||||
{
|
||||
// Long text!
|
||||
@ -156,69 +156,66 @@ void ImGui::TextUnformatted(const char* text, const char* text_end)
|
||||
// - We use memchr(), pay attention that well optimized versions of those str/mem functions are much faster than a casually written loop.
|
||||
const char* line = text;
|
||||
const float line_height = GetTextLineHeight();
|
||||
const ImRect clip_rect = window->ClipRect;
|
||||
ImVec2 text_size(0,0);
|
||||
|
||||
if (text_pos.y <= clip_rect.Max.y)
|
||||
// Lines to skip (can't skip when logging text)
|
||||
ImVec2 pos = text_pos;
|
||||
if (!g.LogEnabled)
|
||||
{
|
||||
ImVec2 pos = text_pos;
|
||||
|
||||
// Lines to skip (can't skip when logging text)
|
||||
if (!g.LogEnabled)
|
||||
int lines_skippable = (int)((window->ClipRect.Min.y - text_pos.y) / line_height);
|
||||
if (lines_skippable > 0)
|
||||
{
|
||||
int lines_skippable = (int)((clip_rect.Min.y - text_pos.y) / line_height);
|
||||
if (lines_skippable > 0)
|
||||
{
|
||||
int lines_skipped = 0;
|
||||
while (line < text_end && lines_skipped < lines_skippable)
|
||||
{
|
||||
const char* line_end = (const char*)memchr(line, '\n', text_end - line);
|
||||
if (!line_end)
|
||||
line_end = text_end;
|
||||
line = line_end + 1;
|
||||
lines_skipped++;
|
||||
}
|
||||
pos.y += lines_skipped * line_height;
|
||||
}
|
||||
}
|
||||
|
||||
// Lines to render
|
||||
if (line < text_end)
|
||||
{
|
||||
ImRect line_rect(pos, pos + ImVec2(FLT_MAX, line_height));
|
||||
while (line < text_end)
|
||||
{
|
||||
if (IsClippedEx(line_rect, 0, false))
|
||||
break;
|
||||
|
||||
const char* line_end = (const char*)memchr(line, '\n', text_end - line);
|
||||
if (!line_end)
|
||||
line_end = text_end;
|
||||
const ImVec2 line_size = CalcTextSize(line, line_end, false);
|
||||
text_size.x = ImMax(text_size.x, line_size.x);
|
||||
RenderText(pos, line, line_end, false);
|
||||
line = line_end + 1;
|
||||
line_rect.Min.y += line_height;
|
||||
line_rect.Max.y += line_height;
|
||||
pos.y += line_height;
|
||||
}
|
||||
|
||||
// Count remaining lines
|
||||
int lines_skipped = 0;
|
||||
while (line < text_end)
|
||||
while (line < text_end && lines_skipped < lines_skippable)
|
||||
{
|
||||
const char* line_end = (const char*)memchr(line, '\n', text_end - line);
|
||||
if (!line_end)
|
||||
line_end = text_end;
|
||||
if ((flags & ImGuiTextFlags_NoWidthForLargeClippedText) == 0)
|
||||
text_size.x = ImMax(text_size.x, CalcTextSize(line, line_end).x);
|
||||
line = line_end + 1;
|
||||
lines_skipped++;
|
||||
}
|
||||
pos.y += lines_skipped * line_height;
|
||||
}
|
||||
|
||||
text_size.y += (pos - text_pos).y;
|
||||
}
|
||||
|
||||
// Lines to render
|
||||
if (line < text_end)
|
||||
{
|
||||
ImRect line_rect(pos, pos + ImVec2(FLT_MAX, line_height));
|
||||
while (line < text_end)
|
||||
{
|
||||
if (IsClippedEx(line_rect, 0, false))
|
||||
break;
|
||||
|
||||
const char* line_end = (const char*)memchr(line, '\n', text_end - line);
|
||||
if (!line_end)
|
||||
line_end = text_end;
|
||||
text_size.x = ImMax(text_size.x, CalcTextSize(line, line_end).x);
|
||||
RenderText(pos, line, line_end, false);
|
||||
line = line_end + 1;
|
||||
line_rect.Min.y += line_height;
|
||||
line_rect.Max.y += line_height;
|
||||
pos.y += line_height;
|
||||
}
|
||||
|
||||
// Count remaining lines
|
||||
int lines_skipped = 0;
|
||||
while (line < text_end)
|
||||
{
|
||||
const char* line_end = (const char*)memchr(line, '\n', text_end - line);
|
||||
if (!line_end)
|
||||
line_end = text_end;
|
||||
if ((flags & ImGuiTextFlags_NoWidthForLargeClippedText) == 0)
|
||||
text_size.x = ImMax(text_size.x, CalcTextSize(line, line_end).x);
|
||||
line = line_end + 1;
|
||||
lines_skipped++;
|
||||
}
|
||||
pos.y += lines_skipped * line_height;
|
||||
}
|
||||
text_size.y = (pos - text_pos).y;
|
||||
|
||||
ImRect bb(text_pos, text_pos + text_size);
|
||||
ItemSize(text_size);
|
||||
ItemAdd(bb, 0);
|
||||
@ -228,7 +225,6 @@ void ImGui::TextUnformatted(const char* text, const char* text_end)
|
||||
const float wrap_width = wrap_enabled ? CalcWrapWidthForPos(window->DC.CursorPos, wrap_pos_x) : 0.0f;
|
||||
const ImVec2 text_size = CalcTextSize(text_begin, text_end, false, wrap_width);
|
||||
|
||||
// Account of baseline offset
|
||||
ImRect bb(text_pos, text_pos + text_size);
|
||||
ItemSize(text_size);
|
||||
if (!ItemAdd(bb, 0))
|
||||
@ -239,6 +235,11 @@ void ImGui::TextUnformatted(const char* text, const char* text_end)
|
||||
}
|
||||
}
|
||||
|
||||
void ImGui::TextUnformatted(const char* text, const char* text_end)
|
||||
{
|
||||
TextEx(text, text_end, ImGuiTextFlags_NoWidthForLargeClippedText);
|
||||
}
|
||||
|
||||
void ImGui::Text(const char* fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
@ -255,7 +256,7 @@ void ImGui::TextV(const char* fmt, va_list args)
|
||||
|
||||
ImGuiContext& g = *GImGui;
|
||||
const char* text_end = g.TempBuffer + ImFormatStringV(g.TempBuffer, IM_ARRAYSIZE(g.TempBuffer), fmt, args);
|
||||
TextUnformatted(g.TempBuffer, text_end);
|
||||
TextEx(g.TempBuffer, text_end, ImGuiTextFlags_NoWidthForLargeClippedText);
|
||||
}
|
||||
|
||||
void ImGui::TextColored(const ImVec4& col, const char* fmt, ...)
|
||||
@ -1980,14 +1981,14 @@ bool ImGui::DragScalar(const char* label, ImGuiDataType data_type, void* v, floa
|
||||
|
||||
// Tabbing or CTRL-clicking on Drag turns it into an input box
|
||||
bool start_text_input = false;
|
||||
const bool tab_focus_requested = FocusableItemRegister(window, id);
|
||||
if (tab_focus_requested || (hovered && (g.IO.MouseClicked[0] || g.IO.MouseDoubleClicked[0])) || g.NavActivateId == id || (g.NavInputId == id && g.ScalarAsInputTextId != id))
|
||||
const bool focus_requested = FocusableItemRegister(window, id);
|
||||
if (focus_requested || (hovered && (g.IO.MouseClicked[0] || g.IO.MouseDoubleClicked[0])) || g.NavActivateId == id || (g.NavInputId == id && g.ScalarAsInputTextId != id))
|
||||
{
|
||||
SetActiveID(id, window);
|
||||
SetFocusID(id, window);
|
||||
FocusWindow(window);
|
||||
g.ActiveIdAllowNavDirFlags = (1 << ImGuiDir_Up) | (1 << ImGuiDir_Down);
|
||||
if (tab_focus_requested || g.IO.KeyCtrl || g.IO.MouseDoubleClicked[0] || g.NavInputId == id)
|
||||
if (focus_requested || g.IO.KeyCtrl || g.IO.MouseDoubleClicked[0] || g.NavInputId == id)
|
||||
{
|
||||
start_text_input = true;
|
||||
g.ScalarAsInputTextId = 0;
|
||||
@ -2045,7 +2046,7 @@ bool ImGui::DragScalarN(const char* label, ImGuiDataType data_type, void* v, int
|
||||
}
|
||||
PopID();
|
||||
|
||||
TextUnformatted(label, FindRenderedTextEnd(label));
|
||||
TextEx(label, FindRenderedTextEnd(label));
|
||||
EndGroup();
|
||||
return value_changed;
|
||||
}
|
||||
@ -2088,7 +2089,7 @@ bool ImGui::DragFloatRange2(const char* label, float* v_current_min, float* v_cu
|
||||
PopItemWidth();
|
||||
SameLine(0, g.Style.ItemInnerSpacing.x);
|
||||
|
||||
TextUnformatted(label, FindRenderedTextEnd(label));
|
||||
TextEx(label, FindRenderedTextEnd(label));
|
||||
EndGroup();
|
||||
PopID();
|
||||
return value_changed;
|
||||
@ -2133,7 +2134,7 @@ bool ImGui::DragIntRange2(const char* label, int* v_current_min, int* v_current_
|
||||
PopItemWidth();
|
||||
SameLine(0, g.Style.ItemInnerSpacing.x);
|
||||
|
||||
TextUnformatted(label, FindRenderedTextEnd(label));
|
||||
TextEx(label, FindRenderedTextEnd(label));
|
||||
EndGroup();
|
||||
PopID();
|
||||
|
||||
@ -2415,15 +2416,15 @@ bool ImGui::SliderScalar(const char* label, ImGuiDataType data_type, void* v, co
|
||||
|
||||
// Tabbing or CTRL-clicking on Slider turns it into an input box
|
||||
bool start_text_input = false;
|
||||
const bool tab_focus_requested = FocusableItemRegister(window, id);
|
||||
const bool focus_requested = FocusableItemRegister(window, id);
|
||||
const bool hovered = ItemHoverable(frame_bb, id);
|
||||
if (tab_focus_requested || (hovered && g.IO.MouseClicked[0]) || g.NavActivateId == id || (g.NavInputId == id && g.ScalarAsInputTextId != id))
|
||||
if (focus_requested || (hovered && g.IO.MouseClicked[0]) || g.NavActivateId == id || (g.NavInputId == id && g.ScalarAsInputTextId != id))
|
||||
{
|
||||
SetActiveID(id, window);
|
||||
SetFocusID(id, window);
|
||||
FocusWindow(window);
|
||||
g.ActiveIdAllowNavDirFlags = (1 << ImGuiDir_Up) | (1 << ImGuiDir_Down);
|
||||
if (tab_focus_requested || g.IO.KeyCtrl || g.NavInputId == id)
|
||||
if (focus_requested || g.IO.KeyCtrl || g.NavInputId == id)
|
||||
{
|
||||
start_text_input = true;
|
||||
g.ScalarAsInputTextId = 0;
|
||||
@ -2486,7 +2487,7 @@ bool ImGui::SliderScalarN(const char* label, ImGuiDataType data_type, void* v, i
|
||||
}
|
||||
PopID();
|
||||
|
||||
TextUnformatted(label, FindRenderedTextEnd(label));
|
||||
TextEx(label, FindRenderedTextEnd(label));
|
||||
EndGroup();
|
||||
return value_changed;
|
||||
}
|
||||
@ -2785,7 +2786,7 @@ bool ImGui::InputScalar(const char* label, ImGuiDataType data_type, void* data_p
|
||||
value_changed = true;
|
||||
}
|
||||
SameLine(0, style.ItemInnerSpacing.x);
|
||||
TextUnformatted(label, FindRenderedTextEnd(label));
|
||||
TextEx(label, FindRenderedTextEnd(label));
|
||||
style.FramePadding = backup_frame_padding;
|
||||
|
||||
PopID();
|
||||
@ -2823,7 +2824,7 @@ bool ImGui::InputScalarN(const char* label, ImGuiDataType data_type, void* v, in
|
||||
}
|
||||
PopID();
|
||||
|
||||
TextUnformatted(label, FindRenderedTextEnd(label));
|
||||
TextEx(label, FindRenderedTextEnd(label));
|
||||
EndGroup();
|
||||
return value_changed;
|
||||
}
|
||||
@ -3304,8 +3305,8 @@ bool ImGui::InputTextEx(const char* label, char* buf, int buf_size, const ImVec2
|
||||
if (g.InputTextState.ID == id)
|
||||
state = &g.InputTextState;
|
||||
|
||||
const bool focus_requested = FocusableItemRegister(window, id, (flags & (ImGuiInputTextFlags_CallbackCompletion|ImGuiInputTextFlags_AllowTabInput)) == 0); // Using completion callback disable keyboard tabbing
|
||||
const bool focus_requested_by_code = focus_requested && (window->FocusIdxAllCounter == window->FocusIdxAllRequestCurrent);
|
||||
const bool focus_requested = FocusableItemRegister(window, id);
|
||||
const bool focus_requested_by_code = focus_requested && (g.FocusRequestCurrWindow == window && g.FocusRequestCurrCounterAll == window->DC.FocusCounterAll);
|
||||
const bool focus_requested_by_tab = focus_requested && !focus_requested_by_code;
|
||||
|
||||
const bool user_clicked = hovered && io.MouseClicked[0];
|
||||
@ -3367,7 +3368,10 @@ bool ImGui::InputTextEx(const char* label, char* buf, int buf_size, const ImVec2
|
||||
SetActiveID(id, window);
|
||||
SetFocusID(id, window);
|
||||
FocusWindow(window);
|
||||
IM_ASSERT(ImGuiNavInput_COUNT < 32);
|
||||
g.ActiveIdBlockNavInputFlags = (1 << ImGuiNavInput_Cancel);
|
||||
if (flags & (ImGuiInputTextFlags_CallbackCompletion | ImGuiInputTextFlags_AllowTabInput)) // Disable keyboard tabbing out
|
||||
g.ActiveIdBlockNavInputFlags |= (1 << ImGuiNavInput_KeyTab_);
|
||||
if (!is_multiline && !(flags & ImGuiInputTextFlags_CallbackHistory))
|
||||
g.ActiveIdAllowNavDirFlags = ((1 << ImGuiDir_Up) | (1 << ImGuiDir_Down));
|
||||
}
|
||||
@ -4117,7 +4121,7 @@ bool ImGui::ColorEdit4(const char* label, float col[4], ImGuiColorEditFlags flag
|
||||
picker_active_window = g.CurrentWindow;
|
||||
if (label != label_display_end)
|
||||
{
|
||||
TextUnformatted(label, label_display_end);
|
||||
TextEx(label, label_display_end);
|
||||
Spacing();
|
||||
}
|
||||
ImGuiColorEditFlags picker_flags_to_forward = ImGuiColorEditFlags__DataTypeMask | ImGuiColorEditFlags__PickerMask | ImGuiColorEditFlags_HDR | ImGuiColorEditFlags_NoAlpha | ImGuiColorEditFlags_AlphaBar;
|
||||
@ -4132,7 +4136,7 @@ bool ImGui::ColorEdit4(const char* label, float col[4], ImGuiColorEditFlags flag
|
||||
if (label != label_display_end && !(flags & ImGuiColorEditFlags_NoLabel))
|
||||
{
|
||||
SameLine(0, style.ItemInnerSpacing.x);
|
||||
TextUnformatted(label, label_display_end);
|
||||
TextEx(label, label_display_end);
|
||||
}
|
||||
|
||||
// Convert back
|
||||
@ -4392,7 +4396,7 @@ bool ImGui::ColorPicker4(const char* label, float col[4], ImGuiColorEditFlags fl
|
||||
{
|
||||
if ((flags & ImGuiColorEditFlags_NoSidePreview))
|
||||
SameLine(0, style.ItemInnerSpacing.x);
|
||||
TextUnformatted(label, label_display_end);
|
||||
TextEx(label, label_display_end);
|
||||
}
|
||||
}
|
||||
|
||||
@ -4620,7 +4624,7 @@ bool ImGui::ColorButton(const char* desc_id, const ImVec4& col, ImGuiColorEditFl
|
||||
SetDragDropPayload(IMGUI_PAYLOAD_TYPE_COLOR_4F, &col, sizeof(float) * 4, ImGuiCond_Once);
|
||||
ColorButton(desc_id, col, flags);
|
||||
SameLine();
|
||||
TextUnformatted("Color");
|
||||
TextEx("Color");
|
||||
EndDragDropSource();
|
||||
}
|
||||
|
||||
@ -4661,7 +4665,7 @@ void ImGui::ColorTooltip(const char* text, const float* col, ImGuiColorEditFlags
|
||||
const char* text_end = text ? FindRenderedTextEnd(text, NULL) : text;
|
||||
if (text_end > text)
|
||||
{
|
||||
TextUnformatted(text, text_end);
|
||||
TextEx(text, text_end);
|
||||
Separator();
|
||||
}
|
||||
|
||||
@ -5209,7 +5213,20 @@ bool ImGui::Selectable(const char* label, bool selected, ImGuiSelectableFlags fl
|
||||
bb.Min.y -= spacing_U;
|
||||
bb.Max.x += spacing_R;
|
||||
bb.Max.y += spacing_D;
|
||||
if (!ItemAdd(bb, id))
|
||||
|
||||
bool item_add;
|
||||
if (flags & ImGuiSelectableFlags_Disabled)
|
||||
{
|
||||
ImGuiItemFlags backup_item_flags = window->DC.ItemFlags;
|
||||
window->DC.ItemFlags |= ImGuiItemFlags_NoNav | ImGuiItemFlags_NoNavDefaultFocus;
|
||||
item_add = ItemAdd(bb, id);
|
||||
window->DC.ItemFlags = backup_item_flags;
|
||||
}
|
||||
else
|
||||
{
|
||||
item_add = ItemAdd(bb, id);
|
||||
}
|
||||
if (!item_add)
|
||||
{
|
||||
if ((flags & ImGuiSelectableFlags_SpanAllColumns) && window->DC.ColumnsSet)
|
||||
PushColumnClipRect();
|
||||
|
Reference in New Issue
Block a user