MCPcopy Create free account
hub / github.com/KebsCS/KBotExt / SliderScalar

Method SliderScalar

KBotExt/imgui/imgui_widgets.cpp:2980–3061  ·  view source on GitHub ↗

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.

Source from the content-addressed store, hash-verified

2978// Note: p_data, p_min and p_max are _pointers_ to a memory address holding the data. For a slider, they are all required.
2979// Read code of e.g. SliderFloat(), SliderInt() etc. or examples in 'Demo->Widgets->Data Types' to understand how to use this function directly.
2980bool ImGui::SliderScalar(const char* label, ImGuiDataType data_type, void* p_data, const void* p_min, const void* p_max, const char* format, ImGuiSliderFlags flags)
2981{
2982 ImGuiWindow* window = GetCurrentWindow();
2983 if (window->SkipItems)
2984 return false;
2985
2986 ImGuiContext& g = *GImGui;
2987 const ImGuiStyle& style = g.Style;
2988 const ImGuiID id = window->GetID(label);
2989 const float w = CalcItemWidth();
2990
2991 const ImVec2 label_size = CalcTextSize(label, NULL, true);
2992 const ImRect frame_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w, label_size.y + style.FramePadding.y * 2.0f));
2993 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));
2994
2995 const bool temp_input_allowed = (flags & ImGuiSliderFlags_NoInput) == 0;
2996 ItemSize(total_bb, style.FramePadding.y);
2997 if (!ItemAdd(total_bb, id, &frame_bb, temp_input_allowed ? ImGuiItemFlags_Inputable : 0))
2998 return false;
2999
3000 // Default format string when passing NULL
3001 if (format == NULL)
3002 format = DataTypeGetInfo(data_type)->PrintFmt;
3003
3004 const bool hovered = ItemHoverable(frame_bb, id, g.LastItemData.InFlags);
3005 bool temp_input_is_active = temp_input_allowed && TempInputIsActive(id);
3006 if (!temp_input_is_active)
3007 {
3008 // Tabbing or CTRL-clicking on Slider turns it into an input box
3009 const bool input_requested_by_tabbing = temp_input_allowed && (g.LastItemData.StatusFlags & ImGuiItemStatusFlags_FocusedByTabbing) != 0;
3010 const bool clicked = hovered && IsMouseClicked(0, id);
3011 const bool make_active = (input_requested_by_tabbing || clicked || g.NavActivateId == id);
3012 if (make_active && clicked)
3013 SetKeyOwner(ImGuiKey_MouseLeft, id);
3014 if (make_active && temp_input_allowed)
3015 if (input_requested_by_tabbing || (clicked && g.IO.KeyCtrl) || (g.NavActivateId == id && (g.NavActivateFlags & ImGuiActivateFlags_PreferInput)))
3016 temp_input_is_active = true;
3017
3018 if (make_active && !temp_input_is_active)
3019 {
3020 SetActiveID(id, window);
3021 SetFocusID(id, window);
3022 FocusWindow(window);
3023 g.ActiveIdUsingNavDirMask |= (1 << ImGuiDir_Left) | (1 << ImGuiDir_Right);
3024 }
3025 }
3026
3027 if (temp_input_is_active)
3028 {
3029 // Only clamp CTRL+Click input when ImGuiSliderFlags_AlwaysClamp is set
3030 const bool is_clamp_input = (flags & ImGuiSliderFlags_AlwaysClamp) != 0;
3031 return TempInputScalar(frame_bb, id, label, data_type, p_data, format, is_clamp_input ? p_min : NULL, is_clamp_input ? p_max : NULL);
3032 }
3033
3034 // Draw frame
3035 const ImU32 frame_col = GetColorU32(g.ActiveId == id ? ImGuiCol_FrameBgActive : hovered ? ImGuiCol_FrameBgHovered : ImGuiCol_FrameBg);
3036 RenderNavHighlight(frame_bb, id);
3037 RenderFrame(frame_bb.Min, frame_bb.Max, frame_col, true, g.Style.FrameRounding);

Callers

nothing calls this directly

Calls 6

GetCurrentWindowFunction · 0.85
ImVec2Function · 0.85
ItemSizeFunction · 0.85
TempInputIsActiveFunction · 0.85
GetIDMethod · 0.80
AddRectFilledMethod · 0.80

Tested by

no test coverage detected