Updated ImGui.
This commit is contained in:
parent
daeab5c239
commit
f76f51770c
57
3rdparty/ocornut-imgui/imgui.cpp
vendored
57
3rdparty/ocornut-imgui/imgui.cpp
vendored
@ -25,6 +25,7 @@
|
||||
- How can I have multiple widgets with the same label? Can I have widget without a label? (Yes). A primer on the purpose of labels/IDs.
|
||||
- How can I tell when ImGui wants my mouse/keyboard inputs and when I can pass them to my application?
|
||||
- How can I load a different font than the default?
|
||||
- How can I easily use icons in my application?
|
||||
- How can I load multiple fonts?
|
||||
- How can I display and input non-latin characters such as Chinese, Japanese, Korean, Cyrillic?
|
||||
- How can I use the drawing facilities without an ImGui window? (using ImDrawList API)
|
||||
@ -150,6 +151,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/11/06 (1.50) - BeginChild(const char*) now applies the stack id to the provided label, consistently with other functions as it should always have been. It shouldn't affect you unless (extremely unlikely) you were appending multiple times to a same child from different locations of the stack id. If that's the case, generate an id with GetId() and use it instead of passing string to BeginChild().
|
||||
- 2016/10/15 (1.50) - avoid 'void* user_data' parameter to io.SetClipboardTextFn/io.GetClipboardTextFn pointers. We pass io.ClipboardUserData to it.
|
||||
- 2016/09/25 (1.50) - style.WindowTitleAlign is now a ImVec2 (ImGuiAlign enum was removed). set to (0.5f,0.5f) for horizontal+vertical centering, (0.0f,0.0f) for upper-left, etc.
|
||||
- 2016/07/30 (1.50) - SameLine(x) with x>0.0f is now relative to left of column/group if any, and not always to left of window. This was sort of always the intent and hopefully breakage should be minimal.
|
||||
@ -405,6 +407,10 @@
|
||||
io.Fonts->AddFontFromFileTTF("myfontfile.ttf", size_in_pixels);
|
||||
io.Fonts->GetTexDataAsRGBA32() or GetTexDataAsAlpha8()
|
||||
|
||||
Q: How can I easily use icons in my application?
|
||||
A: The most convenient and practical way is to merge an icon font such as FontAwesome inside you main font. Then you can refer to icons within your strings.
|
||||
Read 'How can I load multiple fonts?' and the file 'extra_fonts/README.txt' for instructions.
|
||||
|
||||
Q: How can I load multiple fonts?
|
||||
A: Use the font atlas to pack them into a single texture:
|
||||
(Read extra_fonts/README.txt and the code in ImFontAtlas for more details.)
|
||||
@ -424,13 +430,13 @@
|
||||
config.GlyphExtraSpacing.x = 1.0f;
|
||||
io.Fonts->LoadFromFileTTF("myfontfile.ttf", size_pixels, &config);
|
||||
|
||||
// Combine multiple fonts into one
|
||||
// Combine multiple fonts into one (e.g. for icon fonts)
|
||||
ImWchar ranges[] = { 0xf000, 0xf3ff, 0 };
|
||||
ImFontConfig config;
|
||||
config.MergeMode = true;
|
||||
io.Fonts->AddFontDefault();
|
||||
io.Fonts->LoadFromFileTTF("fontawesome-webfont.ttf", 16.0f, &config, ranges);
|
||||
io.Fonts->LoadFromFileTTF("myfontfile.ttf", size_pixels, NULL, &config, io.Fonts->GetGlyphRangesJapanese());
|
||||
io.Fonts->LoadFromFileTTF("fontawesome-webfont.ttf", 16.0f, &config, ranges); // Merge icon font
|
||||
io.Fonts->LoadFromFileTTF("myfontfile.ttf", size_pixels, NULL, &config, io.Fonts->GetGlyphRangesJapanese()); // Merge japanese glyphs
|
||||
|
||||
Q: How can I display and input non-Latin characters such as Chinese, Japanese, Korean, Cyrillic?
|
||||
A: When loading a font, pass custom Unicode ranges to specify the glyphs to load.
|
||||
@ -662,6 +668,7 @@ static float GetDraggedColumnOffset(int column_index);
|
||||
|
||||
static bool IsKeyPressedMap(ImGuiKey key, bool repeat = true);
|
||||
|
||||
static ImFont* GetDefaultFont();
|
||||
static void SetCurrentFont(ImFont* font);
|
||||
static void SetCurrentWindow(ImGuiWindow* window);
|
||||
static void SetWindowScrollY(ImGuiWindow* window, float new_scroll_y);
|
||||
@ -813,6 +820,7 @@ ImGuiIO::ImGuiIO()
|
||||
LogFilename = "imgui_log.txt";
|
||||
Fonts = &GImDefaultFontAtlas;
|
||||
FontGlobalScale = 1.0f;
|
||||
FontDefault = NULL;
|
||||
DisplayFramebufferScale = ImVec2(1.0f, 1.0f);
|
||||
MousePos = ImVec2(-1,-1);
|
||||
MousePosPrev = ImVec2(-1,-1);
|
||||
@ -2110,7 +2118,8 @@ void ImGui::NewFrame()
|
||||
g.Initialized = true;
|
||||
}
|
||||
|
||||
SetCurrentFont(g.IO.Fonts->Fonts[0]);
|
||||
SetCurrentFont(GetDefaultFont());
|
||||
IM_ASSERT(g.Font->IsLoaded());
|
||||
|
||||
g.Time += g.IO.DeltaTime;
|
||||
g.FrameCount += 1;
|
||||
@ -3586,12 +3595,12 @@ bool ImGui::BeginPopupContextVoid(const char* str_id, int mouse_button)
|
||||
return BeginPopup(str_id);
|
||||
}
|
||||
|
||||
bool ImGui::BeginChild(const char* str_id, const ImVec2& size_arg, bool border, ImGuiWindowFlags extra_flags)
|
||||
static bool BeginChildEx(const char* name, ImGuiID id, const ImVec2& size_arg, bool border, ImGuiWindowFlags extra_flags)
|
||||
{
|
||||
ImGuiWindow* window = GetCurrentWindow();
|
||||
ImGuiWindow* window = ImGui::GetCurrentWindow();
|
||||
ImGuiWindowFlags flags = ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoResize|ImGuiWindowFlags_NoSavedSettings|ImGuiWindowFlags_ChildWindow;
|
||||
|
||||
const ImVec2 content_avail = GetContentRegionAvail();
|
||||
const ImVec2 content_avail = ImGui::GetContentRegionAvail();
|
||||
ImVec2 size = ImFloor(size_arg);
|
||||
if (size.x <= 0.0f)
|
||||
{
|
||||
@ -3610,22 +3619,28 @@ bool ImGui::BeginChild(const char* str_id, const ImVec2& size_arg, bool border,
|
||||
flags |= extra_flags;
|
||||
|
||||
char title[256];
|
||||
ImFormatString(title, IM_ARRAYSIZE(title), "%s.%s", window->Name, str_id);
|
||||
if (name)
|
||||
ImFormatString(title, IM_ARRAYSIZE(title), "%s.%s.%08X", window->Name, name, id);
|
||||
else
|
||||
ImFormatString(title, IM_ARRAYSIZE(title), "%s.%08X", window->Name, id);
|
||||
|
||||
bool ret = ImGui::Begin(title, NULL, size, -1.0f, flags);
|
||||
|
||||
if (!(window->Flags & ImGuiWindowFlags_ShowBorders))
|
||||
GetCurrentWindow()->Flags &= ~ImGuiWindowFlags_ShowBorders;
|
||||
ImGui::GetCurrentWindow()->Flags &= ~ImGuiWindowFlags_ShowBorders;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool ImGui::BeginChild(ImGuiID id, const ImVec2& size, bool border, ImGuiWindowFlags extra_flags)
|
||||
bool ImGui::BeginChild(const char* str_id, const ImVec2& size_arg, bool border, ImGuiWindowFlags extra_flags)
|
||||
{
|
||||
char str_id[32];
|
||||
ImFormatString(str_id, IM_ARRAYSIZE(str_id), "child_%08x", id);
|
||||
bool ret = ImGui::BeginChild(str_id, size, border, extra_flags);
|
||||
return ret;
|
||||
ImGuiWindow* window = GetCurrentWindow();
|
||||
return BeginChildEx(str_id, window->GetID(str_id), size_arg, border, extra_flags);
|
||||
}
|
||||
|
||||
bool ImGui::BeginChild(ImGuiID id, const ImVec2& size_arg, bool border, ImGuiWindowFlags extra_flags)
|
||||
{
|
||||
return BeginChildEx(NULL, id, size_arg, border, extra_flags);
|
||||
}
|
||||
|
||||
void ImGui::EndChild()
|
||||
@ -4322,8 +4337,8 @@ bool ImGui::Begin(const char* name, bool* p_open, const ImVec2& size_on_first_us
|
||||
ImVec2 text_max = window->Pos + ImVec2(window->Size.x, style.FramePadding.y*2 + text_size.y);
|
||||
ImRect clip_rect;
|
||||
clip_rect.Max = ImVec2(window->Pos.x + window->Size.x - (p_open ? title_bar_rect.GetHeight() - 3 : style.FramePadding.x), text_max.y); // Match the size of CloseWindowButton()
|
||||
float pad_left = (flags & ImGuiWindowFlags_NoCollapse) == 0 ? (style.FramePadding.x + g.FontSize + style.ItemInnerSpacing.x) : 0.0f;
|
||||
float pad_right = (p_open != NULL) ? (style.FramePadding.x + g.FontSize + style.ItemInnerSpacing.x) : 0.0f;
|
||||
float pad_left = (flags & ImGuiWindowFlags_NoCollapse) == 0 ? (style.FramePadding.x + g.FontSize + style.ItemInnerSpacing.x) : style.FramePadding.x;
|
||||
float pad_right = (p_open != NULL) ? (style.FramePadding.x + g.FontSize + style.ItemInnerSpacing.x) : style.FramePadding.x;
|
||||
if (style.WindowTitleAlign.x > 0.0f) pad_right = ImLerp(pad_right, pad_left, style.WindowTitleAlign.x);
|
||||
text_min.x += pad_left;
|
||||
text_max.x -= pad_right;
|
||||
@ -4584,6 +4599,12 @@ float ImGui::CalcItemWidth()
|
||||
return w;
|
||||
}
|
||||
|
||||
static ImFont* GetDefaultFont()
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
return g.IO.FontDefault ? g.IO.FontDefault : g.IO.Fonts->Fonts[0];
|
||||
}
|
||||
|
||||
static void SetCurrentFont(ImFont* font)
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
@ -4599,7 +4620,7 @@ void ImGui::PushFont(ImFont* font)
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
if (!font)
|
||||
font = g.IO.Fonts->Fonts[0];
|
||||
font = GetDefaultFont();
|
||||
SetCurrentFont(font);
|
||||
g.FontStack.push_back(font);
|
||||
g.CurrentWindow->DrawList->PushTextureID(font->ContainerAtlas->TexID);
|
||||
@ -4610,7 +4631,7 @@ void ImGui::PopFont()
|
||||
ImGuiContext& g = *GImGui;
|
||||
g.CurrentWindow->DrawList->PopTextureID();
|
||||
g.FontStack.pop_back();
|
||||
SetCurrentFont(g.FontStack.empty() ? g.IO.Fonts->Fonts[0] : g.FontStack.back());
|
||||
SetCurrentFont(g.FontStack.empty() ? GetDefaultFont() : g.FontStack.back());
|
||||
}
|
||||
|
||||
void ImGui::PushAllowKeyboardFocus(bool allow_keyboard_focus)
|
||||
|
3
3rdparty/ocornut-imgui/imgui.h
vendored
3
3rdparty/ocornut-imgui/imgui.h
vendored
@ -30,7 +30,7 @@
|
||||
#endif
|
||||
|
||||
// Some compilers support applying printf-style warnings to user functions.
|
||||
#if 0 //defined(__clang__) || defined(__GNUC__)
|
||||
#if 0 // defined(__clang__) || defined(__GNUC__)
|
||||
#define IM_PRINTFARGS(FMT) __attribute__((format(printf, FMT, (FMT+1))))
|
||||
#else
|
||||
#define IM_PRINTFARGS(FMT)
|
||||
@ -741,6 +741,7 @@ struct ImGuiIO
|
||||
ImFontAtlas* Fonts; // <auto> // Load and assemble one or more fonts into a single tightly packed texture. Output to Fonts array.
|
||||
float FontGlobalScale; // = 1.0f // Global scale all fonts
|
||||
bool FontAllowUserScaling; // = false // Allow user scaling text of individual window with CTRL+Wheel.
|
||||
ImFont* FontDefault; // = NULL // Font to use on NewFrame(). Use NULL to uses Fonts->Fonts[0].
|
||||
ImVec2 DisplayFramebufferScale; // = (1.0f,1.0f) // For retina display or other situations where window coordinates are different from framebuffer coordinates. User storage only, presently not used by ImGui.
|
||||
ImVec2 DisplayVisibleMin; // <unset> (0.0f,0.0f) // If you use DisplaySize as a virtual space larger than your screen, set DisplayVisibleMin/Max to the visible area.
|
||||
ImVec2 DisplayVisibleMax; // <unset> (0.0f,0.0f) // If the values are the same, we defaults to Min=(0.0f) and Max=DisplaySize
|
||||
|
18
3rdparty/ocornut-imgui/imgui_demo.cpp
vendored
18
3rdparty/ocornut-imgui/imgui_demo.cpp
vendored
@ -1733,7 +1733,7 @@ void ImGui::ShowStyleEditor(ImGuiStyle* ref)
|
||||
ImFont* font = atlas->Fonts[i];
|
||||
ImGui::BulletText("Font %d: \'%s\', %.2f px, %d glyphs", i, font->ConfigData ? font->ConfigData[0].Name : "", font->FontSize, font->Glyphs.Size);
|
||||
ImGui::TreePush((void*)(intptr_t)i);
|
||||
if (i > 0) { ImGui::SameLine(); if (ImGui::SmallButton("Set as default")) { atlas->Fonts[i] = atlas->Fonts[0]; atlas->Fonts[0] = font; } }
|
||||
ImGui::SameLine(); if (ImGui::SmallButton("Set as default")) ImGui::GetIO().FontDefault = font;
|
||||
ImGui::PushFont(font);
|
||||
ImGui::Text("The quick brown fox jumps over the lazy dog");
|
||||
ImGui::PopFont();
|
||||
@ -2041,21 +2041,21 @@ static void ShowExampleAppCustomRendering(bool* p_open)
|
||||
|
||||
bool adding_preview = false;
|
||||
ImGui::InvisibleButton("canvas", canvas_size);
|
||||
ImVec2 mouse_pos_in_canvas = ImVec2(ImGui::GetIO().MousePos.x - canvas_pos.x, ImGui::GetIO().MousePos.y - canvas_pos.y);
|
||||
if (adding_line)
|
||||
{
|
||||
adding_preview = true;
|
||||
points.push_back(mouse_pos_in_canvas);
|
||||
if (!ImGui::GetIO().MouseDown[0])
|
||||
adding_line = adding_preview = false;
|
||||
}
|
||||
if (ImGui::IsItemHovered())
|
||||
{
|
||||
ImVec2 mouse_pos_in_canvas = ImVec2(ImGui::GetIO().MousePos.x - canvas_pos.x, ImGui::GetIO().MousePos.y - canvas_pos.y);
|
||||
if (!adding_line && ImGui::IsMouseClicked(0))
|
||||
{
|
||||
points.push_back(mouse_pos_in_canvas);
|
||||
adding_line = true;
|
||||
}
|
||||
if (adding_line)
|
||||
{
|
||||
adding_preview = true;
|
||||
points.push_back(mouse_pos_in_canvas);
|
||||
if (!ImGui::GetIO().MouseDown[0])
|
||||
adding_line = adding_preview = false;
|
||||
}
|
||||
if (ImGui::IsMouseClicked(1) && !points.empty())
|
||||
{
|
||||
adding_line = adding_preview = false;
|
||||
|
10
3rdparty/ocornut-imgui/imgui_draw.cpp
vendored
10
3rdparty/ocornut-imgui/imgui_draw.cpp
vendored
@ -1186,7 +1186,7 @@ ImFont* ImFontAtlas::AddFontDefault(const ImFontConfig* font_cfg_template)
|
||||
font_cfg.OversampleH = font_cfg.OversampleV = 1;
|
||||
font_cfg.PixelSnapH = true;
|
||||
}
|
||||
if (font_cfg.Name[0] == '\0') strcpy(font_cfg.Name, "<default>");
|
||||
if (font_cfg.Name[0] == '\0') strcpy(font_cfg.Name, "ProggyClean.ttf, 13px");
|
||||
|
||||
const char* ttf_compressed_base85 = GetDefaultCompressedFontDataTTFBase85();
|
||||
ImFont* font = AddFontFromMemoryCompressedBase85TTF(ttf_compressed_base85, 13.0f, &font_cfg, GetGlyphRangesDefault());
|
||||
@ -1208,7 +1208,7 @@ ImFont* ImFontAtlas::AddFontFromFileTTF(const char* filename, float size_pixels,
|
||||
// Store a short copy of filename into into the font name for convenience
|
||||
const char* p;
|
||||
for (p = filename + strlen(filename); p > filename && p[-1] != '/' && p[-1] != '\\'; p--) {}
|
||||
snprintf(font_cfg.Name, IM_ARRAYSIZE(font_cfg.Name), "%s", p);
|
||||
snprintf(font_cfg.Name, IM_ARRAYSIZE(font_cfg.Name), "%s, %.0fpx", p, size_pixels);
|
||||
}
|
||||
return AddFontFromMemoryTTF(data, data_size, size_pixels, &font_cfg, glyph_ranges);
|
||||
}
|
||||
@ -1944,7 +1944,7 @@ ImVec2 ImFont::CalcTextSizeA(float size, float max_width, float wrap_width, cons
|
||||
else
|
||||
{
|
||||
s += ImTextCharFromUtf8(&c, s, text_end);
|
||||
if (c == 0)
|
||||
if (c == 0) // Malformed UTF-8?
|
||||
break;
|
||||
}
|
||||
|
||||
@ -2002,7 +2002,7 @@ void ImFont::RenderChar(ImDrawList* draw_list, float size, ImVec2 pos, ImU32 col
|
||||
void ImFont::RenderText(ImDrawList* draw_list, float size, ImVec2 pos, ImU32 col, const ImVec4& clip_rect, const char* text_begin, const char* text_end, float wrap_width, bool cpu_fine_clip) const
|
||||
{
|
||||
if (!text_end)
|
||||
text_end = text_begin + strlen(text_begin);
|
||||
text_end = text_begin + strlen(text_begin); // ImGui functions generally already provides a valid text_end, so this is merely to handle direct calls.
|
||||
|
||||
// Align to be pixel perfect
|
||||
pos.x = (float)(int)pos.x + DisplayOffset.x;
|
||||
@ -2070,7 +2070,7 @@ void ImFont::RenderText(ImDrawList* draw_list, float size, ImVec2 pos, ImU32 col
|
||||
else
|
||||
{
|
||||
s += ImTextCharFromUtf8(&c, s, text_end);
|
||||
if (c == 0)
|
||||
if (c == 0) // Malformed UTF-8?
|
||||
break;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user