| 9261 | } |
| 9262 | |
| 9263 | bool ImGui::DragFloat(const char* label, float* v, float v_speed, float v_min, float v_max, const char* display_format, float power) |
| 9264 | { |
| 9265 | ImGuiWindow* window = GetCurrentWindow(); |
| 9266 | if (window->SkipItems) |
| 9267 | return false; |
| 9268 | |
| 9269 | ImGuiContext& g = *GImGui; |
| 9270 | const ImGuiStyle& style = g.Style; |
| 9271 | const ImGuiID id = window->GetID(label); |
| 9272 | const float w = CalcItemWidth(); |
| 9273 | |
| 9274 | const ImVec2 label_size = CalcTextSize(label, NULL, true); |
| 9275 | const ImRect frame_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w, label_size.y + style.FramePadding.y * 2.0f)); |
| 9276 | const ImRect inner_bb(frame_bb.Min + style.FramePadding, frame_bb.Max - style.FramePadding); |
| 9277 | 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)); |
| 9278 | |
| 9279 | // NB- we don't call ItemSize() yet because we may turn into a text edit box below |
| 9280 | if (!ItemAdd(total_bb, id, &frame_bb)) |
| 9281 | { |
| 9282 | ItemSize(total_bb, style.FramePadding.y); |
| 9283 | return false; |
| 9284 | } |
| 9285 | const bool hovered = ItemHoverable(frame_bb, id); |
| 9286 | |
| 9287 | if (!display_format) |
| 9288 | display_format = "%.3f"; |
| 9289 | int decimal_precision = ParseFormatPrecision(display_format, 3); |
| 9290 | |
| 9291 | // Tabbing or CTRL-clicking on Drag turns it into an input box |
| 9292 | bool start_text_input = false; |
| 9293 | const bool tab_focus_requested = FocusableItemRegister(window, id); |
| 9294 | if (tab_focus_requested || (hovered && (g.IO.MouseClicked[0] || g.IO.MouseDoubleClicked[0])) || g.NavActivateId == id || (g.NavInputId == id && g.ScalarAsInputTextId != id)) |
| 9295 | { |
| 9296 | SetActiveID(id, window); |
| 9297 | SetFocusID(id, window); |
| 9298 | FocusWindow(window); |
| 9299 | g.ActiveIdAllowNavDirFlags = (1 << ImGuiDir_Up) | (1 << ImGuiDir_Down); |
| 9300 | if (tab_focus_requested || g.IO.KeyCtrl || g.IO.MouseDoubleClicked[0] || g.NavInputId == id) |
| 9301 | { |
| 9302 | start_text_input = true; |
| 9303 | g.ScalarAsInputTextId = 0; |
| 9304 | } |
| 9305 | } |
| 9306 | if (start_text_input || (g.ActiveId == id && g.ScalarAsInputTextId == id)) |
| 9307 | return InputScalarAsWidgetReplacement(frame_bb, label, ImGuiDataType_Float, v, id, decimal_precision); |
| 9308 | |
| 9309 | // Actual drag behavior |
| 9310 | ItemSize(total_bb, style.FramePadding.y); |
| 9311 | const bool value_changed = DragBehavior(frame_bb, id, v, v_speed, v_min, v_max, decimal_precision, power); |
| 9312 | |
| 9313 | // Display value using user-provided display format so user can add prefix/suffix/decorations to the value. |
| 9314 | char value_buf[64]; |
| 9315 | const char* value_buf_end = value_buf + ImFormatString(value_buf, IM_ARRAYSIZE(value_buf), display_format, *v); |
| 9316 | RenderTextClipped(frame_bb.Min, frame_bb.Max, value_buf, value_buf_end, NULL, ImVec2(0.5f, 0.5f)); |
| 9317 | |
| 9318 | if (label_size.x > 0.0f) |
| 9319 | RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, inner_bb.Min.y), label); |
| 9320 |
nothing calls this directly
no test coverage detected