mirror of
https://github.com/ocornut/imgui.git
synced 2024-11-28 01:20:55 +01:00
Added LogFinish() to stop logging at an arbitrary point.
This commit is contained in:
parent
0796dc0dc1
commit
1b25fa8169
50
imgui.cpp
50
imgui.cpp
@ -635,7 +635,7 @@ static void ImConvertColorHSVtoRGB(float h, float s, float v, float& out_r, floa
|
||||
static bool ImLoadFileToMemory(const char* filename, const char* file_open_mode, void** out_file_data, size_t* out_file_size, size_t padding_bytes)
|
||||
{
|
||||
IM_ASSERT(filename && file_open_mode && out_file_data && out_file_size);
|
||||
IM_ASSERT(padding_bytes >= 0);
|
||||
IM_ASSERT(padding_bytes >= 0);
|
||||
*out_file_data = NULL;
|
||||
*out_file_size = 0;
|
||||
|
||||
@ -663,8 +663,8 @@ static bool ImLoadFileToMemory(const char* filename, const char* file_open_mode,
|
||||
ImGui::MemFree(file_data);
|
||||
return false;
|
||||
}
|
||||
if (padding_bytes > 0)
|
||||
memset((void *)(((char*)file_data) + file_size), 0, padding_bytes);
|
||||
if (padding_bytes > 0)
|
||||
memset((void *)(((char*)file_data) + file_size), 0, padding_bytes);
|
||||
|
||||
fclose(f);
|
||||
*out_file_data = file_data;
|
||||
@ -2660,25 +2660,7 @@ void ImGui::End()
|
||||
|
||||
// Stop logging
|
||||
if (!(window->Flags & ImGuiWindowFlags_ChildWindow)) // FIXME: add more options for scope of logging
|
||||
{
|
||||
g.LogEnabled = false;
|
||||
if (g.LogFile != NULL)
|
||||
{
|
||||
fprintf(g.LogFile, "\n");
|
||||
if (g.LogFile == stdout)
|
||||
fflush(g.LogFile);
|
||||
else
|
||||
fclose(g.LogFile);
|
||||
g.LogFile = NULL;
|
||||
}
|
||||
if (g.LogClipboard->size() > 1)
|
||||
{
|
||||
g.LogClipboard->append("\n");
|
||||
if (g.IO.SetClipboardTextFn)
|
||||
g.IO.SetClipboardTextFn(g.LogClipboard->begin());
|
||||
g.LogClipboard->clear();
|
||||
}
|
||||
}
|
||||
ImGui::LogFinish();
|
||||
|
||||
// Pop
|
||||
window->RootWindow = NULL;
|
||||
@ -3487,6 +3469,30 @@ void ImGui::LogToClipboard(int max_depth)
|
||||
g.LogAutoExpandMaxDepth = max_depth;
|
||||
}
|
||||
|
||||
void ImGui::LogFinish()
|
||||
{
|
||||
ImGuiState& g = GImGui;
|
||||
if (!g.LogEnabled)
|
||||
return;
|
||||
g.LogEnabled = false;
|
||||
if (g.LogFile != NULL)
|
||||
{
|
||||
fprintf(g.LogFile, "\n");
|
||||
if (g.LogFile == stdout)
|
||||
fflush(g.LogFile);
|
||||
else
|
||||
fclose(g.LogFile);
|
||||
g.LogFile = NULL;
|
||||
}
|
||||
if (g.LogClipboard->size() > 1)
|
||||
{
|
||||
g.LogClipboard->append("\n");
|
||||
if (g.IO.SetClipboardTextFn)
|
||||
g.IO.SetClipboardTextFn(g.LogClipboard->begin());
|
||||
g.LogClipboard->clear();
|
||||
}
|
||||
}
|
||||
|
||||
// Helper to display logging buttons
|
||||
void ImGui::LogButtons()
|
||||
{
|
||||
|
14
imgui.h
14
imgui.h
@ -212,6 +212,7 @@ namespace ImGui
|
||||
|
||||
// ID scopes
|
||||
// If you are creating repeated widgets in a loop you most likely want to push a unique identifier so ImGui can differentiate them.
|
||||
// You can also use ## within your widget name to distinguish them from each others (see 'Programmer Guide')
|
||||
IMGUI_API void PushID(const char* str_id); // push identifier into the ID stack. IDs are hash of the *entire* stack!
|
||||
IMGUI_API void PushID(const void* ptr_id);
|
||||
IMGUI_API void PushID(const int int_id);
|
||||
@ -271,7 +272,7 @@ namespace ImGui
|
||||
IMGUI_API void TreePop();
|
||||
IMGUI_API void OpenNextNode(bool open); // force open/close the next TreeNode or CollapsingHeader
|
||||
|
||||
// Value helper output "name: value". tip: freely declare your own within the ImGui namespace!
|
||||
// Value() Helpers: output single value in "name: value" format. Tip: freely declare your own within the ImGui namespace!
|
||||
IMGUI_API void Value(const char* prefix, bool b);
|
||||
IMGUI_API void Value(const char* prefix, int v);
|
||||
IMGUI_API void Value(const char* prefix, unsigned int v);
|
||||
@ -279,11 +280,12 @@ namespace ImGui
|
||||
IMGUI_API void Color(const char* prefix, const ImVec4& v);
|
||||
IMGUI_API void Color(const char* prefix, unsigned int v);
|
||||
|
||||
// Logging
|
||||
IMGUI_API void LogButtons();
|
||||
IMGUI_API void LogToTTY(int max_depth = -1);
|
||||
IMGUI_API void LogToFile(int max_depth = -1, const char* filename = NULL);
|
||||
IMGUI_API void LogToClipboard(int max_depth = -1);
|
||||
// Logging: All text output can be redirected to tty/file/clipboard. Tree nodes are automatically opened.
|
||||
IMGUI_API void LogToTTY(int max_depth = -1); // start logging to tty
|
||||
IMGUI_API void LogToFile(int max_depth = -1, const char* filename = NULL); // start logging to file
|
||||
IMGUI_API void LogToClipboard(int max_depth = -1); // start logging to OS clipboard
|
||||
IMGUI_API void LogFinish(); // stop logging (close file, etc.)
|
||||
IMGUI_API void LogButtons(); // helper to display buttons for logging to tty/file/clipboard
|
||||
|
||||
// Utilities
|
||||
IMGUI_API bool IsItemHovered(); // was the last item active area hovered by mouse?
|
||||
|
Loading…
Reference in New Issue
Block a user