| 67 | } |
| 68 | |
| 69 | bool AzElInput(const char *label, float *az_el_val, bool allow_edit) |
| 70 | { |
| 71 | int64_t wip_val = std::round((*az_el_val) * 1e4) / 10; |
| 72 | |
| 73 | // Set up |
| 74 | ImGuiContext &g = *GImGui; |
| 75 | ImGuiStyle style = ImGui::GetStyle(); |
| 76 | ImDrawList *draw_list = ImGui::GetWindowDrawList(); |
| 77 | ImVec2 pos = ImGui::GetCursorPos(); |
| 78 | static ImGuiID enable_temp_input_on = 0; |
| 79 | static bool first_show_temp = false; |
| 80 | ImGui::PushID(label); |
| 81 | const ImGuiID id = ImGui::GetID(label); |
| 82 | const ImVec2 label_size = ImGui::CalcTextSize(label, NULL, true); |
| 83 | const ImVec2 frame_size = ImVec2(ImGui::CalcItemWidth(), label_size.y + style.FramePadding.y * 2.0f); |
| 84 | const ImVec2 button_size = ImVec2(label_size.x > 0.0f ? style.ItemInnerSpacing.x + label_size.x : 0.0f, frame_size.y); |
| 85 | std::string display_label(label); |
| 86 | size_t tag_start = display_label.find_first_of('#'); |
| 87 | if (tag_start != std::string::npos) |
| 88 | display_label.erase(tag_start); |
| 89 | |
| 90 | if (g.NavActivateId == id && (g.NavActivateFlags & ImGuiActivateFlags_PreferInput)) |
| 91 | { |
| 92 | enable_temp_input_on = id; |
| 93 | first_show_temp = true; |
| 94 | } |
| 95 | |
| 96 | if (enable_temp_input_on != id) |
| 97 | { |
| 98 | const ImRect frame_bb(pos, ImVec2(pos.x + frame_size.x, pos.y + frame_size.y)); |
| 99 | const ImRect total_bb(frame_bb.Min, ImVec2(frame_bb.Max.x + button_size.x, frame_bb.Max.y + button_size.y)); |
| 100 | ImGui::ItemAdd(total_bb, id, &frame_bb, ImGuiItemFlags_Inputable); |
| 101 | } |
| 102 | |
| 103 | // Old-style input field |
| 104 | else if(allow_edit) |
| 105 | { |
| 106 | if (first_show_temp) |
| 107 | ImGui::SetKeyboardFocusHere(); |
| 108 | bool retval = ImGui::InputFloat("##tempinput", az_el_val); |
| 109 | if (!first_show_temp && !ImGui::IsItemActive()) |
| 110 | enable_temp_input_on = 0; |
| 111 | ImGui::SameLine(); |
| 112 | |
| 113 | first_show_temp = false; |
| 114 | ImGui::PopID(); |
| 115 | return retval; |
| 116 | } |
| 117 | |
| 118 | // Modern input |
| 119 | int64_t change_by = 0; |
| 120 | bool num_started = false; |
| 121 | std::string this_id; |
| 122 | ImVec2 screen_pos; |
| 123 | float freq_size = style::bigFont->FontSize; |
| 124 | pos.x += 1 * ui_scale; |
| 125 | ImVec2 dot_size = style::bigFont->CalcTextSizeA(freq_size, FLT_MAX, 0.0f, "."); |
| 126 | ImVec2 digit_size = style::bigFont->CalcTextSizeA(freq_size, FLT_MAX, 0.0f, "0"); |
no test coverage detected