89 const float footer_height_to_reserve = ImGui::GetStyle().ItemSpacing.y + ImGui::GetFrameHeightWithSpacing();
90 ImGui::BeginChild(
"ScrollingRegion", ImVec2(0, -footer_height_to_reserve),
false,
91 ImGuiWindowFlags_HorizontalScrollbar);
94 if (ImGui::BeginPopupContextWindow())
96 if (ImGui::Selectable(
"Clear")) clear();
101 ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(4, 1));
104 std::lock_guard<std::mutex> _(itsDataMtx);
105 for (
auto const & p : itsData)
107 ImVec4 color;
bool has_color =
false;
108 auto const & s = p.second;
111 { color = ImVec4(1.0f, 0.8f, 0.6f, 1.0f); has_color =
true; }
114 if (s ==
"OK") { color = ImVec4(0.2f, 1.0f, 0.2f, 1.0f); has_color =
true; }
120 if (has_color) ImGui::PushStyleColor(ImGuiCol_Text, color);
121 ImGui::TextUnformatted(s.c_str());
122 if (has_color) ImGui::PopStyleColor();
125 static bool autoScroll =
true;
126 static bool scrollToBottom =
true;
128 if (scrollToBottom || (autoScroll && ImGui::GetScrollY() >= ImGui::GetScrollMaxY())) ImGui::SetScrollHereY(1.0f);
129 scrollToBottom =
false;
131 ImGui::PopStyleVar();
136 bool reclaim_focus =
false;
137 ImGuiInputTextFlags input_text_flags = ImGuiInputTextFlags_EnterReturnsTrue | ImGuiInputTextFlags_CallbackHistory;
140 if (ImGui::InputTextWithHint(
"Input",
"Type JeVois commands here...",
141 itsInputBuf, IM_ARRAYSIZE(itsInputBuf), input_text_flags,
142 &TextEditCallbackStub,
this))
144 itsLastInput = itsInputBuf;
145 itsInputBuf[0] =
'\0';
146 reclaim_focus =
true;
149 scrollToBottom =
true;
153 if (itsHistory.empty() ==
false)
154 for (
int i =
int(itsHistory.size()) - 1; i >= 0; --i)
155 if (itsHistory[i] == itsLastInput) { itsHistory.erase(itsHistory.begin() + i);
break; }
158 itsHistory.push_back(itsLastInput);
159 while (itsHistory.size() > 100) itsHistory.erase(itsHistory.begin());
163 ImGui::SetItemDefaultFocus();
164 if (reclaim_focus) ImGui::SetKeyboardFocusHere(-1);
170 switch (data->EventFlag)
240 case ImGuiInputTextFlags_CallbackHistory:
243 const int prev_history_pos = itsHistoryPos;
244 if (data->EventKey == ImGuiKey_UpArrow)
246 if (itsHistoryPos == -1) itsHistoryPos = int(itsHistory.size()) - 1;
247 else if (itsHistoryPos > 0) --itsHistoryPos;
249 else if (data->EventKey == ImGuiKey_DownArrow)
251 if (itsHistoryPos != -1 && ++itsHistoryPos >=
int(itsHistory.size())) itsHistoryPos = -1;
255 if (prev_history_pos != itsHistoryPos)
257 std::string
const & history_str = (itsHistoryPos >= 0) ? itsHistory[itsHistoryPos] :
"";
258 data->DeleteChars(0, data->BufTextLen);
259 data->InsertChars(0, history_str.c_str());