From c1fe6fe14d4165db164c5bd93f994cef3a851288 Mon Sep 17 00:00:00 2001 From: ocornut Date: Fri, 9 Jan 2015 17:19:24 +0000 Subject: [PATCH 01/16] Fixed GetStyleColName() not matching the enum strings for 3 values (#111) --- imgui.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 32c0ca0b..cb82d9d7 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -2888,9 +2888,9 @@ const char* ImGui::GetStyleColName(ImGuiCol idx) case ImGuiCol_ScrollbarGrabHovered: return "ScrollbarGrabHovered"; case ImGuiCol_ScrollbarGrabActive: return "ScrollbarGrabActive"; case ImGuiCol_ComboBg: return "ComboBg"; - case ImGuiCol_CheckHovered: return "CheckBgHovered"; - case ImGuiCol_CheckActive: return "CheckBgActive"; - case ImGuiCol_CheckMark: return "CheckSelected"; + case ImGuiCol_CheckHovered: return "CheckHovered"; + case ImGuiCol_CheckActive: return "CheckActive"; + case ImGuiCol_CheckMark: return "CheckMark"; case ImGuiCol_SliderGrab: return "SliderGrab"; case ImGuiCol_SliderGrabActive: return "SliderGrabActive"; case ImGuiCol_Button: return "Button"; From f0b493c217ada01479f654a0d5b06b4e01d3d455 Mon Sep 17 00:00:00 2001 From: ocornut Date: Tue, 13 Jan 2015 23:05:20 +0000 Subject: [PATCH 02/16] Fixed style.WindowMinSize not honored properly. --- imgui.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index cb82d9d7..b66f5f17 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -2395,13 +2395,13 @@ bool ImGui::Begin(const char* name, bool* p_opened, ImVec2 size, float fill_alph // Clamp into view if (!(window->Flags & ImGuiWindowFlags_ChildWindow)) { - const ImVec2 pad = ImVec2(window->FontSize()*2.0f, window->FontSize()*2.0f); + const ImVec2 pad = ImVec2(window->FontSize()*2.0f, window->FontSize()*2.0f); // FIXME: Parametrize of clarify this behavior. if (g.IO.DisplaySize.x > 0.0f && g.IO.DisplaySize.y > 0.0f) // Ignore zero-sized display explicitly to avoid losing positions if a window manager reports zero-sized window when initializing or minimizing. { window->PosFloat = ImMax(window->PosFloat + window->Size, pad) - window->Size; window->PosFloat = ImMin(window->PosFloat, ImVec2(g.IO.DisplaySize.x, g.IO.DisplaySize.y) - pad); } - window->SizeFull = ImMax(window->SizeFull, pad); + window->SizeFull = ImMax(window->SizeFull, style.WindowMinSize); } window->Pos = ImVec2((float)(int)window->PosFloat.x, (float)(int)window->PosFloat.y); From e2d8c03e1aed4ce4da98039922ad446a55600e9c Mon Sep 17 00:00:00 2001 From: ocornut Date: Tue, 13 Jan 2015 23:06:55 +0000 Subject: [PATCH 03/16] Fixed ImGuiTextBuffer::empty() to ignore the enforced zero-terminator + removed unnecessary destructor --- imgui.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/imgui.h b/imgui.h index 9248ae44..dc009ccc 100644 --- a/imgui.h +++ b/imgui.h @@ -604,11 +604,11 @@ struct ImGuiTextBuffer ImVector Buf; ImGuiTextBuffer() { Buf.push_back(0); } - ~ImGuiTextBuffer() { clear(); } + ~ImGuiTextBuffer() { } const char* begin() const { return &Buf.front(); } const char* end() const { return &Buf.back(); } // Buf is zero-terminated, so end() will point on the zero-terminator size_t size() const { return Buf.size()-1; } - bool empty() { return Buf.empty(); } + bool empty() { return size() >= 1; } void clear() { Buf.clear(); Buf.push_back(0); } IMGUI_API void append(const char* fmt, ...); IMGUI_API void appendv(const char* fmt, va_list args); From 53222248813b08701f0915ff15bb71e80d1284b4 Mon Sep 17 00:00:00 2001 From: ocornut Date: Tue, 13 Jan 2015 23:19:11 +0000 Subject: [PATCH 04/16] Warning fixes for llvm windows 64-bits --- imgui.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index b66f5f17..e9033ae5 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -7730,7 +7730,7 @@ struct ExampleAppConsole if (data->EventKey == ImGuiKey_UpArrow) { if (HistoryPos == -1) - HistoryPos = History.size() - 1; + HistoryPos = (int)(History.size() - 1); else if (HistoryPos > 0) HistoryPos--; } @@ -7746,7 +7746,7 @@ struct ExampleAppConsole { ImFormatString(data->Buf, data->BufSize, "%s", (HistoryPos >= 0) ? History[HistoryPos] : ""); data->BufDirty = true; - data->CursorPos = data->SelectionStart = data->SelectionEnd = strlen(data->Buf); + data->CursorPos = data->SelectionStart = data->SelectionEnd = (int)strlen(data->Buf); } } } From 3a206718026ab88d8cf57dedaa48d55b756097cb Mon Sep 17 00:00:00 2001 From: ocornut Date: Wed, 14 Jan 2015 13:01:53 +0000 Subject: [PATCH 05/16] Fixed logging to clipboard on architectures where va_list are modified by vsnprintf (fixed #112) --- imgui.cpp | 13 +++++++++++-- imgui.h | 2 +- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index e9033ae5..9ab99289 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -1,4 +1,4 @@ -// ImGui library v1.20 +// ImGui library v1.21 wip // See ImGui::ShowTestWindow() for sample code. // Read 'Programmer guide' below for notes on how to setup ImGui in your codebase. // Get latest version at https://github.com/ocornut/imgui @@ -1180,9 +1180,18 @@ bool ImGuiTextFilter::PassFilter(const char* val) const //----------------------------------------------------------------------------- +// On some platform vsnprintf() takes va_list by reference and modifies it. +// va_copy is the 'correct' way to copy a va_list but Visual Studio prior to 2013 doesn't have it. +#ifndef va_copy +#define va_copy(dest, src) (dest = src) +#endif + // Helper: Text buffer for logging/accumulating text void ImGuiTextBuffer::appendv(const char* fmt, va_list args) { + va_list args_copy; + va_copy(args_copy, args); + int len = vsnprintf(NULL, 0, fmt, args); // FIXME-OPT: could do a first pass write attempt, likely successful on first pass. if (len <= 0) return; @@ -1191,7 +1200,7 @@ void ImGuiTextBuffer::appendv(const char* fmt, va_list args) Buf.reserve(Buf.capacity() * 2); Buf.resize(write_off + (size_t)len); - ImFormatStringV(&Buf[write_off] - 1, (size_t)len+1, fmt, args); + ImFormatStringV(&Buf[write_off] - 1, (size_t)len+1, fmt, args_copy); } void ImGuiTextBuffer::append(const char* fmt, ...) diff --git a/imgui.h b/imgui.h index dc009ccc..0eaf64b6 100644 --- a/imgui.h +++ b/imgui.h @@ -1,4 +1,4 @@ -// ImGui library v1.20 +// ImGui library v1.21 wip // See .cpp file for commentary. // See ImGui::ShowTestWindow() for sample code. // Read 'Programmer guide' in .cpp for notes on how to setup ImGui in your codebase. From a372d67f478356b9bd321824fcac1a405b2da5d6 Mon Sep 17 00:00:00 2001 From: ocornut Date: Wed, 14 Jan 2015 13:04:33 +0000 Subject: [PATCH 06/16] Improve memory reserve policy for Clipboard/ImGuiBuffer --- imgui.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 9ab99289..3b1945cb 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -1195,11 +1195,16 @@ void ImGuiTextBuffer::appendv(const char* fmt, va_list args) int len = vsnprintf(NULL, 0, fmt, args); // FIXME-OPT: could do a first pass write attempt, likely successful on first pass. if (len <= 0) return; + const size_t write_off = Buf.size(); + const size_t needed_sz = write_off + (size_t)len; if (write_off + (size_t)len >= Buf.capacity()) - Buf.reserve(Buf.capacity() * 2); + { + const size_t double_capacity = Buf.capacity() * 2; + Buf.reserve(needed_sz > double_capacity ? needed_sz : double_capacity); + } - Buf.resize(write_off + (size_t)len); + Buf.resize(needed_sz); ImFormatStringV(&Buf[write_off] - 1, (size_t)len+1, fmt, args_copy); } @@ -1844,6 +1849,7 @@ static void LogText(const ImVec2& ref_pos, const char* text, const char* text_en const int tree_depth = (window->DC.TreeDepth - g.LogStartDepth); while (true) { + // Split the string. Each new line (after a '\n') is followed by spacing corresponding to the current depth of our log entry. const char* line_end = text_remaining; while (line_end < text_end) if (*line_end == '\n') From 04eca0c375d7de861aa5e617df99d795466e3d25 Mon Sep 17 00:00:00 2001 From: ocornut Date: Wed, 14 Jan 2015 13:43:41 +0000 Subject: [PATCH 07/16] TODO list update --- imgui.cpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 3b1945cb..59a4b76e 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -197,11 +197,12 @@ - window: fix resize grip rendering scaling along with Rounding style setting - window: autofit feedback loop when user relies on any dynamic layout (window width multiplier, column). maybe just clearly drop manual autofit? - window: add a way for very transient windows (non-saved, temporary overlay over hundreds of objects) to "clean" up from the global window list. + - window: allow resizing of child windows (possibly given min/max for each axis?) - widgets: switching from "widget-label" to "label-widget" would make it more convenient to integrate widgets in trees - widgets: clip text? hover clipped text shows it in a tooltip or in-place overlay - - widgets: IsItemHovered() returns true even if mouse is active on another widget (e.g. dragging outside of sliders). Maybe not a sensible default? Add parameter or alternate function? - - main: make IsHovered() more consistent for various type of widgets, widgets with multiple components, etc. also effectively IsHovered() region sometimes differs from hot region, e.g tree nodes - - main: make IsHovered() info stored in a stack? so that 'if TreeNode() { Text; TreePop; } if IsHovered' return the hover state of the TreeNode? + - main: IsItemHovered() returns true even if mouse is active on another widget (e.g. dragging outside of sliders). Maybe not a sensible default? Add parameter or alternate function? + - main: IsItemHovered() make it more consistent for various type of widgets, widgets with multiple components, etc. also effectively IsHovered() region sometimes differs from hot region, e.g tree nodes + - main: IsItemHovered() info stored in a stack? so that 'if TreeNode() { Text; TreePop; } if IsHovered' return the hover state of the TreeNode? - scrollbar: use relative mouse movement when first-clicking inside of scroll grab box. - scrollbar: make the grab visible and a minimum size for long scroll regions !- input number: very large int not reliably supported because of int<>float conversions. @@ -210,7 +211,7 @@ - input number: use mouse wheel to step up/down - input number: non-decimal input. - layout: horizontal layout helper (github issue #97) - - layout: clean up the InputFloatN/SliderFloatN/ColorEdit4 horrible layout code. item width should include frame padding. + - layout: clean up the InputFloatN/SliderFloatN/ColorEdit4 layout code. item width should include frame padding. - columns: separator function or parameter that works within the column (currently Separator() bypass all columns) - columns: declare column set (each column: fixed size, %, fill, distribute default size among fills) - columns: columns header to act as button (~sort op) and allow resize/reorder @@ -224,7 +225,7 @@ - file selection widget -> build the tool in our codebase to improve model-dialog idioms (may or not lead to ImGui changes) - slider: allow using the [-]/[+] buttons used by InputFloat()/InputInt() - slider: initial absolute click is imprecise. change to relative movement slider? hide mouse cursor, allow more precise input using less screen-space. - - text edit: clean up the horrible mess caused by converting UTF-8 <> wchar + - text edit: clean up the mess caused by converting UTF-8 <> wchar - text edit: centered text for slider or input text to it matches typical positioning. - text edit: flag to disable live update of the user buffer. - text edit: field resize behavior - field could stretch when being edited? hover tooltip shows more text? @@ -244,14 +245,11 @@ - tooltip: move to fit within screen (e.g. when mouse cursor is right of the screen). - clipboard: automatically transform \n into \n\r or equivalent for higher compatibility on windows - portability: big-endian test/support (github issue #81) - - examples: add History support in the demo console application (pertinent to github issue #68). - 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: add a button to output C code. - optimization/render: use indexed rendering to reduce vertex data cost (for remote/networked imgui) - optimization/render: move clip-rect to vertex data? would allow merging all commands - optimization/render: merge command-lists with same clip-rect into one even if they aren't sequential? (as long as in-between clip rectangle don't overlap)? - - optimization/render: font exported by bmfont is not tight fit on vertical axis, incur unneeded pixel-shading cost. - optimization: turn some the various stack vectors into statically-sized arrays - optimization: better clipping for multi-component widgets - optimization: specialize for height based clipping first (assume widgets never go up + height tests before width tests?) From 08b50cce1238240d82c3c1ba59e9372efc18aab3 Mon Sep 17 00:00:00 2001 From: ocornut Date: Wed, 14 Jan 2015 21:58:30 +0000 Subject: [PATCH 08/16] TODO list update --- imgui.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/imgui.cpp b/imgui.cpp index 59a4b76e..b487da38 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -198,6 +198,7 @@ - window: autofit feedback loop when user relies on any dynamic layout (window width multiplier, column). maybe just clearly drop manual autofit? - window: add a way for very transient windows (non-saved, temporary overlay over hundreds of objects) to "clean" up from the global window list. - window: allow resizing of child windows (possibly given min/max for each axis?) + - window: resizing from any sides? + mouse cursor directives for app. - widgets: switching from "widget-label" to "label-widget" would make it more convenient to integrate widgets in trees - widgets: clip text? hover clipped text shows it in a tooltip or in-place overlay - main: IsItemHovered() returns true even if mouse is active on another widget (e.g. dragging outside of sliders). Maybe not a sensible default? Add parameter or alternate function? @@ -232,6 +233,8 @@ - text edit: add multi-line text edit - settings: write more decent code to allow saving/loading new fields - settings: api for per-tool simple persistent data (bool,int,float) in .ini file + - style: checkbox: padding for "active" color should be a multiplier of the + - style: colorbox not always square? - log: LogButtons() options for specifying depth and/orhiding depth slider - log: have more control over the log scope (e.g. stop logging when leaving current tree node scope) - log: be able to right-click and log a window or tree-node into tty/file/clipboard / generalized context menu? @@ -247,6 +250,7 @@ - portability: big-endian test/support (github issue #81) - 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: color child window height expressed in multiple of line height. - optimization/render: use indexed rendering to reduce vertex data cost (for remote/networked imgui) - optimization/render: move clip-rect to vertex data? would allow merging all commands - optimization/render: merge command-lists with same clip-rect into one even if they aren't sequential? (as long as in-between clip rectangle don't overlap)? From 3c8f010c29c9c8fa96b2cb682f122f063dbc67c8 Mon Sep 17 00:00:00 2001 From: ocornut Date: Wed, 14 Jan 2015 22:10:48 +0000 Subject: [PATCH 09/16] Fixed TooltipBg color not being honored by tooltip + no minimum tooltip size. --- imgui.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index b487da38..a78912f8 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -348,7 +348,7 @@ ImGuiStyle::ImGuiStyle() { Alpha = 1.0f; // Global alpha applies to everything in ImGui WindowPadding = ImVec2(8,8); // Padding within a window - WindowMinSize = ImVec2(48,48); // Minimum window size + WindowMinSize = ImVec2(32,32); // Minimum window size WindowRounding = 9.0f; // Radius of window corners rounding. Set to 0.0f to have rectangular windows FramePadding = ImVec2(4,3); // Padding within a framed rectangle (used by most widgets) ItemSpacing = ImVec2(8,4); // Horizontal and vertical spacing between widgets/lines @@ -2158,7 +2158,8 @@ int ImGui::GetFrameCount() void ImGui::BeginTooltip() { - ImGui::Begin("##Tooltip", NULL, ImVec2(0,0), 0.9f, ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoMove|ImGuiWindowFlags_NoResize|ImGuiWindowFlags_NoSavedSettings|ImGuiWindowFlags_Tooltip); + ImGuiState& g = GImGui; + ImGui::Begin("##Tooltip", NULL, ImVec2(0,0), g.Style.Colors[ImGuiCol_TooltipBg].w, ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoMove|ImGuiWindowFlags_NoResize|ImGuiWindowFlags_NoSavedSettings|ImGuiWindowFlags_Tooltip); } void ImGui::EndTooltip() @@ -2410,7 +2411,7 @@ bool ImGui::Begin(const char* name, bool* p_opened, ImVec2 size, float fill_alph } // Clamp into view - if (!(window->Flags & ImGuiWindowFlags_ChildWindow)) + if (!(window->Flags & ImGuiWindowFlags_ChildWindow) && !(window->Flags & ImGuiWindowFlags_Tooltip)) { const ImVec2 pad = ImVec2(window->FontSize()*2.0f, window->FontSize()*2.0f); // FIXME: Parametrize of clarify this behavior. if (g.IO.DisplaySize.x > 0.0f && g.IO.DisplaySize.y > 0.0f) // Ignore zero-sized display explicitly to avoid losing positions if a window manager reports zero-sized window when initializing or minimizing. @@ -2544,6 +2545,8 @@ bool ImGui::Begin(const char* name, bool* p_opened, ImVec2 size, float fill_alph { if ((window->Flags & ImGuiWindowFlags_ComboBox) != 0) window->DrawList->AddRectFilled(window->Pos, window->Pos+window->Size, window->Color(ImGuiCol_ComboBg, fill_alpha), 0); + else if ((window->Flags & ImGuiWindowFlags_Tooltip) != 0) + window->DrawList->AddRectFilled(window->Pos, window->Pos+window->Size, window->Color(ImGuiCol_TooltipBg, fill_alpha), style.WindowRounding); else window->DrawList->AddRectFilled(window->Pos, window->Pos+window->Size, window->Color(ImGuiCol_WindowBg, fill_alpha), style.WindowRounding); } From 8ba93d947cc40cd266bc3094e128de8428def396 Mon Sep 17 00:00:00 2001 From: ocornut Date: Thu, 15 Jan 2015 09:14:44 +0000 Subject: [PATCH 10/16] Added FrameRounding setting (default to 0 for now). --- imgui.cpp | 22 +++++++++++++--------- imgui.h | 2 ++ 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index a78912f8..da660949 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -248,6 +248,7 @@ - tooltip: move to fit within screen (e.g. when mouse cursor is right of the screen). - clipboard: automatically transform \n into \n\r or equivalent for higher compatibility on windows - portability: big-endian test/support (github issue #81) + - misc: rounded triangle fail to draw correctly on OpenGL3 example. - 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: color child window height expressed in multiple of line height. @@ -351,6 +352,7 @@ ImGuiStyle::ImGuiStyle() WindowMinSize = ImVec2(32,32); // Minimum window size WindowRounding = 9.0f; // Radius of window corners rounding. Set to 0.0f to have rectangular windows FramePadding = ImVec2(4,3); // Padding within a framed rectangle (used by most widgets) + FrameRounding = 0.0f; // Radius of frame corners rounding. Set to 0.0f to have rectangular frames (used by most widgets). ItemSpacing = ImVec2(8,4); // Horizontal and vertical spacing between widgets/lines ItemInnerSpacing = ImVec2(4,4); // Horizontal and vertical spacing between within elements of a composed widget (e.g. a slider and its label) TouchExtraPadding = ImVec2(0,0); // Expand bounding box for touch-based system where touch position is not accurate enough (unnecessary for mouse inputs). Unfortunately we don't sort widgets so priority on overlap will always be given to the first widget running. So dont grow this too much! @@ -2830,6 +2832,7 @@ static float* GetStyleVarFloatAddr(ImGuiStyleVar idx) { case ImGuiStyleVar_Alpha: return &g.Style.Alpha; case ImGuiStyleVar_WindowRounding: return &g.Style.WindowRounding; + case ImGuiStyleVar_FrameRounding: return &g.Style.FrameRounding; case ImGuiStyleVar_TreeNodeSpacing: return &g.Style.TreeNodeSpacing; } return NULL; @@ -3446,7 +3449,7 @@ bool ImGui::Button(const char* label, ImVec2 size, bool repeat_when_held) // Render const ImU32 col = window->Color((hovered && held) ? ImGuiCol_ButtonActive : hovered ? ImGuiCol_ButtonHovered : ImGuiCol_Button); - RenderFrame(bb.Min, bb.Max, col); + RenderFrame(bb.Min, bb.Max, col, true, style.FrameRounding); if (size.x < text_size.x || size.y < text_size.y) PushClipRect(ImVec4(bb.Min.x+style.FramePadding.x, bb.Min.y+style.FramePadding.y, bb.Max.x, bb.Max.y-style.FramePadding.y)); // Allow extra to draw over the horizontal padding to make it visible that text doesn't fit @@ -4032,7 +4035,7 @@ bool ImGui::SliderFloat(const char* label, float* v, float v_min, float v_max, c } ItemSize(bb); - RenderFrame(frame_bb.Min, frame_bb.Max, window->Color(ImGuiCol_FrameBg)); + RenderFrame(frame_bb.Min, frame_bb.Max, window->Color(ImGuiCol_FrameBg), true, style.FrameRounding); // Process clicking on the slider if (g.ActiveId == id) @@ -4290,7 +4293,7 @@ static void Plot(ImGuiPlotType plot_type, const char* label, float (*values_gett scale_max = v_max; } - RenderFrame(frame_bb.Min, frame_bb.Max, window->Color(ImGuiCol_FrameBg)); + RenderFrame(frame_bb.Min, frame_bb.Max, window->Color(ImGuiCol_FrameBg), true, style.FrameRounding); int res_w = ImMin((int)graph_size.x, values_count); if (plot_type == ImGuiPlotType_Lines) @@ -4416,12 +4419,12 @@ bool ImGui::Checkbox(const char* label, bool* v) if (pressed) *v = !(*v); - RenderFrame(check_bb.Min, check_bb.Max, window->Color((held && hovered) ? ImGuiCol_CheckActive : hovered ? ImGuiCol_CheckHovered : ImGuiCol_FrameBg)); + RenderFrame(check_bb.Min, check_bb.Max, window->Color((held && hovered) ? ImGuiCol_CheckActive : hovered ? ImGuiCol_CheckHovered : ImGuiCol_FrameBg), true, style.FrameRounding); if (*v) { const float check_sz = ImMin(check_bb.GetWidth(), check_bb.GetHeight()); const float pad = check_sz < 8.0f ? 1.0f : check_sz < 13.0f ? 2.0f : 3.0f; - window->DrawList->AddRectFilled(check_bb.Min+ImVec2(pad,pad), check_bb.Max-ImVec2(pad,pad), window->Color(ImGuiCol_CheckMark)); + window->DrawList->AddRectFilled(check_bb.Min+ImVec2(pad,pad), check_bb.Max-ImVec2(pad,pad), window->Color(ImGuiCol_CheckMark), style.FrameRounding); } if (g.LogEnabled) @@ -5020,7 +5023,7 @@ bool ImGui::InputText(const char* label, char* buf, size_t buf_size, ImGuiInputT } } - RenderFrame(frame_bb.Min, frame_bb.Max, window->Color(ImGuiCol_FrameBg), true); + RenderFrame(frame_bb.Min, frame_bb.Max, window->Color(ImGuiCol_FrameBg), true, style.FrameRounding); const ImVec2 font_off_up = ImVec2(0.0f,window->FontSize()+1.0f); // FIXME: those offsets are part of the style or font API const ImVec2 font_off_dn = ImVec2(0.0f,2.0f); @@ -5187,8 +5190,8 @@ bool ImGui::Combo(const char* label, int* current_item, bool (*items_getter)(voi const bool hovered = IsHovered(frame_bb, id); bool value_changed = false; - RenderFrame(frame_bb.Min, frame_bb.Max, window->Color(ImGuiCol_FrameBg)); - RenderFrame(ImVec2(frame_bb.Max.x-arrow_size, frame_bb.Min.y), frame_bb.Max, window->Color(hovered ? ImGuiCol_ButtonHovered : ImGuiCol_Button)); + RenderFrame(frame_bb.Min, frame_bb.Max, window->Color(ImGuiCol_FrameBg), true, style.FrameRounding); + RenderFrame(ImVec2(frame_bb.Max.x-arrow_size, frame_bb.Min.y), frame_bb.Max, window->Color(hovered ? ImGuiCol_ButtonHovered : ImGuiCol_Button), true, style.FrameRounding); // FIXME-ROUNDING RenderCollapseTriangle(ImVec2(frame_bb.Max.x-arrow_size, frame_bb.Min.y) + style.FramePadding, true); if (*current_item >= 0 && *current_item < items_count) @@ -5304,7 +5307,7 @@ bool ImGui::ColorButton(const ImVec4& col, bool small_height, bool outline_borde const bool hovered = IsHovered(bb, 0); const bool pressed = hovered && g.IO.MouseClicked[0]; - RenderFrame(bb.Min, bb.Max, window->Color(col), outline_border); + RenderFrame(bb.Min, bb.Max, window->Color(col), outline_border, style.FrameRounding); if (hovered) { @@ -6889,6 +6892,7 @@ void ImGui::ShowStyleEditor(ImGuiStyle* ref) ImGui::SliderFloat2("WindowPadding", (float*)&style.WindowPadding, 0.0f, 20.0f, "%.0f"); ImGui::SliderFloat("WindowRounding", &style.WindowRounding, 0.0f, 16.0f, "%.0f"); ImGui::SliderFloat2("FramePadding", (float*)&style.FramePadding, 0.0f, 20.0f, "%.0f"); + ImGui::SliderFloat("FrameRounding", &style.FrameRounding, 0.0f, 16.0f, "%.0f"); ImGui::SliderFloat2("ItemSpacing", (float*)&style.ItemSpacing, 0.0f, 20.0f, "%.0f"); ImGui::SliderFloat2("ItemInnerSpacing", (float*)&style.ItemInnerSpacing, 0.0f, 20.0f, "%.0f"); ImGui::SliderFloat2("TouchExtraPadding", (float*)&style.TouchExtraPadding, 0.0f, 10.0f, "%.0f"); diff --git a/imgui.h b/imgui.h index 0eaf64b6..849b0ada 100644 --- a/imgui.h +++ b/imgui.h @@ -422,6 +422,7 @@ enum ImGuiStyleVar_ ImGuiStyleVar_WindowPadding, // ImVec2 ImGuiStyleVar_WindowRounding, // float ImGuiStyleVar_FramePadding, // ImVec2 + ImGuiStyleVar_FrameRounding, // float ImGuiStyleVar_ItemSpacing, // ImVec2 ImGuiStyleVar_ItemInnerSpacing, // ImVec2 ImGuiStyleVar_TreeNodeSpacing, // float @@ -452,6 +453,7 @@ struct ImGuiStyle ImVec2 WindowMinSize; // Minimum window size float WindowRounding; // Radius of window corners rounding. Set to 0.0f to have rectangular windows ImVec2 FramePadding; // Padding within a framed rectangle (used by most widgets) + float FrameRounding; // Radius of frame corners rounding. Set to 0.0f to have rectangular frame (used by most widgets). ImVec2 ItemSpacing; // Horizontal and vertical spacing between widgets/lines ImVec2 ItemInnerSpacing; // Horizontal and vertical spacing between within elements of a composed widget (e.g. a slider and its label) ImVec2 TouchExtraPadding; // Expand bounding box for touch-based system where touch position is not accurate enough (unnecessary for mouse inputs). Unfortunately we don't sort widgets so priority on overlap will always be given to the first widget running. So dont grow this too much! From 02f0dbca37d316c533c6fa4cab0eb72551f8c776 Mon Sep 17 00:00:00 2001 From: ocornut Date: Thu, 15 Jan 2015 09:49:12 +0000 Subject: [PATCH 11/16] ColorEdit3: clicking on color square change edit-mode, removing color-edit mode button by default. --- imgui.cpp | 16 +++++++++++----- imgui.h | 3 ++- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index da660949..7d4944f6 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -5298,6 +5298,7 @@ bool ImGui::ColorButton(const ImVec4& col, bool small_height, bool outline_borde return false; const ImGuiStyle& style = g.Style; + const ImGuiID id = window->GetID("##colorbutton"); const float square_size = window->FontSize(); const ImGuiAabb bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(square_size + style.FramePadding.x*2, square_size + (small_height ? 0 : style.FramePadding.y*2))); ItemSize(bb); @@ -5305,8 +5306,8 @@ bool ImGui::ColorButton(const ImVec4& col, bool small_height, bool outline_borde if (ClipAdvance(bb)) return false; - const bool hovered = IsHovered(bb, 0); - const bool pressed = hovered && g.IO.MouseClicked[0]; + bool hovered, held; + bool pressed = ButtonBehaviour(bb, id, &hovered, &held, true); RenderFrame(bb.Min, bb.Max, window->Color(col), outline_border, style.FrameRounding); if (hovered) @@ -5350,7 +5351,7 @@ bool ImGui::ColorEdit4(const char* label, float col[4], bool alpha) const float square_sz = (window->FontSize() + style.FramePadding.x * 2.0f); ImGuiColorEditMode edit_mode = window->DC.ColorEditMode; - if (edit_mode == ImGuiColorEditMode_UserSelect) + if (edit_mode == ImGuiColorEditMode_UserSelect || edit_mode == ImGuiColorEditMode_UserSelectShowButton) edit_mode = g.ColorEditModeStorage.GetInt(id, 0) % 3; float fx = col[0]; @@ -5432,9 +5433,13 @@ bool ImGui::ColorEdit4(const char* label, float col[4], bool alpha) } ImGui::SameLine(0, (int)style.ItemInnerSpacing.x); - ImGui::ColorButton(col_display); + if (ImGui::ColorButton(col_display)) + { + // Don't set local copy of 'edit_mode' right away! + g.ColorEditModeStorage.SetInt(id, (edit_mode + 1) % 3); + } - if (window->DC.ColorEditMode == ImGuiColorEditMode_UserSelect) + if (window->DC.ColorEditMode == ImGuiColorEditMode_UserSelectShowButton) { ImGui::SameLine(0, (int)style.ItemInnerSpacing.x); const char* button_titles[3] = { "RGB", "HSV", "HEX" }; @@ -6930,6 +6935,7 @@ void ImGui::ShowStyleEditor(ImGuiStyle* ref) ImGui::RadioButton("HSV", &edit_mode, ImGuiColorEditMode_HSV); ImGui::SameLine(); ImGui::RadioButton("HEX", &edit_mode, ImGuiColorEditMode_HEX); + //ImGui::Text("Tip: Click on colored square to change edit mode."); static ImGuiTextFilter filter; filter.Draw("Filter colors", 200); diff --git a/imgui.h b/imgui.h index 849b0ada..1cc8fb4c 100644 --- a/imgui.h +++ b/imgui.h @@ -431,7 +431,8 @@ enum ImGuiStyleVar_ // Enumeration for ColorEditMode() enum ImGuiColorEditMode_ { - ImGuiColorEditMode_UserSelect = -1, + ImGuiColorEditMode_UserSelect = -2, + ImGuiColorEditMode_UserSelectShowButton = -1, ImGuiColorEditMode_RGB = 0, ImGuiColorEditMode_HSV = 1, ImGuiColorEditMode_HEX = 2 From 62ecdd21a53a90353285466dc36bc69880b75332 Mon Sep 17 00:00:00 2001 From: ocornut Date: Thu, 15 Jan 2015 09:59:18 +0000 Subject: [PATCH 12/16] Examples: Added a color slider for the background color + tweak first example use of button.s --- examples/directx11_example/main.cpp | 16 ++++++++-------- examples/directx9_example/main.cpp | 18 ++++++++++-------- examples/opengl3_example/main.cpp | 18 ++++++++++-------- examples/opengl_example/main.cpp | 16 +++++++++------- 4 files changed, 37 insertions(+), 31 deletions(-) diff --git a/examples/directx11_example/main.cpp b/examples/directx11_example/main.cpp index ec3e20aa..7acb36d4 100644 --- a/examples/directx11_example/main.cpp +++ b/examples/directx11_example/main.cpp @@ -540,6 +540,10 @@ int WINAPI wWinMain(HINSTANCE hInst, HINSTANCE, LPWSTR, int) InitImGui(); + bool show_test_window = true; + bool show_another_window = false; + ImVec4 clear_col(0.8f, 0.6f, 0.6f, 1.0f); + // Enter the message loop MSG msg; ZeroMemory(&msg, sizeof(msg)); @@ -551,20 +555,17 @@ int WINAPI wWinMain(HINSTANCE hInst, HINSTANCE, LPWSTR, int) DispatchMessage(&msg); continue; } - UpdateImGui(); - static bool show_test_window = true; - static bool show_another_window = false; - // 1. Show a simple window // Tip: if we don't call ImGui::Begin()/ImGui::End() the widgets appears in a window automatically called "Debug" { static float f; ImGui::Text("Hello, world!"); ImGui::SliderFloat("float", &f, 0.0f, 1.0f); - show_test_window ^= ImGui::Button("Test Window"); - show_another_window ^= ImGui::Button("Another Window"); + ImGui::ColorEdit3("clear color", (float*)&clear_col); + if (ImGui::Button("Test Window")) show_test_window ^= 1; + if (ImGui::Button("Another Window")) show_another_window ^= 1; // Calculate and show frame rate static float ms_per_frame[120] = { 0 }; @@ -594,8 +595,7 @@ int WINAPI wWinMain(HINSTANCE hInst, HINSTANCE, LPWSTR, int) } // Rendering - float clearColor[4] = { 204 / 255.f, 153 / 255.f, 153 / 255.f }; - g_pd3dDeviceImmediateContext->ClearRenderTargetView(g_mainRenderTargetView, clearColor); + g_pd3dDeviceImmediateContext->ClearRenderTargetView(g_mainRenderTargetView, (float*)&clear_col); ImGui::Render(); g_pSwapChain->Present(0, 0); } diff --git a/examples/directx9_example/main.cpp b/examples/directx9_example/main.cpp index fe4f15d7..d95d8084 100644 --- a/examples/directx9_example/main.cpp +++ b/examples/directx9_example/main.cpp @@ -281,6 +281,10 @@ int WINAPI wWinMain(HINSTANCE hInst, HINSTANCE, LPWSTR, int) InitImGui(); + bool show_test_window = true; + bool show_another_window = false; + ImVec4 clear_col(0.8f, 0.6f, 0.6f, 1.0f); + // Enter the message loop MSG msg; ZeroMemory(&msg, sizeof(msg)); @@ -292,20 +296,17 @@ int WINAPI wWinMain(HINSTANCE hInst, HINSTANCE, LPWSTR, int) DispatchMessage(&msg); continue; } - UpdateImGui(); - static bool show_test_window = true; - static bool show_another_window = false; - // 1. Show a simple window // Tip: if we don't call ImGui::Begin()/ImGui::End() the widgets appears in a window automatically called "Debug" { static float f; ImGui::Text("Hello, world!"); ImGui::SliderFloat("float", &f, 0.0f, 1.0f); - show_test_window ^= ImGui::Button("Test Window"); - show_another_window ^= ImGui::Button("Another Window"); + ImGui::ColorEdit3("clear color", (float*)&clear_col); + if (ImGui::Button("Test Window")) show_test_window ^= 1; + if (ImGui::Button("Another Window")) show_another_window ^= 1; // Calculate and show frame rate static float ms_per_frame[120] = { 0 }; @@ -330,7 +331,7 @@ int WINAPI wWinMain(HINSTANCE hInst, HINSTANCE, LPWSTR, int) // 3. Show the ImGui test window. Most of the sample code is in ImGui::ShowTestWindow() if (show_test_window) { - ImGui::SetNextWindowPos(ImVec2(650, 20), ImGuiSetCondition_FirstUseEver); + ImGui::SetNextWindowPos(ImVec2(650, 20), ImGuiSetCondition_FirstUseEver); ImGui::ShowTestWindow(&show_test_window); } @@ -338,7 +339,8 @@ int WINAPI wWinMain(HINSTANCE hInst, HINSTANCE, LPWSTR, int) g_pd3dDevice->SetRenderState(D3DRS_ZENABLE, false); g_pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, false); g_pd3dDevice->SetRenderState(D3DRS_SCISSORTESTENABLE, false); - g_pd3dDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(204, 153, 153), 1.0f, 0); + D3DCOLOR clear_col_dx = D3DCOLOR_RGBA((int)(clear_col.x*255.0f), (int)(clear_col.y*255.0f), (int)(clear_col.z*255.0f), (int)(clear_col.w*255.0f)); + g_pd3dDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, clear_col_dx, 1.0f, 0); if (g_pd3dDevice->BeginScene() >= 0) { ImGui::Render(); diff --git a/examples/opengl3_example/main.cpp b/examples/opengl3_example/main.cpp index 91dcd149..8fb02c47 100644 --- a/examples/opengl3_example/main.cpp +++ b/examples/opengl3_example/main.cpp @@ -169,7 +169,7 @@ void InitGL() glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); - window = glfwCreateWindow(1280, 720, "ImGui OpenGL example", NULL, NULL); + window = glfwCreateWindow(1280, 720, "ImGui OpenGL3 example", NULL, NULL); glfwMakeContextCurrent(window); glfwSetKeyCallback(window, glfw_key_callback); glfwSetMouseButtonCallback(window, glfw_mouse_button_callback); @@ -321,6 +321,10 @@ int main(int argc, char** argv) InitGL(); InitImGui(); + bool show_test_window = true; + bool show_another_window = false; + ImVec4 clear_col(0.8f, 0.6f, 0.6f, 1.0f); + while (!glfwWindowShouldClose(window)) { ImGuiIO& io = ImGui::GetIO(); @@ -329,17 +333,15 @@ int main(int argc, char** argv) glfwPollEvents(); UpdateImGui(); - static bool show_test_window = true; - static bool show_another_window = false; - // 1. Show a simple window // Tip: if we don't call ImGui::Begin()/ImGui::End() the widgets appears in a window automatically called "Debug" { static float f; ImGui::Text("Hello, world!"); ImGui::SliderFloat("float", &f, 0.0f, 1.0f); - show_test_window ^= ImGui::Button("Test Window"); - show_another_window ^= ImGui::Button("Another Window"); + ImGui::ColorEdit3("clear color", (float*)&clear_col); + if (ImGui::Button("Test Window")) show_test_window ^= 1; + if (ImGui::Button("Another Window")) show_another_window ^= 1; // Calculate and show frame rate static float ms_per_frame[120] = { 0 }; @@ -364,13 +366,13 @@ int main(int argc, char** argv) // 3. Show the ImGui test window. Most of the sample code is in ImGui::ShowTestWindow() if (show_test_window) { - ImGui::SetNextWindowPos(ImVec2(650, 20), ImGuiSetCondition_FirstUseEver); + ImGui::SetNextWindowPos(ImVec2(650, 20), ImGuiSetCondition_FirstUseEver); ImGui::ShowTestWindow(&show_test_window); } // Rendering glViewport(0, 0, (int)io.DisplaySize.x, (int)io.DisplaySize.y); - glClearColor(0.8f, 0.6f, 0.6f, 1.0f); + glClearColor(clear_col.x, clear_col.y, clear_col.z, clear_col.w); glClear(GL_COLOR_BUFFER_BIT); ImGui::Render(); glfwSwapBuffers(window); diff --git a/examples/opengl_example/main.cpp b/examples/opengl_example/main.cpp index 12989cb4..92cf457e 100644 --- a/examples/opengl_example/main.cpp +++ b/examples/opengl_example/main.cpp @@ -143,7 +143,7 @@ void InitGL() if (!glfwInit()) exit(1); - window = glfwCreateWindow(1280, 720, "ImGui OpenGL example", NULL, NULL); + window = glfwCreateWindow(1280, 720, "ImGui OpenGL2 example", NULL, NULL); glfwMakeContextCurrent(window); glfwSetKeyCallback(window, glfw_key_callback); glfwSetMouseButtonCallback(window, glfw_mouse_button_callback); @@ -255,6 +255,10 @@ int main(int argc, char** argv) InitGL(); InitImGui(); + bool show_test_window = true; + bool show_another_window = false; + ImVec4 clear_col(0.8f, 0.6f, 0.6f, 1.0f); + while (!glfwWindowShouldClose(window)) { ImGuiIO& io = ImGui::GetIO(); @@ -262,17 +266,15 @@ int main(int argc, char** argv) glfwPollEvents(); UpdateImGui(); - static bool show_test_window = true; - static bool show_another_window = false; - // 1. Show a simple window // Tip: if we don't call ImGui::Begin()/ImGui::End() the widgets appears in a window automatically called "Debug" { static float f; ImGui::Text("Hello, world!"); ImGui::SliderFloat("float", &f, 0.0f, 1.0f); - show_test_window ^= ImGui::Button("Test Window"); - show_another_window ^= ImGui::Button("Another Window"); + ImGui::ColorEdit3("clear color", (float*)&clear_col); + if (ImGui::Button("Test Window")) show_test_window ^= 1; + if (ImGui::Button("Another Window")) show_another_window ^= 1; // Calculate and show frame rate static float ms_per_frame[120] = { 0 }; @@ -303,7 +305,7 @@ int main(int argc, char** argv) // Rendering glViewport(0, 0, (int)io.DisplaySize.x, (int)io.DisplaySize.y); - glClearColor(0.8f, 0.6f, 0.6f, 1.0f); + glClearColor(clear_col.x, clear_col.y, clear_col.z, clear_col.w); glClear(GL_COLOR_BUFFER_BIT); ImGui::Render(); glfwSwapBuffers(window); From 2d7a2310fdfa9559f8d958d54396f8cae82d5df7 Mon Sep 17 00:00:00 2001 From: ocornut Date: Thu, 15 Jan 2015 10:29:51 +0000 Subject: [PATCH 13/16] Collapsing header also honor FrameRounding --- imgui.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/imgui.cpp b/imgui.cpp index 7d4944f6..61ad4d8a 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -3693,7 +3693,7 @@ bool ImGui::CollapsingHeader(const char* label, const char* str_id, const bool d if (display_frame) { // Framed type - RenderFrame(bb.Min, bb.Max, col, true); + RenderFrame(bb.Min, bb.Max, col, true, style.FrameRounding); RenderCollapseTriangle(bb.Min + style.FramePadding, opened, 1.0f, true); if (g.LogEnabled) { From 584c7ffac8a49e4abde6c8a3a47df5a6c61bbdcf Mon Sep 17 00:00:00 2001 From: ocornut Date: Thu, 15 Jan 2015 14:41:22 +0000 Subject: [PATCH 14/16] Added SetCursorScreenPos() helper (WindowPos+CursorPos = SrceenPos) --- imgui.cpp | 8 ++++++++ imgui.h | 3 ++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/imgui.cpp b/imgui.cpp index 61ad4d8a..23a36630 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -3111,6 +3111,8 @@ void ImGui::SetWindowFontScale(float scale) window->FontWindowScale = scale; } +// NB: internally we store CursorPos in absolute screen coordinates because it is more convenient. +// Conversion happens as we pass the value to user, but it makes our naming convention dodgy. May want to rename 'DC.CursorPos'. ImVec2 ImGui::GetCursorPos() { ImGuiWindow* window = GetCurrentWindow(); @@ -3141,6 +3143,12 @@ ImVec2 ImGui::GetCursorScreenPos() return window->DC.CursorPos; } +void ImGui::SetCursorScreenPos(const ImVec2& screen_pos) +{ + ImGuiWindow* window = GetCurrentWindow(); + window->DC.CursorPos = screen_pos; +} + void ImGui::SetScrollPosHere() { ImGuiWindow* window = GetCurrentWindow(); diff --git a/imgui.h b/imgui.h index 1cc8fb4c..a798a05a 100644 --- a/imgui.h +++ b/imgui.h @@ -206,7 +206,8 @@ namespace ImGui IMGUI_API void SetCursorPos(const ImVec2& pos); // " IMGUI_API void SetCursorPosX(float x); // " IMGUI_API void SetCursorPosY(float y); // " - IMGUI_API ImVec2 GetCursorScreenPos(); // cursor position in screen space + IMGUI_API ImVec2 GetCursorScreenPos(); // cursor position in absolute screen coordinates (0..io.DisplaySize) + IMGUI_API void SetCursorScreenPos(const ImVec2& pos); // cursor position in absolute screen coordinates (0..io.DisplaySize) IMGUI_API void AlignFirstTextHeightToWidgets(); // call once if the first item on the line is a Text() item and you want to vertically lower it to match subsequent (bigger) widgets. IMGUI_API float GetTextLineSpacing(); IMGUI_API float GetTextLineHeight(); From 2082487366dc0ecd53c0b6c9c3febacb40feaf94 Mon Sep 17 00:00:00 2001 From: ocornut Date: Thu, 15 Jan 2015 17:47:53 +0000 Subject: [PATCH 15/16] Allow SetNextWindowPos() to affect tooltips. --- imgui.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 23a36630..bf3f62b0 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -2311,11 +2311,13 @@ bool ImGui::Begin(const char* name, bool* p_opened, ImVec2 size, float fill_alph g.CurrentWindow = window; // Process SetNextWindow***() calls + bool window_pos_set_by_api = false; if (g.SetNextWindowPosCond) { const ImVec2 backup_cursor_pos = window->DC.CursorPos; ImGui::SetWindowPos(g.SetNextWindowPosVal, g.SetNextWindowPosCond); window->DC.CursorPos = backup_cursor_pos; + window_pos_set_by_api = true; g.SetNextWindowPosCond = 0; } if (g.SetNextWindowSizeCond) @@ -2406,8 +2408,8 @@ bool ImGui::Begin(const char* name, bool* p_opened, ImVec2 size, float fill_alph } } - // Tooltips always follow mouse - if ((window->Flags & ImGuiWindowFlags_Tooltip) != 0) + // Tooltips always follows mouse + if (!window_pos_set_by_api && (window->Flags & ImGuiWindowFlags_Tooltip) != 0) { window->PosFloat = g.IO.MousePos + ImVec2(32,16) - style.FramePadding*2; } @@ -2425,7 +2427,7 @@ bool ImGui::Begin(const char* name, bool* p_opened, ImVec2 size, float fill_alph } window->Pos = ImVec2((float)(int)window->PosFloat.x, (float)(int)window->PosFloat.y); - // Default item width + // Default item width. Make it proportional to window size if window manually resizes if (window->Size.x > 0.0f && !(window->Flags & ImGuiWindowFlags_Tooltip) && !(window->Flags & ImGuiWindowFlags_AlwaysAutoResize)) window->ItemWidthDefault = (float)(int)(window->Size.x * 0.65f); else @@ -2513,7 +2515,7 @@ bool ImGui::Begin(const char* name, bool* p_opened, ImVec2 size, float fill_alph } else if (!(window->Flags & ImGuiWindowFlags_NoResize)) { - // Resize grip + // Manual resize grip const ImGuiAabb resize_aabb(window->Aabb().GetBR()-ImVec2(18,18), window->Aabb().GetBR()); const ImGuiID resize_id = window->GetID("##RESIZE"); bool hovered, held; @@ -2522,7 +2524,7 @@ bool ImGui::Begin(const char* name, bool* p_opened, ImVec2 size, float fill_alph if (g.HoveredWindow == window && held && g.IO.MouseDoubleClicked[0]) { - // Manual auto-fit + // Manual auto-fit when double-clicking window->SizeFull = size_auto_fit; window->Size = window->SizeFull; if (!(window->Flags & ImGuiWindowFlags_NoSavedSettings)) @@ -2538,7 +2540,7 @@ bool ImGui::Begin(const char* name, bool* p_opened, ImVec2 size, float fill_alph } } - // Update aabb immediately so that the rendering below isn't one frame late + // Update aabb immediately so that rendering right below us isn't one frame late title_bar_aabb = window->TitleBarAabb(); } From f61e8e6e26988e9de14bda3b070851f9a1595a79 Mon Sep 17 00:00:00 2001 From: ocornut Date: Thu, 15 Jan 2015 18:00:10 +0000 Subject: [PATCH 16/16] Tooltip always auto-resize. May look into max-over-xx-seconds policy later. --- imgui.cpp | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index bf3f62b0..14589d01 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -2161,7 +2161,8 @@ int ImGui::GetFrameCount() void ImGui::BeginTooltip() { ImGuiState& g = GImGui; - ImGui::Begin("##Tooltip", NULL, ImVec2(0,0), g.Style.Colors[ImGuiCol_TooltipBg].w, ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoMove|ImGuiWindowFlags_NoResize|ImGuiWindowFlags_NoSavedSettings|ImGuiWindowFlags_Tooltip); + ImGuiWindowFlags window_flags = ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoMove|ImGuiWindowFlags_NoResize|ImGuiWindowFlags_NoSavedSettings|ImGuiWindowFlags_AlwaysAutoResize|ImGuiWindowFlags_Tooltip; + ImGui::Begin("##Tooltip", NULL, ImVec2(0,0), g.Style.Colors[ImGuiCol_TooltipBg].w, window_flags); } void ImGui::EndTooltip() @@ -2355,16 +2356,7 @@ bool ImGui::Begin(const char* name, bool* p_opened, ImVec2 size, float fill_alph // New windows appears in front if (window->LastFrameDrawn < current_frame - 1) - { FocusWindow(window); - if ((window->Flags & ImGuiWindowFlags_Tooltip) != 0) - { - // Hide for 1 frame while resizing - window->AutoFitFrames = 2; - window->AutoFitOnlyGrows = false; - window->Visible = false; - } - } window->LastFrameDrawn = current_frame; window->ClipRectStack.resize(0); @@ -2489,11 +2481,9 @@ bool ImGui::Begin(const char* name, bool* p_opened, ImVec2 size, float fill_alph ImU32 resize_col = 0; if ((window->Flags & ImGuiWindowFlags_Tooltip) != 0) { - // Tooltip always resize - if (window->AutoFitFrames > 0) - { - window->SizeFull = window->SizeContentsFit + style.WindowPadding - ImVec2(0.0f, style.ItemSpacing.y); - } + // Tooltip always resize. We keep the spacing symmetric on both axises for aesthetic purpose. + const ImVec2 size_auto_fit = window->SizeContentsFit + style.WindowPadding - ImVec2(0.0f, style.ItemSpacing.y); + window->SizeFull = size_auto_fit; } else {