Internal: Text: Extracted TextUnformatted into TextEx over which we can freely atter the signature. Clarified current large text behavior of TextUnformatted with explicit ImGuiTextFlags_NoWidthForLargeClippedText flag (always set).

docking
omar 6 years ago
parent 622a27506a
commit 1ed3c4cf4a

@ -138,6 +138,7 @@ It's mostly a bunch of personal notes, probably incomplete. Feel free to query i
- image/image button: misalignment on padded/bordered button? - image/image button: misalignment on padded/bordered button?
- image/image button: parameters are confusing, image() has tint_col,border_col whereas imagebutton() has bg_col/tint_col. Even thou they are different parameters ordering could be more consistent. can we fix that? - image/image button: parameters are confusing, image() has tint_col,border_col whereas imagebutton() has bg_col/tint_col. Even thou they are different parameters ordering could be more consistent. can we fix that?
- image button: not taking an explicit id is odd. - image button: not taking an explicit id is odd.
- slider/drag: ctrl+click when format doesn't include a % character.. disable? display underlying value in default format? (see InputScalarAsWidgetReplacement)
- slider: allow using the [-]/[+] buttons used by InputFloat()/InputInt() - slider: allow using the [-]/[+] buttons used by InputFloat()/InputInt()
- slider: initial absolute click is imprecise. change to relative movement slider (same as scrollbar). (#1946) - slider: initial absolute click is imprecise. change to relative movement slider (same as scrollbar). (#1946)
- slider: add dragging-based widgets to edit values with mouse (on 2 axises), saving screen real-estate. - slider: add dragging-based widgets to edit values with mouse (on 2 axises), saving screen real-estate.
@ -249,6 +250,7 @@ It's mostly a bunch of personal notes, probably incomplete. Feel free to query i
- font: finish CustomRectRegister() to allow mapping Unicode codepoint to custom texture data - font: finish CustomRectRegister() to allow mapping Unicode codepoint to custom texture data
- font: PushFontSize API (#1018) - font: PushFontSize API (#1018)
- font: MemoryTTF taking ownership confusing/not obvious, maybe default should be opposite? - font: MemoryTTF taking ownership confusing/not obvious, maybe default should be opposite?
- font: storing MinAdvanceX per font would allow us to skip calculating line width (under a threshold of character count) in loops looking for block width
- font/demo: add tools to show glyphs used by a text blob, display U16 value, list missing glyphs. - font/demo: add tools to show glyphs used by a text blob, display U16 value, list missing glyphs.
- font/demo: demonstrate use of ImFontGlyphRangesBuilder. - font/demo: demonstrate use of ImFontGlyphRangesBuilder.
- font/atlas: add a missing Glyphs.reserve() - font/atlas: add a missing Glyphs.reserve()

@ -83,6 +83,7 @@ struct ImGuiWindowSettings; // Storage for window settings stored in .in
// Use your programming IDE "Go to definition" facility on the names of the center columns to find the actual flags/enum lists. // Use your programming IDE "Go to definition" facility on the names of the center columns to find the actual flags/enum lists.
typedef int ImGuiLayoutType; // -> enum ImGuiLayoutType_ // Enum: Horizontal or vertical typedef int ImGuiLayoutType; // -> enum ImGuiLayoutType_ // Enum: Horizontal or vertical
typedef int ImGuiButtonFlags; // -> enum ImGuiButtonFlags_ // Flags: for ButtonEx(), ButtonBehavior() typedef int ImGuiButtonFlags; // -> enum ImGuiButtonFlags_ // Flags: for ButtonEx(), ButtonBehavior()
typedef int ImGuiDragFlags; // -> enum ImGuiDragFlags_ // Flags: for DragBehavior()
typedef int ImGuiItemFlags; // -> enum ImGuiItemFlags_ // Flags: for PushItemFlag() typedef int ImGuiItemFlags; // -> enum ImGuiItemFlags_ // Flags: for PushItemFlag()
typedef int ImGuiItemStatusFlags; // -> enum ImGuiItemStatusFlags_ // Flags: for DC.LastItemStatusFlags typedef int ImGuiItemStatusFlags; // -> enum ImGuiItemStatusFlags_ // Flags: for DC.LastItemStatusFlags
typedef int ImGuiNavHighlightFlags; // -> enum ImGuiNavHighlightFlags_ // Flags: for RenderNavHighlight() typedef int ImGuiNavHighlightFlags; // -> enum ImGuiNavHighlightFlags_ // Flags: for RenderNavHighlight()
@ -90,7 +91,7 @@ typedef int ImGuiNavDirSourceFlags; // -> enum ImGuiNavDirSourceFlags_ // Flags:
typedef int ImGuiNavMoveFlags; // -> enum ImGuiNavMoveFlags_ // Flags: for navigation requests typedef int ImGuiNavMoveFlags; // -> enum ImGuiNavMoveFlags_ // Flags: for navigation requests
typedef int ImGuiSeparatorFlags; // -> enum ImGuiSeparatorFlags_ // Flags: for Separator() - internal typedef int ImGuiSeparatorFlags; // -> enum ImGuiSeparatorFlags_ // Flags: for Separator() - internal
typedef int ImGuiSliderFlags; // -> enum ImGuiSliderFlags_ // Flags: for SliderBehavior() typedef int ImGuiSliderFlags; // -> enum ImGuiSliderFlags_ // Flags: for SliderBehavior()
typedef int ImGuiDragFlags; // -> enum ImGuiDragFlags_ // Flags: for DragBehavior() typedef int ImGuiTextFlags; // -> enum ImGuiTextFlags_ // Flags: for TextEx()
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
// STB libraries includes // STB libraries includes
@ -381,6 +382,12 @@ enum ImGuiItemStatusFlags_
#endif #endif
}; };
enum ImGuiTextFlags_
{
ImGuiTextFlags_None = 0,
ImGuiTextFlags_NoWidthForLargeClippedText = 1 << 0
};
// FIXME: this is in development, not exposed/functional as a generic feature yet. // FIXME: this is in development, not exposed/functional as a generic feature yet.
// Horizontal/Vertical enums are fixed to 0/1 so they may be used to index ImVec2 // Horizontal/Vertical enums are fixed to 0/1 so they may be used to index ImVec2
enum ImGuiLayoutType_ enum ImGuiLayoutType_
@ -1501,6 +1508,7 @@ namespace ImGui
IMGUI_API void RenderPixelEllipsis(ImDrawList* draw_list, ImVec2 pos, int count, ImU32 col); IMGUI_API void RenderPixelEllipsis(ImDrawList* draw_list, ImVec2 pos, int count, ImU32 col);
// Widgets // Widgets
IMGUI_API void TextEx(const char* text, const char* text_end = NULL, ImGuiTextFlags flags = 0);
IMGUI_API bool ButtonEx(const char* label, const ImVec2& size_arg = ImVec2(0,0), ImGuiButtonFlags flags = 0); IMGUI_API bool ButtonEx(const char* label, const ImVec2& size_arg = ImVec2(0,0), ImGuiButtonFlags flags = 0);
IMGUI_API bool CloseButton(ImGuiID id, const ImVec2& pos, float radius); IMGUI_API bool CloseButton(ImGuiID id, const ImVec2& pos, float radius);
IMGUI_API bool CollapseButton(ImGuiID id, const ImVec2& pos); IMGUI_API bool CollapseButton(ImGuiID id, const ImVec2& pos);

@ -132,7 +132,7 @@ static ImVec2 InputTextCalcTextSizeW(const ImWchar* text_begin, const
// - BulletTextV() // - 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(); ImGuiWindow* window = GetCurrentWindow();
if (window->SkipItems) 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 ImVec2 text_pos(window->DC.CursorPos.x, window->DC.CursorPos.y + window->DC.CurrentLineTextBaseOffset);
const float wrap_pos_x = window->DC.TextWrapPos; 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) if (text_end - text > 2000 && !wrap_enabled)
{ {
// Long text! // Long text!
@ -156,14 +156,13 @@ 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. // - 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 char* line = text;
const float line_height = GetTextLineHeight(); const float line_height = GetTextLineHeight();
const ImRect clip_rect = window->ClipRect;
ImVec2 text_size(0,0); ImVec2 text_size(0,0);
// Lines to skip (can't skip when logging text) // Lines to skip (can't skip when logging text)
ImVec2 pos = text_pos; ImVec2 pos = text_pos;
if (!g.LogEnabled) if (!g.LogEnabled)
{ {
int lines_skippable = (int)((clip_rect.Min.y - text_pos.y) / line_height); int lines_skippable = (int)((window->ClipRect.Min.y - text_pos.y) / line_height);
if (lines_skippable > 0) if (lines_skippable > 0)
{ {
int lines_skipped = 0; int lines_skipped = 0;
@ -172,6 +171,8 @@ void ImGui::TextUnformatted(const char* text, const char* text_end)
const char* line_end = (const char*)memchr(line, '\n', text_end - line); const char* line_end = (const char*)memchr(line, '\n', text_end - line);
if (!line_end) if (!line_end)
line_end = text_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; line = line_end + 1;
lines_skipped++; lines_skipped++;
} }
@ -191,8 +192,7 @@ void ImGui::TextUnformatted(const char* text, const char* text_end)
const char* line_end = (const char*)memchr(line, '\n', text_end - line); const char* line_end = (const char*)memchr(line, '\n', text_end - line);
if (!line_end) if (!line_end)
line_end = text_end; line_end = text_end;
const ImVec2 line_size = CalcTextSize(line, line_end, false); text_size.x = ImMax(text_size.x, CalcTextSize(line, line_end).x);
text_size.x = ImMax(text_size.x, line_size.x);
RenderText(pos, line, line_end, false); RenderText(pos, line, line_end, false);
line = line_end + 1; line = line_end + 1;
line_rect.Min.y += line_height; line_rect.Min.y += line_height;
@ -207,6 +207,8 @@ void ImGui::TextUnformatted(const char* text, const char* text_end)
const char* line_end = (const char*)memchr(line, '\n', text_end - line); const char* line_end = (const char*)memchr(line, '\n', text_end - line);
if (!line_end) if (!line_end)
line_end = text_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; line = line_end + 1;
lines_skipped++; lines_skipped++;
} }
@ -223,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 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); const ImVec2 text_size = CalcTextSize(text_begin, text_end, false, wrap_width);
// Account of baseline offset
ImRect bb(text_pos, text_pos + text_size); ImRect bb(text_pos, text_pos + text_size);
ItemSize(text_size); ItemSize(text_size);
if (!ItemAdd(bb, 0)) if (!ItemAdd(bb, 0))
@ -234,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, ...) void ImGui::Text(const char* fmt, ...)
{ {
va_list args; va_list args;
@ -250,7 +256,7 @@ void ImGui::TextV(const char* fmt, va_list args)
ImGuiContext& g = *GImGui; ImGuiContext& g = *GImGui;
const char* text_end = g.TempBuffer + ImFormatStringV(g.TempBuffer, IM_ARRAYSIZE(g.TempBuffer), fmt, args); 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, ...) void ImGui::TextColored(const ImVec4& col, const char* fmt, ...)
@ -2009,7 +2015,7 @@ bool ImGui::DragScalarN(const char* label, ImGuiDataType data_type, void* v, int
} }
PopID(); PopID();
TextUnformatted(label, FindRenderedTextEnd(label)); TextEx(label, FindRenderedTextEnd(label));
EndGroup(); EndGroup();
return value_changed; return value_changed;
} }
@ -2052,7 +2058,7 @@ bool ImGui::DragFloatRange2(const char* label, float* v_current_min, float* v_cu
PopItemWidth(); PopItemWidth();
SameLine(0, g.Style.ItemInnerSpacing.x); SameLine(0, g.Style.ItemInnerSpacing.x);
TextUnformatted(label, FindRenderedTextEnd(label)); TextEx(label, FindRenderedTextEnd(label));
EndGroup(); EndGroup();
PopID(); PopID();
return value_changed; return value_changed;
@ -2097,7 +2103,7 @@ bool ImGui::DragIntRange2(const char* label, int* v_current_min, int* v_current_
PopItemWidth(); PopItemWidth();
SameLine(0, g.Style.ItemInnerSpacing.x); SameLine(0, g.Style.ItemInnerSpacing.x);
TextUnformatted(label, FindRenderedTextEnd(label)); TextEx(label, FindRenderedTextEnd(label));
EndGroup(); EndGroup();
PopID(); PopID();
@ -2450,7 +2456,7 @@ bool ImGui::SliderScalarN(const char* label, ImGuiDataType data_type, void* v, i
} }
PopID(); PopID();
TextUnformatted(label, FindRenderedTextEnd(label)); TextEx(label, FindRenderedTextEnd(label));
EndGroup(); EndGroup();
return value_changed; return value_changed;
} }
@ -2749,7 +2755,7 @@ bool ImGui::InputScalar(const char* label, ImGuiDataType data_type, void* data_p
value_changed = true; value_changed = true;
} }
SameLine(0, style.ItemInnerSpacing.x); SameLine(0, style.ItemInnerSpacing.x);
TextUnformatted(label, FindRenderedTextEnd(label)); TextEx(label, FindRenderedTextEnd(label));
style.FramePadding = backup_frame_padding; style.FramePadding = backup_frame_padding;
PopID(); PopID();
@ -2787,7 +2793,7 @@ bool ImGui::InputScalarN(const char* label, ImGuiDataType data_type, void* v, in
} }
PopID(); PopID();
TextUnformatted(label, FindRenderedTextEnd(label)); TextEx(label, FindRenderedTextEnd(label));
EndGroup(); EndGroup();
return value_changed; return value_changed;
} }
@ -4078,7 +4084,7 @@ bool ImGui::ColorEdit4(const char* label, float col[4], ImGuiColorEditFlags flag
picker_active_window = g.CurrentWindow; picker_active_window = g.CurrentWindow;
if (label != label_display_end) if (label != label_display_end)
{ {
TextUnformatted(label, label_display_end); TextEx(label, label_display_end);
Spacing(); Spacing();
} }
ImGuiColorEditFlags picker_flags_to_forward = ImGuiColorEditFlags__DataTypeMask | ImGuiColorEditFlags__PickerMask | ImGuiColorEditFlags_HDR | ImGuiColorEditFlags_NoAlpha | ImGuiColorEditFlags_AlphaBar; ImGuiColorEditFlags picker_flags_to_forward = ImGuiColorEditFlags__DataTypeMask | ImGuiColorEditFlags__PickerMask | ImGuiColorEditFlags_HDR | ImGuiColorEditFlags_NoAlpha | ImGuiColorEditFlags_AlphaBar;
@ -4093,7 +4099,7 @@ bool ImGui::ColorEdit4(const char* label, float col[4], ImGuiColorEditFlags flag
if (label != label_display_end && !(flags & ImGuiColorEditFlags_NoLabel)) if (label != label_display_end && !(flags & ImGuiColorEditFlags_NoLabel))
{ {
SameLine(0, style.ItemInnerSpacing.x); SameLine(0, style.ItemInnerSpacing.x);
TextUnformatted(label, label_display_end); TextEx(label, label_display_end);
} }
// Convert back // Convert back
@ -4353,7 +4359,7 @@ bool ImGui::ColorPicker4(const char* label, float col[4], ImGuiColorEditFlags fl
{ {
if ((flags & ImGuiColorEditFlags_NoSidePreview)) if ((flags & ImGuiColorEditFlags_NoSidePreview))
SameLine(0, style.ItemInnerSpacing.x); SameLine(0, style.ItemInnerSpacing.x);
TextUnformatted(label, label_display_end); TextEx(label, label_display_end);
} }
} }
@ -4581,7 +4587,7 @@ bool ImGui::ColorButton(const char* desc_id, const ImVec4& col, ImGuiColorEditFl
SetDragDropPayload(IMGUI_PAYLOAD_TYPE_COLOR_4F, &col, sizeof(float) * 4, ImGuiCond_Once); SetDragDropPayload(IMGUI_PAYLOAD_TYPE_COLOR_4F, &col, sizeof(float) * 4, ImGuiCond_Once);
ColorButton(desc_id, col, flags); ColorButton(desc_id, col, flags);
SameLine(); SameLine();
TextUnformatted("Color"); TextEx("Color");
EndDragDropSource(); EndDragDropSource();
} }
@ -4622,7 +4628,7 @@ void ImGui::ColorTooltip(const char* text, const float* col, ImGuiColorEditFlags
const char* text_end = text ? FindRenderedTextEnd(text, NULL) : text; const char* text_end = text ? FindRenderedTextEnd(text, NULL) : text;
if (text_end > text) if (text_end > text)
{ {
TextUnformatted(text, text_end); TextEx(text, text_end);
Separator(); Separator();
} }

Loading…
Cancel
Save