Note: p_data, p_min and p_max are _pointers_ to a memory address holding the data. For a slider, they are all required. Read code of e.g. SliderFloat(), SliderInt() etc. or examples in 'Demo->Widgets->Data Types' to understand how to use this function directly.
| 2906 | // Note: p_data, p_min and p_max are _pointers_ to a memory address holding the data. For a slider, they are all required. |
| 2907 | // Read code of e.g. SliderFloat(), SliderInt() etc. or examples in 'Demo->Widgets->Data Types' to understand how to use this function directly. |
| 2908 | bool ImGui::SliderScalar(const char* label, ImGuiDataType data_type, void* p_data, const void* p_min, const void* p_max, const char* format, ImGuiSliderFlags flags) |
| 2909 | { |
| 2910 | ImGuiWindow* window = GetCurrentWindow(); |
| 2911 | if (window->SkipItems) |
| 2912 | return false; |
| 2913 | |
| 2914 | ImGuiContext& g = *GImGui; |
| 2915 | const ImGuiStyle& style = g.Style; |
| 2916 | const ImGuiID id = window->GetID(label); |
| 2917 | const float w = CalcItemWidth(); |
| 2918 | |
| 2919 | const ImVec2 label_size = CalcTextSize(label, NULL, true); |
| 2920 | const ImRect frame_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w, label_size.y + style.FramePadding.y * 2.0f)); |
| 2921 | const ImRect total_bb(frame_bb.Min, frame_bb.Max + ImVec2(label_size.x > 0.0f ? style.ItemInnerSpacing.x + label_size.x : 0.0f, 0.0f)); |
| 2922 | |
| 2923 | const bool temp_input_allowed = (flags & ImGuiSliderFlags_NoInput) == 0; |
| 2924 | ItemSize(total_bb, style.FramePadding.y); |
| 2925 | if (!ItemAdd(total_bb, id, &frame_bb, temp_input_allowed ? ImGuiItemFlags_Inputable : 0)) |
| 2926 | return false; |
| 2927 | |
| 2928 | // Default format string when passing NULL |
| 2929 | if (format == NULL) |
| 2930 | format = DataTypeGetInfo(data_type)->PrintFmt; |
| 2931 | |
| 2932 | const bool hovered = ItemHoverable(frame_bb, id); |
| 2933 | bool temp_input_is_active = temp_input_allowed && TempInputIsActive(id); |
| 2934 | if (!temp_input_is_active) |
| 2935 | { |
| 2936 | // Tabbing or CTRL-clicking on Slider turns it into an input box |
| 2937 | const bool input_requested_by_tabbing = temp_input_allowed && (g.LastItemData.StatusFlags & ImGuiItemStatusFlags_FocusedByTabbing) != 0; |
| 2938 | const bool clicked = hovered && IsMouseClicked(0, id); |
| 2939 | const bool make_active = (input_requested_by_tabbing || clicked || g.NavActivateId == id || g.NavActivateInputId == id); |
| 2940 | if (make_active && clicked) |
| 2941 | SetKeyOwner(ImGuiKey_MouseLeft, id); |
| 2942 | if (make_active && temp_input_allowed) |
| 2943 | if (input_requested_by_tabbing || (clicked && g.IO.KeyCtrl) || g.NavActivateInputId == id) |
| 2944 | temp_input_is_active = true; |
| 2945 | |
| 2946 | if (make_active && !temp_input_is_active) |
| 2947 | { |
| 2948 | SetActiveID(id, window); |
| 2949 | SetFocusID(id, window); |
| 2950 | FocusWindow(window); |
| 2951 | g.ActiveIdUsingNavDirMask |= (1 << ImGuiDir_Left) | (1 << ImGuiDir_Right); |
| 2952 | } |
| 2953 | } |
| 2954 | |
| 2955 | if (temp_input_is_active) |
| 2956 | { |
| 2957 | // Only clamp CTRL+Click input when ImGuiSliderFlags_AlwaysClamp is set |
| 2958 | const bool is_clamp_input = (flags & ImGuiSliderFlags_AlwaysClamp) != 0; |
| 2959 | return TempInputScalar(frame_bb, id, label, data_type, p_data, format, is_clamp_input ? p_min : NULL, is_clamp_input ? p_max : NULL); |
| 2960 | } |
| 2961 | |
| 2962 | // Draw frame |
| 2963 | const ImU32 frame_col = GetColorU32(g.ActiveId == id ? ImGuiCol_FrameBgActive : hovered ? ImGuiCol_FrameBgHovered : ImGuiCol_FrameBg); |
| 2964 | RenderNavHighlight(frame_bb, id); |
| 2965 | RenderFrame(frame_bb.Min, frame_bb.Max, frame_col, true, g.Style.FrameRounding); |
nothing calls this directly
no test coverage detected