Begin: WIP consistent Begin/End behavior, BeginTooltip API (one issue with BeginDragDropSource)

This commit is contained in:
ocornut 2020-10-19 17:45:34 +02:00
parent 698743c849
commit 0920ad9f04
5 changed files with 41 additions and 36 deletions

View File

@ -4153,13 +4153,15 @@ void ImGui::UpdateDebugToolItemPicker()
g.DebugItemPickerActive = false; g.DebugItemPickerActive = false;
} }
ImGui::SetNextWindowBgAlpha(0.60f); ImGui::SetNextWindowBgAlpha(0.60f);
ImGui::BeginTooltip(); if (ImGui::BeginTooltip())
{
ImGui::Text("HoveredId: 0x%08X", hovered_id); ImGui::Text("HoveredId: 0x%08X", hovered_id);
ImGui::Text("Press ESC to abort picking."); ImGui::Text("Press ESC to abort picking.");
ImGui::TextColored(GetStyleColorVec4(hovered_id ? ImGuiCol_Text : ImGuiCol_TextDisabled), "Click to break in debugger!"); ImGui::TextColored(GetStyleColorVec4(hovered_id ? ImGuiCol_Text : ImGuiCol_TextDisabled), "Click to break in debugger!");
ImGui::EndTooltip(); ImGui::EndTooltip();
} }
} }
}
void ImGui::Initialize(ImGuiContext* context) void ImGui::Initialize(ImGuiContext* context)
{ {
@ -8540,12 +8542,12 @@ void ImGui::SetScrollHereY(float center_y_ratio)
// [SECTION] TOOLTIPS // [SECTION] TOOLTIPS
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void ImGui::BeginTooltip() bool ImGui::BeginTooltip()
{ {
BeginTooltipEx(ImGuiWindowFlags_None, ImGuiTooltipFlags_None); return BeginTooltipEx(ImGuiWindowFlags_None, ImGuiTooltipFlags_None);
} }
void ImGui::BeginTooltipEx(ImGuiWindowFlags extra_flags, ImGuiTooltipFlags tooltip_flags) bool ImGui::BeginTooltipEx(ImGuiWindowFlags extra_flags, ImGuiTooltipFlags tooltip_flags)
{ {
ImGuiContext& g = *GImGui; ImGuiContext& g = *GImGui;
@ -8575,8 +8577,10 @@ void ImGui::BeginTooltipEx(ImGuiWindowFlags extra_flags, ImGuiTooltipFlags toolt
} }
ImGuiWindowFlags flags = ImGuiWindowFlags_Tooltip | ImGuiWindowFlags_NoInputs | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoDocking; ImGuiWindowFlags flags = ImGuiWindowFlags_Tooltip | ImGuiWindowFlags_NoInputs | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoDocking;
bool ret = Begin(window_name, NULL, flags | extra_flags); bool ret = Begin(window_name, NULL, flags | extra_flags);
// FIXME-NEWBEGIN // FIXME-NEWBEGIN: adding a bool to API...
IM_ASSERT(ret); //IM_UNUSED(ret);
//IM_ASSERT(ret);
return ret;
} }
void ImGui::EndTooltip() void ImGui::EndTooltip()
@ -8587,7 +8591,8 @@ void ImGui::EndTooltip()
void ImGui::SetTooltipV(const char* fmt, va_list args) void ImGui::SetTooltipV(const char* fmt, va_list args)
{ {
BeginTooltipEx(0, ImGuiTooltipFlags_OverridePreviousTooltip); if (!BeginTooltipEx(0, ImGuiTooltipFlags_OverridePreviousTooltip))
return;
TextV(fmt, args); TextV(fmt, args);
EndTooltip(); EndTooltip();
} }
@ -10381,7 +10386,9 @@ bool ImGui::BeginDragDropSource(ImGuiDragDropFlags flags)
{ {
// Target can request the Source to not display its tooltip (we use a dedicated flag to make this request explicit) // Target can request the Source to not display its tooltip (we use a dedicated flag to make this request explicit)
// We unfortunately can't just modify the source flags and skip the call to BeginTooltip, as caller may be emitting contents. // We unfortunately can't just modify the source flags and skip the call to BeginTooltip, as caller may be emitting contents.
BeginTooltip(); bool ret = BeginTooltip(); // FIXME-NEWBEGIN: problematic
IM_UNUSED(ret);
IM_ASSERT(ret);
if (g.DragDropAcceptIdPrev && (g.DragDropAcceptFlags & ImGuiDragDropFlags_AcceptNoPreviewTooltip)) if (g.DragDropAcceptIdPrev && (g.DragDropAcceptFlags & ImGuiDragDropFlags_AcceptNoPreviewTooltip))
{ {
ImGuiWindow* tooltip_window = g.CurrentWindow; ImGuiWindow* tooltip_window = g.CurrentWindow;
@ -15745,9 +15752,8 @@ static void RenderViewportsThumbnails()
static void MetricsHelpMarker(const char* desc) static void MetricsHelpMarker(const char* desc)
{ {
ImGui::TextDisabled("(?)"); ImGui::TextDisabled("(?)");
if (ImGui::IsItemHovered()) if (ImGui::IsItemHovered() && ImGui::BeginTooltip())
{ {
ImGui::BeginTooltip();
ImGui::PushTextWrapPos(ImGui::GetFontSize() * 35.0f); ImGui::PushTextWrapPos(ImGui::GetFontSize() * 35.0f);
ImGui::TextUnformatted(desc); ImGui::TextUnformatted(desc);
ImGui::PopTextWrapPos(); ImGui::PopTextWrapPos();

View File

@ -624,7 +624,7 @@ namespace ImGui
// Tooltips // Tooltips
// - Tooltip are windows following the mouse which do not take focus away. // - Tooltip are windows following the mouse which do not take focus away.
IMGUI_API void BeginTooltip(); // begin/append a tooltip window. to create full-featured tooltip (with any kind of items). IMGUI_API bool BeginTooltip(); // begin/append a tooltip window. to create full-featured tooltip (with any kind of items).
IMGUI_API void EndTooltip(); IMGUI_API void EndTooltip();
IMGUI_API void SetTooltip(const char* fmt, ...) IM_FMTARGS(1); // set a text-only tooltip, typically use with ImGui::IsItemHovered(). override any previous call to SetTooltip(). IMGUI_API void SetTooltip(const char* fmt, ...) IM_FMTARGS(1); // set a text-only tooltip, typically use with ImGui::IsItemHovered(). override any previous call to SetTooltip().
IMGUI_API void SetTooltipV(const char* fmt, va_list args) IM_FMTLIST(1); IMGUI_API void SetTooltipV(const char* fmt, va_list args) IM_FMTLIST(1);

View File

@ -179,9 +179,8 @@ static void ShowExampleMenuFile();
static void HelpMarker(const char* desc) static void HelpMarker(const char* desc)
{ {
ImGui::TextDisabled("(?)"); ImGui::TextDisabled("(?)");
if (ImGui::IsItemHovered()) if (ImGui::IsItemHovered() && ImGui::BeginTooltip())
{ {
ImGui::BeginTooltip();
ImGui::PushTextWrapPos(ImGui::GetFontSize() * 35.0f); ImGui::PushTextWrapPos(ImGui::GetFontSize() * 35.0f);
ImGui::TextUnformatted(desc); ImGui::TextUnformatted(desc);
ImGui::PopTextWrapPos(); ImGui::PopTextWrapPos();
@ -621,9 +620,8 @@ static void ShowDemoWindowWidgets()
ImGui::SameLine(); ImGui::SameLine();
ImGui::Text("- or me"); ImGui::Text("- or me");
if (ImGui::IsItemHovered()) if (ImGui::IsItemHovered() && ImGui::BeginTooltip())
{ {
ImGui::BeginTooltip();
ImGui::Text("I am a fancy tooltip"); ImGui::Text("I am a fancy tooltip");
static float arr[] = { 0.6f, 0.1f, 1.0f, 0.5f, 0.92f, 0.1f, 0.2f }; static float arr[] = { 0.6f, 0.1f, 1.0f, 0.5f, 0.92f, 0.1f, 0.2f };
ImGui::PlotLines("Curve", arr, IM_ARRAYSIZE(arr)); ImGui::PlotLines("Curve", arr, IM_ARRAYSIZE(arr));
@ -1006,9 +1004,8 @@ static void ShowDemoWindowWidgets()
ImVec4 tint_col = ImVec4(1.0f, 1.0f, 1.0f, 1.0f); // No tint ImVec4 tint_col = ImVec4(1.0f, 1.0f, 1.0f, 1.0f); // No tint
ImVec4 border_col = ImVec4(1.0f, 1.0f, 1.0f, 0.5f); // 50% opaque white ImVec4 border_col = ImVec4(1.0f, 1.0f, 1.0f, 0.5f); // 50% opaque white
ImGui::Image(my_tex_id, ImVec2(my_tex_w, my_tex_h), uv_min, uv_max, tint_col, border_col); ImGui::Image(my_tex_id, ImVec2(my_tex_w, my_tex_h), uv_min, uv_max, tint_col, border_col);
if (ImGui::IsItemHovered()) if (ImGui::IsItemHovered() && ImGui::BeginTooltip())
{ {
ImGui::BeginTooltip();
float region_sz = 32.0f; float region_sz = 32.0f;
float region_x = io.MousePos.x - pos.x - region_sz * 0.5f; float region_x = io.MousePos.x - pos.x - region_sz * 0.5f;
float region_y = io.MousePos.y - pos.y - region_sz * 0.5f; float region_y = io.MousePos.y - pos.y - region_sz * 0.5f;
@ -5682,9 +5679,8 @@ static void NodeFont(ImFont* font)
draw_list->AddRect(cell_p1, cell_p2, glyph ? IM_COL32(255, 255, 255, 100) : IM_COL32(255, 255, 255, 50)); draw_list->AddRect(cell_p1, cell_p2, glyph ? IM_COL32(255, 255, 255, 100) : IM_COL32(255, 255, 255, 50));
if (glyph) if (glyph)
font->RenderChar(draw_list, cell_size, cell_p1, glyph_col, (ImWchar)(base + n)); font->RenderChar(draw_list, cell_size, cell_p1, glyph_col, (ImWchar)(base + n));
if (glyph && ImGui::IsMouseHoveringRect(cell_p1, cell_p2)) if (glyph && ImGui::IsMouseHoveringRect(cell_p1, cell_p2) && ImGui::BeginTooltip())
{ {
ImGui::BeginTooltip();
ImGui::Text("Codepoint: U+%04X", base + n); ImGui::Text("Codepoint: U+%04X", base + n);
ImGui::Separator(); ImGui::Separator();
ImGui::Text("Visible: %d", glyph->Visible); ImGui::Text("Visible: %d", glyph->Visible);
@ -5914,7 +5910,8 @@ void ImGui::ShowStyleEditor(ImGuiStyle* ref)
if (ImGui::IsItemActive()) if (ImGui::IsItemActive())
{ {
ImGui::SetNextWindowPos(ImGui::GetCursorScreenPos()); ImGui::SetNextWindowPos(ImGui::GetCursorScreenPos());
ImGui::BeginTooltip(); if (ImGui::BeginTooltip())
{
ImVec2 p = ImGui::GetCursorScreenPos(); ImVec2 p = ImGui::GetCursorScreenPos();
ImDrawList* draw_list = ImGui::GetWindowDrawList(); ImDrawList* draw_list = ImGui::GetWindowDrawList();
float RAD_MIN = 10.0f, RAD_MAX = 80.0f; float RAD_MIN = 10.0f, RAD_MAX = 80.0f;
@ -5928,6 +5925,7 @@ void ImGui::ShowStyleEditor(ImGuiStyle* ref)
ImGui::Dummy(ImVec2(off_x, RAD_MAX * 2.0f)); ImGui::Dummy(ImVec2(off_x, RAD_MAX * 2.0f));
ImGui::EndTooltip(); ImGui::EndTooltip();
} }
}
ImGui::SameLine(); ImGui::SameLine();
HelpMarker("When drawing circle primitives with \"num_segments == 0\" tesselation will be calculated automatically."); HelpMarker("When drawing circle primitives with \"num_segments == 0\" tesselation will be calculated automatically.");

View File

@ -2449,7 +2449,7 @@ namespace ImGui
IMGUI_API void ClosePopupsOverWindow(ImGuiWindow* ref_window, bool restore_focus_to_window_under_popup); IMGUI_API void ClosePopupsOverWindow(ImGuiWindow* ref_window, bool restore_focus_to_window_under_popup);
IMGUI_API bool IsPopupOpen(ImGuiID id, ImGuiPopupFlags popup_flags); IMGUI_API bool IsPopupOpen(ImGuiID id, ImGuiPopupFlags popup_flags);
IMGUI_API bool BeginPopupEx(ImGuiID id, ImGuiWindowFlags extra_flags); IMGUI_API bool BeginPopupEx(ImGuiID id, ImGuiWindowFlags extra_flags);
IMGUI_API void BeginTooltipEx(ImGuiWindowFlags extra_flags, ImGuiTooltipFlags tooltip_flags); IMGUI_API bool BeginTooltipEx(ImGuiWindowFlags extra_flags, ImGuiTooltipFlags tooltip_flags);
IMGUI_API ImGuiWindow* GetTopMostPopupModal(); IMGUI_API ImGuiWindow* GetTopMostPopupModal();
IMGUI_API ImVec2 FindBestWindowPosForPopup(ImGuiWindow* window); IMGUI_API ImVec2 FindBestWindowPosForPopup(ImGuiWindow* window);
IMGUI_API ImVec2 FindBestWindowPosForPopupEx(const ImVec2& ref_pos, const ImVec2& size, ImGuiDir* last_dir, const ImRect& r_outer, const ImRect& r_avoid, ImGuiPopupPositionPolicy policy); IMGUI_API ImVec2 FindBestWindowPosForPopupEx(const ImVec2& ref_pos, const ImVec2& size, ImGuiDir* last_dir, const ImRect& r_outer, const ImRect& r_avoid, ImGuiPopupPositionPolicy policy);

View File

@ -5353,7 +5353,8 @@ void ImGui::ColorTooltip(const char* text, const float* col, ImGuiColorEditFlags
{ {
ImGuiContext& g = *GImGui; ImGuiContext& g = *GImGui;
BeginTooltipEx(0, ImGuiTooltipFlags_OverridePreviousTooltip); if (!BeginTooltipEx(0, ImGuiTooltipFlags_OverridePreviousTooltip))
return;
const char* text_end = text ? FindRenderedTextEnd(text, NULL) : text; const char* text_end = text ? FindRenderedTextEnd(text, NULL) : text;
if (text_end > text) if (text_end > text)
{ {