mirror of
https://github.com/Drezil/imgui.git
synced 2025-07-04 12:08:47 +02:00
Merge branch 'master' into 2016-07-navigation
This commit is contained in:
63
imgui.cpp
63
imgui.cpp
@ -31,6 +31,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)
|
||||
@ -191,6 +192,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.
|
||||
@ -449,6 +451,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.)
|
||||
@ -468,13 +474,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.
|
||||
@ -700,6 +706,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 SetWindowScrollX(ImGuiWindow* window, float new_scroll_x);
|
||||
@ -865,6 +872,7 @@ ImGuiIO::ImGuiIO()
|
||||
|
||||
Fonts = &GImDefaultFontAtlas;
|
||||
FontGlobalScale = 1.0f;
|
||||
FontDefault = NULL;
|
||||
FontAllowUserScaling = false;
|
||||
DisplayFramebufferScale = ImVec2(1.0f, 1.0f);
|
||||
DisplayVisibleMin = DisplayVisibleMax = ImVec2(0.0f, 0.0f);
|
||||
@ -2776,7 +2784,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;
|
||||
@ -4324,12 +4333,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* parent_window = GetCurrentWindow();
|
||||
ImGuiWindow* parent_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);
|
||||
const int auto_fit_axises = ((size.x == 0.0f) ? 0x01 : 0x00) | ((size.y == 0.0f) ? 0x02 : 0x00);
|
||||
if (size.x <= 0.0f)
|
||||
@ -4341,33 +4350,39 @@ 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", parent_window->Name, str_id);
|
||||
if (name)
|
||||
ImFormatString(title, IM_ARRAYSIZE(title), "%s.%s.%08X", parent_window->Name, name, id);
|
||||
else
|
||||
ImFormatString(title, IM_ARRAYSIZE(title), "%s.%08X", parent_window->Name, id);
|
||||
|
||||
bool ret = ImGui::Begin(title, NULL, size, -1.0f, flags);
|
||||
ImGuiWindow* child_window = GetCurrentWindow();
|
||||
ImGuiWindow* child_window = ImGui::GetCurrentWindow();
|
||||
child_window->AutoFitChildAxises = auto_fit_axises;
|
||||
if (!(parent_window->Flags & ImGuiWindowFlags_ShowBorders))
|
||||
child_window->Flags &= ~ImGuiWindowFlags_ShowBorders;
|
||||
|
||||
// Process navigation-in immediately so NavInit can run on first frame
|
||||
const ImGuiID id = parent_window->GetChildID(child_window);
|
||||
//const ImGuiID id = parent_window->GetChildID(child_window);
|
||||
if (/*!(flags & ImGuiWindowFlags_NavFlattened) &&*/ (child_window->DC.NavLayerActiveFlags != 0 || child_window->DC.NavHasScroll) && GImGui->NavActivateId == id)
|
||||
{
|
||||
FocusWindow(child_window);
|
||||
ImGui::FocusWindow(child_window);
|
||||
NavInitWindow(child_window, false);
|
||||
SetActiveIDNoNav(id+1, child_window); // Steal ActiveId with a dummy id so that key-press won't activate child item
|
||||
ImGui::SetActiveIDNoNav(id+1, child_window); // Steal ActiveId with a dummy id so that key-press won't activate child item
|
||||
GImGui->ActiveIdSource = ImGuiInputSource_Nav;
|
||||
}
|
||||
|
||||
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()
|
||||
@ -5141,8 +5156,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;
|
||||
@ -5418,6 +5433,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;
|
||||
@ -5433,7 +5454,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);
|
||||
@ -5444,7 +5465,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::PushItemFlag(ImGuiItemFlags option, bool enabled)
|
||||
|
Reference in New Issue
Block a user