diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index f5b3bdb00..540e1e581 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -95,6 +95,8 @@ Other Changes: also this type was added in 1.71 and not advertised as a public-facing feature). - Fonts: binary_to_compressed_c.cpp: Display an error message if failing to open/read the input font file. - Demo: Log, Console: Using a simpler stateless pattern for auto-scrolling. +- Demo: Widgets: Showing how to use the format parameter of Slider/Drag functions to display the name + of an enum value instead of the underlying integer value. - Backends: DX10/DX11: Backup, clear and restore Geometry Shader is any is bound when calling renderer. - Backends: DX11: Clear Hull Shader, Domain Shader, Compute Shader before rendering. Not backing/restoring them. - Backends: OSX: Disabled default native Mac clipboard copy/paste implementation in core library (added in 1.71), diff --git a/docs/TODO.txt b/docs/TODO.txt index d0f2e84e6..f289ebab7 100644 --- a/docs/TODO.txt +++ b/docs/TODO.txt @@ -89,6 +89,7 @@ It's mostly a bunch of personal notes, probably incomplete. Feel free to query i - input text: decorrelate layout from inputs - e.g. what's the easiest way to implement a nice IP/Mac address input editor? - input text: global callback system so user can plug in an expression evaluator easily. (#1691) - input text: force scroll to end or scroll to a given line/contents (so user can implement a log or a search feature) + - input text: a way to preview completion (e.g. disabled text completing from the cursor) - input text: a side bar that could e.g. preview where errors are. probably left to the user to draw but we'd need to give them the info there. - input text: a way for the user to provide syntax coloring. - input text: Shift+TAB with ImGuiInputTextFlags_AllowTabInput could eat preceding blanks, up to tab_count. @@ -122,6 +123,7 @@ It's mostly a bunch of personal notes, probably incomplete. Feel free to query i - columns: option to alternate background colors on odd/even scanlines. - columns: allow columns to recurse. - columns: allow a same columns set to be interrupted by e.g. CollapsingHeader and resume with columns in sync when moving them. + - columns: sizing is lossy when columns width is very small (default width may turn negative etc.) - columns: separator function or parameter that works within the column (currently Separator() bypass all columns) (#125) - columns: flag to add horizontal separator above/below? - columns/layout: setup minimum line height (equivalent of automatically calling AlignFirstTextHeightToWidgets) diff --git a/imgui.cpp b/imgui.cpp index 0a2a53ee0..27c90033a 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -4433,15 +4433,23 @@ bool ImGui::IsMouseDoubleClicked(int button) return g.IO.MouseDoubleClicked[button]; } +// [Internal] This doesn't test if the button is presed +bool ImGui::IsMouseDragPastThreshold(int button, float lock_threshold) +{ + ImGuiContext& g = *GImGui; + IM_ASSERT(button >= 0 && button < IM_ARRAYSIZE(g.IO.MouseDown)); + if (lock_threshold < 0.0f) + lock_threshold = g.IO.MouseDragThreshold; + return g.IO.MouseDragMaxDistanceSqr[button] >= lock_threshold * lock_threshold; +} + bool ImGui::IsMouseDragging(int button, float lock_threshold) { ImGuiContext& g = *GImGui; IM_ASSERT(button >= 0 && button < IM_ARRAYSIZE(g.IO.MouseDown)); if (!g.IO.MouseDown[button]) return false; - if (lock_threshold < 0.0f) - lock_threshold = g.IO.MouseDragThreshold; - return g.IO.MouseDragMaxDistanceSqr[button] >= lock_threshold * lock_threshold; + return IsMouseDragPastThreshold(button, lock_threshold); } ImVec2 ImGui::GetMousePos() @@ -9719,6 +9727,9 @@ void ImGui::ShowMetricsWindow(bool* p_open) if (!node_open) return; + if (window && !window->WasActive) + ImGui::Text("(Note: owning Window is inactive: DrawList is not being rendered!)"); + int elem_offset = 0; for (const ImDrawCmd* pcmd = draw_list->CmdBuffer.begin(); pcmd < draw_list->CmdBuffer.end(); elem_offset += pcmd->ElemCount, pcmd++) { diff --git a/imgui_demo.cpp b/imgui_demo.cpp index b7b48a52e..570d18dba 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -539,8 +539,19 @@ static void ShowDemoWindowWidgets() static float f1=0.123f, f2=0.0f; ImGui::SliderFloat("slider float", &f1, 0.0f, 1.0f, "ratio = %.3f"); ImGui::SliderFloat("slider float (curve)", &f2, -10.0f, 10.0f, "%.4f", 2.0f); + static float angle = 0.0f; ImGui::SliderAngle("slider angle", &angle); + + // Using the format string to display a name instead of an integer. + // Here we completely omit '%d' from the format string, so it'll only display a name. + // This technique can also be used with DragInt(). + enum Element { Element_Fire, Element_Earth, Element_Air, Element_Water, Element_COUNT }; + const char* element_names[Element_COUNT] = { "Fire", "Earth", "Air", "Water" }; + static int current_element = Element_Fire; + const char* current_element_name = (current_element >= 0 && current_element < Element_COUNT) ? element_names[current_element] : "Unknown"; + ImGui::SliderInt("slider enum", ¤t_element, 0, Element_COUNT - 1, current_element_name); + ImGui::SameLine(); HelpMarker("Using the format string parameter to display a name instead of the underlying integer."); } { @@ -1782,9 +1793,9 @@ static void ShowDemoWindowLayout() ImGui::Text("SetNextItemWidth/PushItemWidth(-1)"); ImGui::SameLine(); HelpMarker("Align to right edge"); ImGui::PushItemWidth(-1); - ImGui::DragFloat("float##5a", &f); - ImGui::DragFloat("float##5b", &f); - ImGui::DragFloat("float##5c", &f); + ImGui::DragFloat("##float5a", &f); + ImGui::DragFloat("##float5b", &f); + ImGui::DragFloat("##float5c", &f); ImGui::PopItemWidth(); ImGui::TreePop(); diff --git a/imgui_internal.h b/imgui_internal.h index dd2b8927a..522914d32 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -1556,6 +1556,7 @@ namespace ImGui IMGUI_API void SetNavIDWithRectRel(ImGuiID id, int nav_layer, const ImRect& rect_rel); // Inputs + inline bool IsMouseDragPastThreshold(int button, float lock_threshold = -1.0f); inline bool IsKeyPressedMap(ImGuiKey key, bool repeat = true) { const int key_index = GImGui->IO.KeyMap[key]; return (key_index >= 0) ? IsKeyPressed(key_index, repeat) : false; } inline bool IsNavInputDown(ImGuiNavInput n) { return GImGui->IO.NavInputs[n] > 0.0f; } inline bool IsNavInputPressed(ImGuiNavInput n, ImGuiInputReadMode mode) { return GetNavInputAmount(n, mode) > 0.0f; }