1
0
mirror of https://github.com/Drezil/imgui.git synced 2024-12-29 19:16:35 +00:00

Merge branch 'tpoechtrager-master'

This commit is contained in:
ocornut 2015-08-08 12:26:44 -06:00
commit 32f15b9c9a
6 changed files with 36 additions and 30 deletions

View File

@ -22,7 +22,7 @@ ifeq ($(UNAME_S), Linux) #LINUX
LIBS = `pkg-config --static --libs glfw3`
CXXFLAGS = -I../../ -I../libs/gl3w `pkg-config --cflags glfw3`
CXXFLAGS += -Wall
CXXFLAGS += -Wall -Wformat
CFLAGS = $(CXXFLAGS)
endif
@ -33,7 +33,7 @@ ifeq ($(UNAME_S), Darwin) #APPLE
LIBS += -lglfw3
CXXFLAGS = -I../../ -I../libs/gl3w -I/usr/local/Cellar/glew/1.10.0/include -I/usr/local/include
CXXFLAGS += -Wall
CXXFLAGS += -Wall -Wformat
# CXXFLAGS += -D__APPLE__
CFLAGS = $(CXXFLAGS)
endif

View File

@ -21,7 +21,7 @@ ifeq ($(UNAME_S), Linux) #LINUX
LIBS = `pkg-config --static --libs glfw3`
CXXFLAGS = -I../../ `pkg-config --cflags glfw3`
CXXFLAGS += -Wall
CXXFLAGS += -Wall -Wformat
CFLAGS = $(CXXFLAGS)
endif
@ -32,7 +32,7 @@ ifeq ($(UNAME_S), Darwin) #APPLE
LIBS += -lglfw3
CXXFLAGS = -I../../ -I/usr/local/include
CXXFLAGS += -Wall
CXXFLAGS += -Wall -Wformat
# CXXFLAGS += -D__APPLE__
CFLAGS = $(CXXFLAGS)
endif

View File

@ -458,7 +458,6 @@
- input: rework IO to be able to pass actual events to fix temporal aliasing issues.
- input: support track pad style scrolling & slider edit.
- memory: add a way to discard allocs of unused/transient windows. with the current architecture new windows (including popup, opened combos, listbox) perform at least 3 allocs.
- misc: mark printf compiler attributes on relevant functions
- misc: provide a way to compile out the entire implementation while providing a dummy API (e.g. #define IMGUI_DUMMY_IMPL)
- misc: double-clicking on title bar to minimize isn't consistent, perhaps move to single-click on left-most collapse icon?
- style editor: have a more global HSV setter (e.g. alter hue on all elements). consider replacing active/hovered by offset in HSV space?
@ -2071,7 +2070,7 @@ static void LoadSettings()
if (line_start[0] == '[' && line_end > line_start && line_end[-1] == ']')
{
char name[64];
ImFormatString(name, IM_ARRAYSIZE(name), "%.*s", line_end-line_start-2, line_start+1);
ImFormatString(name, IM_ARRAYSIZE(name), "%.*s", (int)(line_end-line_start-2), line_start+1);
settings = FindWindowSettings(name);
if (!settings)
settings = AddWindowSettings(name);
@ -8881,7 +8880,7 @@ void ImGui::ShowMetricsWindow(bool* opened)
NodeDrawList(window->DrawList, "DrawList");
if (window->RootWindow != window) NodeWindow(window->RootWindow, "RootWindow");
if (window->DC.ChildWindows.Size > 0) NodeWindows(window->DC.ChildWindows, "ChildWindows");
ImGui::BulletText("Storage: %d bytes", window->StateStorage.Data.Size * sizeof(ImGuiStorage::Pair));
ImGui::BulletText("Storage: %d bytes", window->StateStorage.Data.Size * (int)sizeof(ImGuiStorage::Pair));
ImGui::TreePop();
}
};

28
imgui.h
View File

@ -30,6 +30,12 @@
#define IMGUI_API
#endif
#if defined(__clang__) || defined(__GNUC__)
#define IM_PRINTFARGS(FMT) __attribute__((format(printf, FMT, (FMT+1))))
#else
#define IM_PRINTFARGS(FMT)
#endif
// Forward declarations
struct ImDrawCmd;
struct ImDrawList;
@ -213,19 +219,19 @@ namespace ImGui
IMGUI_API ImGuiID GetID(const void* ptr_id);
// Widgets
IMGUI_API void Text(const char* fmt, ...);
IMGUI_API void Text(const char* fmt, ...) IM_PRINTFARGS(1);
IMGUI_API void TextV(const char* fmt, va_list args);
IMGUI_API void TextColored(const ImVec4& col, const char* fmt, ...); // shortcut for PushStyleColor(ImGuiCol_Text, col); Text(fmt, ...); PopStyleColor();
IMGUI_API void TextColored(const ImVec4& col, const char* fmt, ...) IM_PRINTFARGS(2); // shortcut for PushStyleColor(ImGuiCol_Text, col); Text(fmt, ...); PopStyleColor();
IMGUI_API void TextColoredV(const ImVec4& col, const char* fmt, va_list args);
IMGUI_API void TextDisabled(const char* fmt, ...); // shortcut for PushStyleColor(ImGuiCol_Text, style.Colors[ImGuiCol_TextDisabled]); Text(fmt, ...); PopStyleColor();
IMGUI_API void TextDisabled(const char* fmt, ...) IM_PRINTFARGS(1); // shortcut for PushStyleColor(ImGuiCol_Text, style.Colors[ImGuiCol_TextDisabled]); Text(fmt, ...); PopStyleColor();
IMGUI_API void TextDisabledV(const char* fmt, va_list args);
IMGUI_API void TextWrapped(const char* fmt, ...); // shortcut for PushTextWrapPos(0.0f); Text(fmt, ...); PopTextWrapPos();. Note that this won't work on an auto-resizing window if there's no other widgets to extend the window width, yoy may need to set a size using SetNextWindowSize().
IMGUI_API void TextWrapped(const char* fmt, ...) IM_PRINTFARGS(1); // shortcut for PushTextWrapPos(0.0f); Text(fmt, ...); PopTextWrapPos();. Note that this won't work on an auto-resizing window if there's no other widgets to extend the window width, yoy may need to set a size using SetNextWindowSize().
IMGUI_API void TextWrappedV(const char* fmt, va_list args);
IMGUI_API void TextUnformatted(const char* text, const char* text_end = NULL); // doesn't require null terminated string if 'text_end' is specified. no copy done to any bounded stack buffer, recommended for long chunks of text
IMGUI_API void LabelText(const char* label, const char* fmt, ...); // display text+label aligned the same way as value+label widgets
IMGUI_API void LabelText(const char* label, const char* fmt, ...) IM_PRINTFARGS(2); // display text+label aligned the same way as value+label widgets
IMGUI_API void LabelTextV(const char* label, const char* fmt, va_list args);
IMGUI_API void Bullet();
IMGUI_API void BulletText(const char* fmt, ...);
IMGUI_API void BulletText(const char* fmt, ...) IM_PRINTFARGS(1);
IMGUI_API void BulletTextV(const char* fmt, va_list args);
IMGUI_API bool Button(const char* label, const ImVec2& size = ImVec2(0,0));
IMGUI_API bool SmallButton(const char* label);
@ -288,8 +294,8 @@ namespace ImGui
// Widgets: Trees
IMGUI_API bool TreeNode(const char* str_label_id); // if returning 'true' the node is open and the user is responsible for calling TreePop
IMGUI_API bool TreeNode(const char* str_id, const char* fmt, ...); // "
IMGUI_API bool TreeNode(const void* ptr_id, const char* fmt, ...); // "
IMGUI_API bool TreeNode(const char* str_id, const char* fmt, ...) IM_PRINTFARGS(2); // "
IMGUI_API bool TreeNode(const void* ptr_id, const char* fmt, ...) IM_PRINTFARGS(2); // "
IMGUI_API bool TreeNodeV(const char* str_id, const char* fmt, va_list args); // "
IMGUI_API bool TreeNodeV(const void* ptr_id, const char* fmt, va_list args); // "
IMGUI_API void TreePush(const char* str_id = NULL); // already called by TreeNode(), but you can call Push/Pop yourself for layouting purpose
@ -315,7 +321,7 @@ namespace ImGui
IMGUI_API void Color(const char* prefix, unsigned int v);
// Tooltip
IMGUI_API void SetTooltip(const char* fmt, ...); // set tooltip under mouse-cursor, typically use with ImGui::IsHovered(). last call wins
IMGUI_API void SetTooltip(const char* fmt, ...) IM_PRINTFARGS(1); // set tooltip under mouse-cursor, typically use with ImGui::IsHovered(). last call wins
IMGUI_API void SetTooltipV(const char* fmt, va_list args);
IMGUI_API void BeginTooltip(); // use to create full-featured tooltip windows that aren't just text
IMGUI_API void EndTooltip();
@ -346,7 +352,7 @@ namespace ImGui
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
IMGUI_API void LogText(const char* fmt, ...); // pass text data straight to log (without being displayed)
IMGUI_API void LogText(const char* fmt, ...) IM_PRINTFARGS(1); // pass text data straight to log (without being displayed)
// Utilities
IMGUI_API bool IsItemHovered(); // was the last item hovered by mouse?
@ -861,7 +867,7 @@ struct ImGuiTextBuffer
int size() const { return Buf.Size-1; }
bool empty() { return size() >= 1; }
void clear() { Buf.clear(); Buf.push_back(0); }
IMGUI_API void append(const char* fmt, ...);
IMGUI_API void append(const char* fmt, ...) IM_PRINTFARGS(2);
IMGUI_API void appendv(const char* fmt, va_list args);
};

View File

@ -25,6 +25,7 @@
#endif
#ifdef __GNUC__
#pragma GCC diagnostic ignored "-Wint-to-pointer-cast" // warning: cast to pointer from integer of different size
#pragma GCC diagnostic ignored "-Wformat-security" // warning : format string is not a string literal (potentially insecure)
#endif
// Play it nice with Windows users. Notepad in 2015 still doesn't display text data with Unix-style \n.
@ -1424,7 +1425,7 @@ void ImGui::ShowStyleEditor(ImGuiStyle* ref)
const ImVec4& col = style.Colors[i];
const char* name = ImGui::GetStyleColName(i);
if (!output_only_modified || memcmp(&col, (ref ? &ref->Colors[i] : &def.Colors[i]), sizeof(ImVec4)) != 0)
ImGui::LogText("style.Colors[ImGuiCol_%s]%*s= ImVec4(%.2ff, %.2ff, %.2ff, %.2ff);" IM_NEWLINE, name, 22 - strlen(name), "", col.x, col.y, col.z, col.w);
ImGui::LogText("style.Colors[ImGuiCol_%s]%*s= ImVec4(%.2ff, %.2ff, %.2ff, %.2ff);" IM_NEWLINE, name, 22 - (int)strlen(name), "", col.x, col.y, col.z, col.w);
}
ImGui::LogFinish();
}
@ -1702,7 +1703,7 @@ struct ExampleAppConsole
ScrollToBottom = true;
}
void AddLog(const char* fmt, ...)
void AddLog(const char* fmt, ...) IM_PRINTFARGS(2)
{
char buf[1024];
va_list args;
@ -1862,7 +1863,7 @@ struct ExampleAppConsole
if (candidates.Size == 0)
{
// No match
AddLog("No match for \"%.*s\"!\n", word_end-word_start, word_start);
AddLog("No match for \"%.*s\"!\n", (int)(word_end-word_start), word_start);
}
else if (candidates.Size == 1)
{

View File

@ -90,7 +90,7 @@ char* ImStrdup(const char* str);
int ImStrlenW(const ImWchar* str);
const ImWchar* ImStrbolW(const ImWchar* buf_mid_line, const ImWchar* buf_begin); // Find beginning-of-line
const char* ImStristr(const char* haystack, const char* needle, const char* needle_end);
int ImFormatString(char* buf, int buf_size, const char* fmt, ...);
int ImFormatString(char* buf, int buf_size, const char* fmt, ...) IM_PRINTFARGS(3);
int ImFormatStringV(char* buf, int buf_size, const char* fmt, va_list args);
// Helpers: Math