MCPcopy Create free account
hub / github.com/SatDump/SatDump / AzElInput

Function AzElInput

src-core/common/widgets/azel_input.cpp:69–241  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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");

Callers 1

renderRotatorStatusMethod · 0.85

Calls 9

GetCursorPosFunction · 0.85
ImVec2Function · 0.85
to_stringFunction · 0.85
CalcTextSizeAMethod · 0.80
AddTextMethod · 0.80
c_strMethod · 0.80
digit_helperFunction · 0.70
SameLineFunction · 0.50
eraseMethod · 0.45

Tested by

no test coverage detected