Browse Source

Merge branch 'master' into navigation

pull/1608/head
omar 7 years ago
parent
commit
a2b2e56e8e
  1. 115
      imgui.cpp
  2. 1
      imgui.h
  3. 4
      imgui_draw.cpp
  4. 3
      imgui_internal.h

115
imgui.cpp

@ -2903,15 +2903,12 @@ void ImGui::NewFrame()
{ {
KeepAliveID(g.MovedWindowMoveId); KeepAliveID(g.MovedWindowMoveId);
IM_ASSERT(g.MovedWindow && g.MovedWindow->RootWindow); IM_ASSERT(g.MovedWindow && g.MovedWindow->RootWindow);
IM_ASSERT(g.MovedWindow->RootWindow->MoveId == g.MovedWindowMoveId); IM_ASSERT(g.MovedWindow->MoveId == g.MovedWindowMoveId);
if (g.IO.MouseDown[0]) if (g.IO.MouseDown[0])
{ {
if (!(g.MovedWindow->Flags & ImGuiWindowFlags_NoMove)) g.MovedWindow->RootWindow->PosFloat += g.IO.MouseDelta;
{ if (g.IO.MouseDelta.x != 0.0f || g.IO.MouseDelta.y != 0.0f)
g.MovedWindow->PosFloat += g.IO.MouseDelta; MarkIniSettingsDirty(g.MovedWindow->RootWindow);
if (g.IO.MouseDelta.x != 0.0f || g.IO.MouseDelta.y != 0.0f)
MarkIniSettingsDirty(g.MovedWindow);
}
FocusWindow(g.MovedWindow); FocusWindow(g.MovedWindow);
} }
else else
@ -3388,7 +3385,7 @@ void ImGui::EndFrame()
if (!(g.HoveredWindow->Flags & ImGuiWindowFlags_NoMove)) if (!(g.HoveredWindow->Flags & ImGuiWindowFlags_NoMove))
{ {
g.MovedWindow = g.HoveredWindow; g.MovedWindow = g.HoveredWindow;
g.MovedWindowMoveId = g.HoveredRootWindow->MoveId; g.MovedWindowMoveId = g.HoveredWindow->MoveId;
SetActiveIDNoNav(g.MovedWindowMoveId, g.HoveredRootWindow); SetActiveIDNoNav(g.MovedWindowMoveId, g.HoveredRootWindow);
} }
} }
@ -4359,7 +4356,7 @@ bool ImGui::BeginPopupModal(const char* name, bool* p_open, ImGuiWindowFlags ext
SetNextWindowPos(g.IO.DisplaySize * 0.5f, ImGuiCond_Appearing, ImVec2(0.5f, 0.5f)); SetNextWindowPos(g.IO.DisplaySize * 0.5f, ImGuiCond_Appearing, ImVec2(0.5f, 0.5f));
ImGuiWindowFlags flags = extra_flags|ImGuiWindowFlags_Popup|ImGuiWindowFlags_Modal|ImGuiWindowFlags_NoCollapse|ImGuiWindowFlags_NoSavedSettings; ImGuiWindowFlags flags = extra_flags|ImGuiWindowFlags_Popup|ImGuiWindowFlags_Modal|ImGuiWindowFlags_NoCollapse|ImGuiWindowFlags_NoSavedSettings;
bool is_open = ImGui::Begin(name, p_open, flags); bool is_open = Begin(name, p_open, flags);
if (!is_open || (p_open && !*p_open)) // NB: is_open can be 'false' when the popup is completely clipped (e.g. zero size display) if (!is_open || (p_open && !*p_open)) // NB: is_open can be 'false' when the popup is completely clipped (e.g. zero size display)
{ {
EndPopup(); EndPopup();
@ -4376,9 +4373,9 @@ void ImGui::EndPopup()
ImGuiWindow* window = GetCurrentWindow(); ImGuiWindow* window = GetCurrentWindow();
IM_ASSERT(window->Flags & ImGuiWindowFlags_Popup); // Mismatched BeginPopup()/EndPopup() calls IM_ASSERT(window->Flags & ImGuiWindowFlags_Popup); // Mismatched BeginPopup()/EndPopup() calls
IM_ASSERT(GImGui->CurrentPopupStack.Size > 0); IM_ASSERT(GImGui->CurrentPopupStack.Size > 0);
ImGui::End(); End();
if (!(window->Flags & ImGuiWindowFlags_Modal)) if (!(window->Flags & ImGuiWindowFlags_Modal))
ImGui::PopStyleVar(); PopStyleVar();
} }
// This is a helper to handle the most simple case of associating one named popup to one given widget. // This is a helper to handle the most simple case of associating one named popup to one given widget.
@ -4507,17 +4504,17 @@ bool ImGui::BeginChildFrame(ImGuiID id, const ImVec2& size, ImGuiWindowFlags ext
{ {
ImGuiContext& g = *GImGui; ImGuiContext& g = *GImGui;
const ImGuiStyle& style = g.Style; const ImGuiStyle& style = g.Style;
ImGui::PushStyleColor(ImGuiCol_ChildWindowBg, style.Colors[ImGuiCol_FrameBg]); PushStyleColor(ImGuiCol_ChildWindowBg, style.Colors[ImGuiCol_FrameBg]);
ImGui::PushStyleVar(ImGuiStyleVar_ChildWindowRounding, style.FrameRounding); PushStyleVar(ImGuiStyleVar_ChildWindowRounding, style.FrameRounding);
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, style.FramePadding); PushStyleVar(ImGuiStyleVar_WindowPadding, style.FramePadding);
return ImGui::BeginChild(id, size, (g.CurrentWindow->Flags & ImGuiWindowFlags_ShowBorders) ? true : false, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_AlwaysUseWindowPadding | extra_flags); return BeginChild(id, size, (g.CurrentWindow->Flags & ImGuiWindowFlags_ShowBorders) ? true : false, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_AlwaysUseWindowPadding | extra_flags);
} }
void ImGui::EndChildFrame() void ImGui::EndChildFrame()
{ {
ImGui::EndChild(); EndChild();
ImGui::PopStyleVar(2); PopStyleVar(2);
ImGui::PopStyleColor(); PopStyleColor();
} }
// Save and compare stack sizes on Begin()/End() to detect usage errors // Save and compare stack sizes on Begin()/End() to detect usage errors
@ -5995,7 +5992,7 @@ void ImGui::SetNextWindowPos(const ImVec2& pos, ImGuiCond cond, const ImVec2& pi
#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS #ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
void ImGui::SetNextWindowPosCenter(ImGuiCond cond) void ImGui::SetNextWindowPosCenter(ImGuiCond cond)
{ {
SetNextWindowPos(ImGui::GetIO().DisplaySize * 0.5f, cond, ImVec2(0.5f, 0.5f)); SetNextWindowPos(GetIO().DisplaySize * 0.5f, cond, ImVec2(0.5f, 0.5f));
} }
#endif #endif
@ -9538,8 +9535,11 @@ bool ImGui::BeginCombo(const char* label, const char* preview_value, ImVec2 popu
return false; return false;
const float arrow_size = SmallSquareSize(); const float arrow_size = SmallSquareSize();
const bool hovered = IsHovered(frame_bb, id);
bool hovered, held;
bool pressed = ButtonBehavior(frame_bb, id, &hovered, &held);
const bool navigated = g.NavId == id; const bool navigated = g.NavId == id;
bool popup_open = IsPopupOpen(id); bool popup_open = IsPopupOpen(id);
const ImRect value_bb(frame_bb.Min, frame_bb.Max - ImVec2(arrow_size, 0.0f)); const ImRect value_bb(frame_bb.Min, frame_bb.Max - ImVec2(arrow_size, 0.0f));
@ -9554,32 +9554,12 @@ bool ImGui::BeginCombo(const char* label, const char* preview_value, ImVec2 popu
if (label_size.x > 0) if (label_size.x > 0)
RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, frame_bb.Min.y + style.FramePadding.y), label); RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, frame_bb.Min.y + style.FramePadding.y), label);
bool popup_toggled = false; if ((pressed || g.NavActivateId == id) && !popup_open)
if (hovered)
{ {
SetHoveredID(id); if (window->DC.NavLayerCurrent == 0)
if (g.IO.MouseClicked[0]) window->NavLastId = id;
{ OpenPopupEx(id, false);
ClearActiveID(); popup_open = true;
popup_toggled = true;
}
}
if (g.NavActivateId == id)
popup_toggled = true;
if (popup_toggled)
{
if (popup_open)
{
ClosePopup(id);
}
else
{
if (window->DC.NavLayerCurrent == 0)
window->NavLastId = id;
FocusWindow(window);
OpenPopupEx(id, false);
}
popup_open = !popup_open;
} }
if (!popup_open) if (!popup_open)
@ -10095,7 +10075,7 @@ void ImGui::EndMenu()
} }
// Note: only access 3 floats if ImGuiColorEditFlags_NoAlpha flag is set. // Note: only access 3 floats if ImGuiColorEditFlags_NoAlpha flag is set.
void ImGui::ColorTooltip(const char* text, const float col[4], ImGuiColorEditFlags flags) void ImGui::ColorTooltip(const char* text, const float* col, ImGuiColorEditFlags flags)
{ {
ImGuiContext& g = *GImGui; ImGuiContext& g = *GImGui;
@ -10236,51 +10216,52 @@ bool ImGui::ColorEdit3(const char* label, float col[3], ImGuiColorEditFlags flag
return ColorEdit4(label, col, flags | ImGuiColorEditFlags_NoAlpha); return ColorEdit4(label, col, flags | ImGuiColorEditFlags_NoAlpha);
} }
static void ColorEditOptionsPopup(ImGuiColorEditFlags flags, float* col) void ImGui::ColorEditOptionsPopup(const float* col, ImGuiColorEditFlags flags)
{ {
bool allow_opt_inputs = !(flags & ImGuiColorEditFlags__InputsMask); bool allow_opt_inputs = !(flags & ImGuiColorEditFlags__InputsMask);
bool allow_opt_datatype = !(flags & ImGuiColorEditFlags__DataTypeMask); bool allow_opt_datatype = !(flags & ImGuiColorEditFlags__DataTypeMask);
if ((!allow_opt_inputs && !allow_opt_datatype) || !ImGui::BeginPopup("context")) if ((!allow_opt_inputs && !allow_opt_datatype) || !BeginPopup("context"))
return; return;
ImGuiContext& g = *GImGui; ImGuiContext& g = *GImGui;
ImGuiColorEditFlags opts = g.ColorEditOptions; ImGuiColorEditFlags opts = g.ColorEditOptions;
if (allow_opt_inputs) if (allow_opt_inputs)
{ {
if (ImGui::RadioButton("RGB", (opts & ImGuiColorEditFlags_RGB) ? 1 : 0)) opts = (opts & ~ImGuiColorEditFlags__InputsMask) | ImGuiColorEditFlags_RGB; if (RadioButton("RGB", (opts & ImGuiColorEditFlags_RGB) ? 1 : 0)) opts = (opts & ~ImGuiColorEditFlags__InputsMask) | ImGuiColorEditFlags_RGB;
if (ImGui::RadioButton("HSV", (opts & ImGuiColorEditFlags_HSV) ? 1 : 0)) opts = (opts & ~ImGuiColorEditFlags__InputsMask) | ImGuiColorEditFlags_HSV; if (RadioButton("HSV", (opts & ImGuiColorEditFlags_HSV) ? 1 : 0)) opts = (opts & ~ImGuiColorEditFlags__InputsMask) | ImGuiColorEditFlags_HSV;
if (ImGui::RadioButton("HEX", (opts & ImGuiColorEditFlags_HEX) ? 1 : 0)) opts = (opts & ~ImGuiColorEditFlags__InputsMask) | ImGuiColorEditFlags_HEX; if (RadioButton("HEX", (opts & ImGuiColorEditFlags_HEX) ? 1 : 0)) opts = (opts & ~ImGuiColorEditFlags__InputsMask) | ImGuiColorEditFlags_HEX;
} }
if (allow_opt_datatype) if (allow_opt_datatype)
{ {
if (allow_opt_inputs) ImGui::Separator(); if (allow_opt_inputs) Separator();
if (ImGui::RadioButton("0..255", (opts & ImGuiColorEditFlags_Uint8) ? 1 : 0)) opts = (opts & ~ImGuiColorEditFlags__DataTypeMask) | ImGuiColorEditFlags_Uint8; if (RadioButton("0..255", (opts & ImGuiColorEditFlags_Uint8) ? 1 : 0)) opts = (opts & ~ImGuiColorEditFlags__DataTypeMask) | ImGuiColorEditFlags_Uint8;
if (ImGui::RadioButton("0.00..1.00", (opts & ImGuiColorEditFlags_Float) ? 1 : 0)) opts = (opts & ~ImGuiColorEditFlags__DataTypeMask) | ImGuiColorEditFlags_Float; if (RadioButton("0.00..1.00", (opts & ImGuiColorEditFlags_Float) ? 1 : 0)) opts = (opts & ~ImGuiColorEditFlags__DataTypeMask) | ImGuiColorEditFlags_Float;
} }
if (allow_opt_inputs || allow_opt_datatype) ImGui::Separator(); if (allow_opt_inputs || allow_opt_datatype)
if (ImGui::Button("Copy as..", ImVec2(-1,0))) Separator();
ImGui::OpenPopup("Copy"); if (Button("Copy as..", ImVec2(-1,0)))
if (ImGui::BeginPopup("Copy")) OpenPopup("Copy");
if (BeginPopup("Copy"))
{ {
int cr = IM_F32_TO_INT8_SAT(col[0]), cg = IM_F32_TO_INT8_SAT(col[1]), cb = IM_F32_TO_INT8_SAT(col[2]), ca = (flags & ImGuiColorEditFlags_NoAlpha) ? 255 : IM_F32_TO_INT8_SAT(col[3]); int cr = IM_F32_TO_INT8_SAT(col[0]), cg = IM_F32_TO_INT8_SAT(col[1]), cb = IM_F32_TO_INT8_SAT(col[2]), ca = (flags & ImGuiColorEditFlags_NoAlpha) ? 255 : IM_F32_TO_INT8_SAT(col[3]);
char buf[64]; char buf[64];
sprintf(buf, "(%.3ff, %.3ff, %.3ff, %.3ff)", col[0], col[1], col[2], (flags & ImGuiColorEditFlags_NoAlpha) ? 1.0f : col[3]); sprintf(buf, "(%.3ff, %.3ff, %.3ff, %.3ff)", col[0], col[1], col[2], (flags & ImGuiColorEditFlags_NoAlpha) ? 1.0f : col[3]);
if (ImGui::Selectable(buf)) if (Selectable(buf))
ImGui::SetClipboardText(buf); SetClipboardText(buf);
sprintf(buf, "(%d,%d,%d,%d)", cr, cg, cb, ca); sprintf(buf, "(%d,%d,%d,%d)", cr, cg, cb, ca);
if (ImGui::Selectable(buf)) if (Selectable(buf))
ImGui::SetClipboardText(buf); SetClipboardText(buf);
if (flags & ImGuiColorEditFlags_NoAlpha) if (flags & ImGuiColorEditFlags_NoAlpha)
sprintf(buf, "0x%02X%02X%02X", cr, cg, cb); sprintf(buf, "0x%02X%02X%02X", cr, cg, cb);
else else
sprintf(buf, "0x%02X%02X%02X%02X", cr, cg, cb, ca); sprintf(buf, "0x%02X%02X%02X%02X", cr, cg, cb, ca);
if (ImGui::Selectable(buf)) if (Selectable(buf))
ImGui::SetClipboardText(buf); SetClipboardText(buf);
ImGui::EndPopup(); EndPopup();
} }
g.ColorEditOptions = opts; g.ColorEditOptions = opts;
ImGui::EndPopup(); EndPopup();
} }
static void ColorPickerOptionsPopup(ImGuiColorEditFlags flags, float* ref_col) static void ColorPickerOptionsPopup(ImGuiColorEditFlags flags, float* ref_col)
@ -10351,7 +10332,7 @@ bool ImGui::ColorEdit4(const char* label, float col[4], ImGuiColorEditFlags flag
// Context menu: display and modify options (before defaults are applied) // Context menu: display and modify options (before defaults are applied)
if (!(flags & ImGuiColorEditFlags_NoOptions)) if (!(flags & ImGuiColorEditFlags_NoOptions))
ColorEditOptionsPopup(flags, col); ColorEditOptionsPopup(col, flags);
// Read stored options // Read stored options
if (!(flags & ImGuiColorEditFlags__InputsMask)) if (!(flags & ImGuiColorEditFlags__InputsMask))

1
imgui.h

@ -1475,7 +1475,6 @@ struct ImFontAtlas
IMGUI_API int AddCustomRectRegular(unsigned int id, int width, int height); // Id needs to be >= 0x10000. Id >= 0x80000000 are reserved for ImGui and ImDrawList IMGUI_API int AddCustomRectRegular(unsigned int id, int width, int height); // Id needs to be >= 0x10000. Id >= 0x80000000 are reserved for ImGui and ImDrawList
IMGUI_API int AddCustomRectFontGlyph(ImFont* font, ImWchar id, int width, int height, float advance_x, const ImVec2& offset = ImVec2(0,0)); // Id needs to be < 0x10000 to register a rectangle to map into a specific font. IMGUI_API int AddCustomRectFontGlyph(ImFont* font, ImWchar id, int width, int height, float advance_x, const ImVec2& offset = ImVec2(0,0)); // Id needs to be < 0x10000 to register a rectangle to map into a specific font.
IMGUI_API void ClearCustomRects();
IMGUI_API void CalcCustomRectUV(const CustomRect* rect, ImVec2* out_uv_min, ImVec2* out_uv_max); IMGUI_API void CalcCustomRectUV(const CustomRect* rect, ImVec2* out_uv_min, ImVec2* out_uv_max);
const CustomRect* GetCustomRectByIndex(int index) const { if (index < 0) return NULL; return &CustomRects[index]; } const CustomRect* GetCustomRectByIndex(int index) const { if (index < 0) return NULL; return &CustomRects[index]; }

4
imgui_draw.cpp

@ -1134,6 +1134,8 @@ void ImFontAtlas::ClearInputData()
} }
ConfigData.clear(); ConfigData.clear();
CustomRects.clear(); CustomRects.clear();
for (int n = 0; n < IM_ARRAYSIZE(CustomRectIds); n++)
CustomRectIds[n] = -1;
} }
void ImFontAtlas::ClearTexData() void ImFontAtlas::ClearTexData()
@ -1597,6 +1599,8 @@ void ImFontAtlasBuildPackCustomRects(ImFontAtlas* atlas, void* pack_context_opaq
stbrp_context* pack_context = (stbrp_context*)pack_context_opaque; stbrp_context* pack_context = (stbrp_context*)pack_context_opaque;
ImVector<ImFontAtlas::CustomRect>& user_rects = atlas->CustomRects; ImVector<ImFontAtlas::CustomRect>& user_rects = atlas->CustomRects;
IM_ASSERT(user_rects.Size >= 1); // We expect at least the default custom rects to be registered, else something went wrong.
ImVector<stbrp_rect> pack_rects; ImVector<stbrp_rect> pack_rects;
pack_rects.resize(user_rects.Size); pack_rects.resize(user_rects.Size);
memset(pack_rects.Data, 0, sizeof(stbrp_rect) * user_rects.Size); memset(pack_rects.Data, 0, sizeof(stbrp_rect) * user_rects.Size);

3
imgui_internal.h

@ -903,7 +903,8 @@ namespace ImGui
IMGUI_API bool InputScalarEx(const char* label, ImGuiDataType data_type, void* data_ptr, void* step_ptr, void* step_fast_ptr, const char* scalar_format, ImGuiInputTextFlags extra_flags); IMGUI_API bool InputScalarEx(const char* label, ImGuiDataType data_type, void* data_ptr, void* step_ptr, void* step_fast_ptr, const char* scalar_format, ImGuiInputTextFlags extra_flags);
IMGUI_API bool InputScalarAsWidgetReplacement(const ImRect& aabb, const char* label, ImGuiDataType data_type, void* data_ptr, ImGuiID id, int decimal_precision); IMGUI_API bool InputScalarAsWidgetReplacement(const ImRect& aabb, const char* label, ImGuiDataType data_type, void* data_ptr, ImGuiID id, int decimal_precision);
IMGUI_API void ColorTooltip(const char* text, const float col[4], ImGuiColorEditFlags flags); IMGUI_API void ColorTooltip(const char* text, const float* col, ImGuiColorEditFlags flags);
IMGUI_API void ColorEditOptionsPopup(const float* col, ImGuiColorEditFlags flags);
IMGUI_API bool TreeNodeBehavior(ImGuiID id, ImGuiTreeNodeFlags flags, const char* label, const char* label_end = NULL); IMGUI_API bool TreeNodeBehavior(ImGuiID id, ImGuiTreeNodeFlags flags, const char* label, const char* label_end = NULL);
IMGUI_API bool TreeNodeBehaviorIsOpen(ImGuiID id, ImGuiTreeNodeFlags flags = 0); // Consume previous SetNextTreeNodeOpened() data, if any. May return true when logging IMGUI_API bool TreeNodeBehaviorIsOpen(ImGuiID id, ImGuiTreeNodeFlags flags = 0); // Consume previous SetNextTreeNodeOpened() data, if any. May return true when logging

Loading…
Cancel
Save