mirror of
https://github.com/Drezil/imgui.git
synced 2025-07-14 00:39:55 +02:00
Merge branch 'master' into 2016-02-colorpicker
This commit is contained in:
82
imgui.cpp
82
imgui.cpp
@ -1,4 +1,4 @@
|
||||
// dear imgui, v1.48 WIP
|
||||
// dear imgui, v1.49 WIP
|
||||
// (main code and documentation)
|
||||
|
||||
// See ImGui::ShowTestWindow() in imgui_demo.cpp for demo code.
|
||||
@ -152,6 +152,8 @@
|
||||
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/04/03 (1.48) - removed style.WindowFillAlphaDefault setting which was redundant. Bake default BG alpha inside style.Colors[ImGuiCol_WindowBg] and all other Bg color values. (ref github issue #337).
|
||||
- 2016/04/03 (1.48) - renamed ImGuiCol_TooltipBg to ImGuiCol_PopupBg, used by popups/menus and tooltips. popups/menus were previously using ImGuiCol_WindowBg. (ref github issue #337)
|
||||
- 2016/03/21 (1.48) - renamed GetWindowFont() to GetFont(), GetWindowFontSize() to GetFontSize(). Kept inline redirection function (will obsolete).
|
||||
- 2016/03/02 (1.48) - InputText() completion/history/always callbacks: if you modify the text buffer manually (without using DeleteChars()/InsertChars() helper) you need to maintain the BufTextLen field. added an assert.
|
||||
- 2016/02/21 (1.48) - removed ColorEditMode() and ImGuiColorEditMode in favor of ImGuiColorEditFlags and parameters to ColorEdit*() functions
|
||||
@ -506,6 +508,7 @@
|
||||
- color: add a better color picker (#346)
|
||||
- node/graph editor (#306)
|
||||
- pie menus patterns (#434)
|
||||
- drag'n drop, dragging helpers (carry dragging info, visualize drag source before clicking, drop target, etc.) (#143, #479)
|
||||
- plot: PlotLines() should use the polygon-stroke facilities (currently issues with averaging normals)
|
||||
- plot: make it easier for user to draw extra stuff into the graph (e.g: draw basis, highlight certain points, 2d plots, multiple plots)
|
||||
- plot: "smooth" automatic scale over time, user give an input 0.0(full user scale) 1.0(full derived from value)
|
||||
@ -694,13 +697,12 @@ 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
|
||||
WindowTitleAlign = ImGuiAlign_Left; // Alignment for title bar text
|
||||
ChildWindowRounding = 0.0f; // Radius of child window corners rounding. Set to 0.0f to have rectangular windows
|
||||
ChildWindowRounding = 0.0f; // Radius of child window corners rounding. Set to 0.0f to have rectangular child 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 reactive bounding box for touch-based system where touch position is not accurate enough. Unfortunately we don't sort widgets so priority on overlap will always be given to the first widget. So don't grow this too much!
|
||||
WindowFillAlphaDefault = 0.70f; // Default alpha of window background, if not specified in ImGui::Begin()
|
||||
IndentSpacing = 22.0f; // Horizontal spacing when e.g. entering a tree node
|
||||
ColumnsMinSpacing = 6.0f; // Minimum horizontal spacing between two columns
|
||||
ScrollbarSize = 16.0f; // Width of the vertical scrollbar, Height of the horizontal scrollbar
|
||||
@ -715,8 +717,9 @@ ImGuiStyle::ImGuiStyle()
|
||||
|
||||
Colors[ImGuiCol_Text] = ImVec4(0.90f, 0.90f, 0.90f, 1.00f);
|
||||
Colors[ImGuiCol_TextDisabled] = ImVec4(0.60f, 0.60f, 0.60f, 1.00f);
|
||||
Colors[ImGuiCol_WindowBg] = ImVec4(0.00f, 0.00f, 0.00f, 1.00f);
|
||||
Colors[ImGuiCol_WindowBg] = ImVec4(0.00f, 0.00f, 0.00f, 0.70f);
|
||||
Colors[ImGuiCol_ChildWindowBg] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f);
|
||||
Colors[ImGuiCol_PopupBg] = ImVec4(0.05f, 0.05f, 0.10f, 0.90f);
|
||||
Colors[ImGuiCol_Border] = ImVec4(0.70f, 0.70f, 0.70f, 0.65f);
|
||||
Colors[ImGuiCol_BorderShadow] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f);
|
||||
Colors[ImGuiCol_FrameBg] = ImVec4(0.80f, 0.80f, 0.80f, 0.30f); // Background of checkbox, radio button, plot, slider, text input
|
||||
@ -754,7 +757,6 @@ ImGuiStyle::ImGuiStyle()
|
||||
Colors[ImGuiCol_PlotHistogram] = ImVec4(0.90f, 0.70f, 0.00f, 1.00f);
|
||||
Colors[ImGuiCol_PlotHistogramHovered] = ImVec4(1.00f, 0.60f, 0.00f, 1.00f);
|
||||
Colors[ImGuiCol_TextSelectedBg] = ImVec4(0.00f, 0.00f, 1.00f, 0.35f);
|
||||
Colors[ImGuiCol_TooltipBg] = ImVec4(0.05f, 0.05f, 0.10f, 0.90f);
|
||||
Colors[ImGuiCol_ModalWindowDarkening] = ImVec4(0.20f, 0.20f, 0.20f, 0.35f);
|
||||
}
|
||||
|
||||
@ -1652,7 +1654,7 @@ ImGuiWindow* ImGui::GetParentWindow()
|
||||
{
|
||||
ImGuiState& g = *GImGui;
|
||||
IM_ASSERT(g.CurrentWindowStack.Size >= 2);
|
||||
return g.CurrentWindowStack[g.CurrentWindowStack.Size - 2];
|
||||
return g.CurrentWindowStack[(unsigned int)g.CurrentWindowStack.Size - 2];
|
||||
}
|
||||
|
||||
void ImGui::SetActiveID(ImGuiID id, ImGuiWindow* window = NULL)
|
||||
@ -2339,9 +2341,9 @@ static void AddDrawListToRenderList(ImVector<ImDrawList*>& out_render_list, ImDr
|
||||
|
||||
// Check that draw_list doesn't use more vertices than indexable (default ImDrawIdx = 2 bytes = 64K vertices)
|
||||
// If this assert triggers because you are drawing lots of stuff manually, A) workaround by calling BeginChild()/EndChild() to put your draw commands in multiple draw lists, B) #define ImDrawIdx to a 'unsigned int' in imconfig.h and render accordingly.
|
||||
IM_ASSERT((int)draw_list->_VtxCurrentIdx == draw_list->VtxBuffer.Size); // Sanity check. Bug or mismatch between PrimReserve() calls and incrementing _VtxCurrentIdx, _VtxWritePtr etc.
|
||||
IM_ASSERT((unsigned long long int)draw_list->_VtxCurrentIdx <= ((unsigned long long int)1L << (sizeof(ImDrawIdx)*8))); // Too many vertices in same ImDrawList. See comment above.
|
||||
|
||||
IM_ASSERT((int)draw_list->_VtxCurrentIdx == draw_list->VtxBuffer.Size); // Sanity check. Bug or mismatch between PrimReserve() calls and incrementing _VtxCurrentIdx, _VtxWritePtr etc.
|
||||
IM_ASSERT((int64_t)draw_list->_VtxCurrentIdx <= ((int64_t)1L << (sizeof(ImDrawIdx)*8))); // Too many vertices in same ImDrawList. See comment above.
|
||||
|
||||
out_render_list.push_back(draw_list);
|
||||
GImGui->IO.MetricsRenderVertices += draw_list->VtxBuffer.Size;
|
||||
GImGui->IO.MetricsRenderIndices += draw_list->IdxBuffer.Size;
|
||||
@ -3139,9 +3141,8 @@ static ImRect GetVisibleRect()
|
||||
|
||||
void ImGui::BeginTooltip()
|
||||
{
|
||||
ImGuiState& g = *GImGui;
|
||||
ImGuiWindowFlags flags = ImGuiWindowFlags_Tooltip|ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoMove|ImGuiWindowFlags_NoResize|ImGuiWindowFlags_NoSavedSettings|ImGuiWindowFlags_AlwaysAutoResize;
|
||||
ImGui::Begin("##Tooltip", NULL, ImVec2(0,0), g.Style.Colors[ImGuiCol_TooltipBg].w, flags);
|
||||
ImGui::Begin("##Tooltip", NULL, flags);
|
||||
}
|
||||
|
||||
void ImGui::EndTooltip()
|
||||
@ -3279,9 +3280,8 @@ static bool BeginPopupEx(const char* str_id, ImGuiWindowFlags extra_flags)
|
||||
ImFormatString(name, 20, "##menu_%d", g.CurrentPopupStack.Size); // Recycle windows based on depth
|
||||
else
|
||||
ImFormatString(name, 20, "##popup_%08x", id); // Not recycling, so we can close/open during the same frame
|
||||
float alpha = 1.0f;
|
||||
|
||||
bool opened = ImGui::Begin(name, NULL, ImVec2(0.0f, 0.0f), alpha, flags);
|
||||
bool opened = ImGui::Begin(name, NULL, flags);
|
||||
if (!(window->Flags & ImGuiWindowFlags_ShowBorders))
|
||||
g.CurrentWindow->Flags &= ~ImGuiWindowFlags_ShowBorders;
|
||||
if (!opened) // opened can be 'false' when the popup is completely clipped (e.g. zero size display)
|
||||
@ -3312,7 +3312,7 @@ bool ImGui::BeginPopupModal(const char* name, bool* p_opened, ImGuiWindowFlags e
|
||||
}
|
||||
|
||||
ImGuiWindowFlags flags = extra_flags|ImGuiWindowFlags_Popup|ImGuiWindowFlags_Modal|ImGuiWindowFlags_NoCollapse|ImGuiWindowFlags_NoSavedSettings;
|
||||
bool opened = ImGui::Begin(name, p_opened, ImVec2(0.0f, 0.0f), -1.0f, flags);
|
||||
bool opened = ImGui::Begin(name, p_opened, flags);
|
||||
if (!opened || (p_opened && !*p_opened)) // Opened can be 'false' when the popup is completely clipped (e.g. zero size display)
|
||||
{
|
||||
ImGui::EndPopup();
|
||||
@ -3392,8 +3392,7 @@ bool ImGui::BeginChild(const char* str_id, const ImVec2& size_arg, bool border,
|
||||
char title[256];
|
||||
ImFormatString(title, IM_ARRAYSIZE(title), "%s.%s", window->Name, str_id);
|
||||
|
||||
const float alpha = 1.0f;
|
||||
bool ret = ImGui::Begin(title, NULL, size, alpha, flags);
|
||||
bool ret = ImGui::Begin(title, NULL, size, -1.0f, flags);
|
||||
|
||||
if (!(window->Flags & ImGuiWindowFlags_ShowBorders))
|
||||
GetCurrentWindow()->Flags &= ~ImGuiWindowFlags_ShowBorders;
|
||||
@ -3443,13 +3442,14 @@ bool ImGui::BeginChildFrame(ImGuiID id, const ImVec2& size, ImGuiWindowFlags ext
|
||||
const ImGuiStyle& style = g.Style;
|
||||
ImGui::PushStyleColor(ImGuiCol_ChildWindowBg, style.Colors[ImGuiCol_FrameBg]);
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_ChildWindowRounding, style.FrameRounding);
|
||||
return ImGui::BeginChild(id, size, false, ImGuiWindowFlags_NoMove | extra_flags);
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, style.FramePadding);
|
||||
return ImGui::BeginChild(id, size, (g.CurrentWindow->Flags & ImGuiWindowFlags_ShowBorders) ? true : false, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_AlwaysUseWindowPadding | extra_flags);
|
||||
}
|
||||
|
||||
void ImGui::EndChildFrame()
|
||||
{
|
||||
ImGui::EndChild();
|
||||
ImGui::PopStyleVar();
|
||||
ImGui::PopStyleVar(2);
|
||||
ImGui::PopStyleColor();
|
||||
}
|
||||
|
||||
@ -3692,10 +3692,6 @@ bool ImGui::Begin(const char* name, bool* p_opened, const ImVec2& size_on_first_
|
||||
window->RootWindow = g.CurrentWindowStack[root_idx];
|
||||
window->RootNonPopupWindow = g.CurrentWindowStack[root_non_popup_idx]; // This is merely for displaying the TitleBgActive color.
|
||||
|
||||
// Default alpha
|
||||
if (bg_alpha < 0.0f)
|
||||
bg_alpha = style.WindowFillAlphaDefault;
|
||||
|
||||
// When reusing window again multiple times a frame, just append content (don't need to setup again)
|
||||
if (first_begin_of_the_frame)
|
||||
{
|
||||
@ -3767,7 +3763,7 @@ bool ImGui::Begin(const char* name, bool* p_opened, const ImVec2& size_on_first_
|
||||
}
|
||||
|
||||
// Lock window padding so that altering the ShowBorders flag for children doesn't have side-effects.
|
||||
window->WindowPadding = ((flags & ImGuiWindowFlags_ChildWindow) && !(flags & (ImGuiWindowFlags_ShowBorders | ImGuiWindowFlags_ComboBox | ImGuiWindowFlags_Popup))) ? ImVec2(0,0) : style.WindowPadding;
|
||||
window->WindowPadding = ((flags & ImGuiWindowFlags_ChildWindow) && !(flags & (ImGuiWindowFlags_AlwaysUseWindowPadding | ImGuiWindowFlags_ShowBorders | ImGuiWindowFlags_ComboBox | ImGuiWindowFlags_Popup))) ? ImVec2(0,0) : style.WindowPadding;
|
||||
|
||||
// Calculate auto-fit size
|
||||
ImVec2 size_auto_fit;
|
||||
@ -3981,27 +3977,26 @@ bool ImGui::Begin(const char* name, bool* p_opened, const ImVec2& size_on_first_
|
||||
}
|
||||
|
||||
// Scrollbars
|
||||
window->ScrollbarY = (flags & ImGuiWindowFlags_ForceVerticalScrollbar) || ((window->SizeContents.y > window->Size.y + style.ItemSpacing.y) && !(flags & ImGuiWindowFlags_NoScrollbar));
|
||||
window->ScrollbarX = (flags & ImGuiWindowFlags_ForceHorizontalScrollbar) || ((window->SizeContents.x > window->Size.x - (window->ScrollbarY ? style.ScrollbarSize : 0.0f) - window->WindowPadding.x) && !(flags & ImGuiWindowFlags_NoScrollbar) && (flags & ImGuiWindowFlags_HorizontalScrollbar));
|
||||
window->ScrollbarY = (flags & ImGuiWindowFlags_AlwaysVerticalScrollbar) || ((window->SizeContents.y > window->Size.y + style.ItemSpacing.y) && !(flags & ImGuiWindowFlags_NoScrollbar));
|
||||
window->ScrollbarX = (flags & ImGuiWindowFlags_AlwaysHorizontalScrollbar) || ((window->SizeContents.x > window->Size.x - (window->ScrollbarY ? style.ScrollbarSize : 0.0f) - window->WindowPadding.x) && !(flags & ImGuiWindowFlags_NoScrollbar) && (flags & ImGuiWindowFlags_HorizontalScrollbar));
|
||||
window->ScrollbarSizes = ImVec2(window->ScrollbarY ? style.ScrollbarSize : 0.0f, window->ScrollbarX ? style.ScrollbarSize : 0.0f);
|
||||
window->BorderSize = (flags & ImGuiWindowFlags_ShowBorders) ? 1.0f : 0.0f;
|
||||
|
||||
// Window background
|
||||
if (bg_alpha > 0.0f)
|
||||
{
|
||||
ImGuiCol col_idx;
|
||||
if ((flags & ImGuiWindowFlags_ComboBox) != 0)
|
||||
col_idx = ImGuiCol_ComboBg;
|
||||
else if ((flags & ImGuiWindowFlags_Tooltip) != 0)
|
||||
col_idx = ImGuiCol_TooltipBg;
|
||||
else if ((flags & ImGuiWindowFlags_Popup) != 0)
|
||||
col_idx = ImGuiCol_WindowBg;
|
||||
else if ((flags & ImGuiWindowFlags_ChildWindow) != 0)
|
||||
col_idx = ImGuiCol_ChildWindowBg;
|
||||
else
|
||||
col_idx = ImGuiCol_WindowBg;
|
||||
window->DrawList->AddRectFilled(window->Pos, window->Pos+window->Size, GetColorU32(col_idx, bg_alpha), window_rounding);
|
||||
}
|
||||
// Default alpha
|
||||
ImGuiCol bg_color_idx = ImGuiCol_WindowBg;
|
||||
if ((flags & ImGuiWindowFlags_ComboBox) != 0)
|
||||
bg_color_idx = ImGuiCol_ComboBg;
|
||||
else if ((flags & ImGuiWindowFlags_Tooltip) != 0 || (flags & ImGuiWindowFlags_Popup) != 0)
|
||||
bg_color_idx = ImGuiCol_PopupBg;
|
||||
else if ((flags & ImGuiWindowFlags_ChildWindow) != 0)
|
||||
bg_color_idx = ImGuiCol_ChildWindowBg;
|
||||
ImVec4 bg_color = style.Colors[bg_color_idx];
|
||||
if (bg_alpha >= 0.0f)
|
||||
bg_color.w = bg_alpha;
|
||||
bg_color.w *= style.Alpha;
|
||||
if (bg_color.w > 0.0f)
|
||||
window->DrawList->AddRectFilled(window->Pos, window->Pos+window->Size, ColorConvertFloat4ToU32(bg_color), window_rounding);
|
||||
|
||||
// Title bar
|
||||
if (!(flags & ImGuiWindowFlags_NoTitleBar))
|
||||
@ -4521,6 +4516,7 @@ const char* ImGui::GetStyleColName(ImGuiCol idx)
|
||||
case ImGuiCol_TextDisabled: return "TextDisabled";
|
||||
case ImGuiCol_WindowBg: return "WindowBg";
|
||||
case ImGuiCol_ChildWindowBg: return "ChildWindowBg";
|
||||
case ImGuiCol_PopupBg: return "PopupBg";
|
||||
case ImGuiCol_Border: return "Border";
|
||||
case ImGuiCol_BorderShadow: return "BorderShadow";
|
||||
case ImGuiCol_FrameBg: return "FrameBg";
|
||||
@ -4558,7 +4554,6 @@ const char* ImGui::GetStyleColName(ImGuiCol idx)
|
||||
case ImGuiCol_PlotHistogram: return "PlotHistogram";
|
||||
case ImGuiCol_PlotHistogramHovered: return "PlotHistogramHovered";
|
||||
case ImGuiCol_TextSelectedBg: return "TextSelectedBg";
|
||||
case ImGuiCol_TooltipBg: return "TooltipBg";
|
||||
case ImGuiCol_ModalWindowDarkening: return "ModalWindowDarkening";
|
||||
}
|
||||
IM_ASSERT(0);
|
||||
@ -7104,9 +7099,9 @@ static void STB_TEXTEDIT_LAYOUTROW(StbTexteditRow* r, STB_TEXTEDIT_STRING* ob
|
||||
|
||||
static bool is_separator(unsigned int c) { return ImCharIsSpace(c) || c==',' || c==';' || c=='(' || c==')' || c=='{' || c=='}' || c=='[' || c==']' || c=='|'; }
|
||||
static int is_word_boundary_from_right(STB_TEXTEDIT_STRING* obj, int idx) { return idx > 0 ? (is_separator( obj->Text[idx-1] ) && !is_separator( obj->Text[idx] ) ) : 1; }
|
||||
static int is_word_boundary_from_left(STB_TEXTEDIT_STRING* obj, int idx) { return idx > 0 ? (!is_separator( obj->Text[idx-1] ) && is_separator( obj->Text[idx] ) ) : 1; }
|
||||
static int STB_TEXTEDIT_MOVEWORDLEFT_IMPL(STB_TEXTEDIT_STRING* obj, int idx) { while (idx >= 0 && !is_word_boundary_from_right(obj, idx)) idx--; return idx < 0 ? 0 : idx; }
|
||||
#ifdef __APPLE__ // FIXME: Move setting to IO structure
|
||||
static int is_word_boundary_from_left(STB_TEXTEDIT_STRING* obj, int idx) { return idx > 0 ? (!is_separator( obj->Text[idx-1] ) && is_separator( obj->Text[idx] ) ) : 1; }
|
||||
static int STB_TEXTEDIT_MOVEWORDRIGHT_IMPL(STB_TEXTEDIT_STRING* obj, int idx) { int len = obj->CurLenW; while (idx < len && !is_word_boundary_from_left(obj, idx)) idx++; return idx > len ? len : idx; }
|
||||
#else
|
||||
static int STB_TEXTEDIT_MOVEWORDRIGHT_IMPL(STB_TEXTEDIT_STRING* obj, int idx) { int len = obj->CurLenW; while (idx < len && !is_word_boundary_from_right(obj, idx)) idx++; return idx > len ? len : idx; }
|
||||
@ -7310,7 +7305,6 @@ bool ImGui::InputTextEx(const char* label, char* buf, int buf_size, const ImVec2
|
||||
return false;
|
||||
}
|
||||
draw_window = GetCurrentWindow();
|
||||
draw_window->DC.CursorPos += style.FramePadding;
|
||||
size.x -= draw_window->ScrollbarSizes.x;
|
||||
}
|
||||
else
|
||||
@ -8501,7 +8495,7 @@ bool ImGui::BeginMenu(const char* label, bool enabled)
|
||||
bool want_open = false, want_close = false;
|
||||
if (window->Flags & (ImGuiWindowFlags_Popup|ImGuiWindowFlags_ChildMenu))
|
||||
{
|
||||
// Implement http://bjk5.com/post/44698559168/breaking-down-amazons-mega-dropdown to avoid using timers so menus feel more reactive.
|
||||
// Implement http://bjk5.com/post/44698559168/breaking-down-amazons-mega-dropdown to avoid using timers, so menus feels more reactive.
|
||||
bool moving_within_opened_triangle = false;
|
||||
if (g.HoveredWindow == window && g.OpenedPopupStack.Size > g.CurrentPopupStack.Size && g.OpenedPopupStack[g.CurrentPopupStack.Size].ParentWindow == window)
|
||||
{
|
||||
|
Reference in New Issue
Block a user