98 ImGui::SetNextWindowPos(ImVec2(100, 200), ImGuiCond_FirstUseEver);
99 ImGui::SetNextWindowSize(ImVec2(1200, 800), ImGuiCond_FirstUseEver);
102 if (ImGui::Begin(itsTitle.c_str()))
105 const float footer_height_to_reserve = ImGui::GetStyle().ItemSpacing.y + ImGui::GetFrameHeightWithSpacing() + 5;
106 ImGui::BeginChild(
"ScrollingRegion", ImVec2(0, -footer_height_to_reserve),
false,
107 ImGuiWindowFlags_HorizontalScrollbar);
108 ImGui::PushTextWrapPos(ImGui::GetWindowSize().x - ImGui::GetFontSize() * 2.0f);
111 if (ImGui::BeginPopupContextWindow())
113 if (ImGui::Selectable(
"Clear")) clear();
118 ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(4, 1));
121 for (
auto const & p : itsData)
123 ImVec4 color;
bool has_color =
false;
124 auto const & s = p.second;
127 if (p.first) { color = ImVec4(0.8f, 0.8f, 0.2f, 1.0f); has_color =
true; }
138 if (has_color) ImGui::PushStyleColor(ImGuiCol_Text, color);
139 ImGui::TextUnformatted(s.c_str());
140 if (has_color) ImGui::PopStyleColor();
144 if (itsFrozen && itsData.empty() ==
false && itsData.back().first)
146 int ndots = itsWaitState < 10 ? itsWaitState : 20 - itsWaitState;
147 std::string msg = std::string(10-ndots,
' ') + std::string(ndots,
'.') +
148 " Working " + std::string(ndots,
'.');
149 ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(1.0f, 0.3f, 0.3f, 1.0f));
150 ImGui::TextUnformatted(msg.c_str());
151 ImGui::PopStyleColor();
153 if (jevois::frameNum() % 10 == 0) { ++itsWaitState;
if (itsWaitState > 20) itsWaitState = 0; }
156 static bool autoScroll =
true;
157 static bool scrollToBottom =
true;
159 if (scrollToBottom || (autoScroll && ImGui::GetScrollY() >= ImGui::GetScrollMaxY())) ImGui::SetScrollHereY(1.0f);
160 scrollToBottom =
false;
162 ImGui::PopStyleVar();
163 ImGui::PopTextWrapPos();
168 std::string hint =
"Type queries here...";
169 int flags = ImGuiInputTextFlags_EnterReturnsTrue | ImGuiInputTextFlags_CallbackHistory;
172 ImGui::PushItemFlag(ImGuiItemFlags_Disabled,
true);
173 ImGui::PushStyleVar(ImGuiStyleVar_Alpha, ImGui::GetStyle().Alpha * 0.5f);
174 hint =
"Working... Please wait...";
175 flags |= ImGuiInputTextFlags_ReadOnly;
178 bool reclaim_focus =
false;
179 if (ImGui::InputTextWithHint(
"Input", hint.c_str(), itsInputBuf, IM_ARRAYSIZE(itsInputBuf),
180 flags, &TextEditCallbackStub,
this))
182 itsLastInput = itsInputBuf;
183 itsInputBuf[0] =
'\0';
184 reclaim_focus =
true;
188 scrollToBottom =
true;
192 if (itsHistory.empty() ==
false)
193 for (
int i =
int(itsHistory.size()) - 1; i >= 0; --i)
194 if (itsHistory[i] == itsLastInput) { itsHistory.erase(itsHistory.begin() + i);
break; }
197 itsHistory.push_back(itsLastInput);
198 while (itsHistory.size() > 100) itsHistory.erase(itsHistory.begin());
204 ImGui::PopItemFlag();
205 ImGui::PopStyleVar();
209 ImGui::SetItemDefaultFocus();
210 if (reclaim_focus) ImGui::SetKeyboardFocusHere(-1);
218 if (data->EventFlag == ImGuiInputTextFlags_CallbackHistory)
220 const int prev_history_pos = itsHistoryPos;
221 if (data->EventKey == ImGuiKey_UpArrow)
223 if (itsHistoryPos == -1) itsHistoryPos = int(itsHistory.size()) - 1;
224 else if (itsHistoryPos > 0) --itsHistoryPos;
226 else if (data->EventKey == ImGuiKey_DownArrow)
228 if (itsHistoryPos != -1 && ++itsHistoryPos >=
int(itsHistory.size())) itsHistoryPos = -1;
231 if (prev_history_pos != itsHistoryPos)
233 std::string
const & history_str = (itsHistoryPos >= 0) ? itsHistory[itsHistoryPos] :
"";
234 data->DeleteChars(0, data->BufTextLen);
235 data->InsertChars(0, history_str.c_str());