111 ImGui::SetNextWindowPos(ImVec2(100, 200), ImGuiCond_FirstUseEver);
112 ImGui::SetNextWindowSize(ImVec2(1200, 800), ImGuiCond_FirstUseEver);
115 if (ImGui::Begin(itsTitle.c_str()))
118 const float footer_height_to_reserve = ImGui::GetStyle().ItemSpacing.y + ImGui::GetFrameHeightWithSpacing() + 5;
119 ImGui::BeginChild(
"ScrollingRegion", ImVec2(0, -footer_height_to_reserve),
false,
120 ImGuiWindowFlags_HorizontalScrollbar);
121 ImGui::PushTextWrapPos(ImGui::GetWindowSize().x - ImGui::GetFontSize() * 2.0f);
124 if (ImGui::BeginPopupContextWindow())
126 if (ImGui::Selectable(
"Clear")) clear();
131 ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(4, 1));
134 for (
auto const & p : itsData)
136 ImVec4 color;
bool has_color =
false;
137 auto const & s = p.second;
140 if (p.first) { color = ImVec4(0.8f, 0.8f, 0.2f, 1.0f); has_color =
true; }
151 if (has_color) ImGui::PushStyleColor(ImGuiCol_Text, color);
152 ImGui::TextUnformatted(s.c_str());
153 if (has_color) ImGui::PopStyleColor();
157 if (itsFrozen && itsData.empty() ==
false && itsData.back().first)
159 int ndots = itsWaitState < 10 ? itsWaitState : 20 - itsWaitState;
160 std::string msg = std::string(10-ndots,
' ') + std::string(ndots,
'.') +
161 ' ' + itsWaitMsg +
' ' + std::string(ndots,
'.');
162 ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(1.0f, 0.3f, 0.3f, 1.0f));
163 ImGui::TextUnformatted(msg.c_str());
164 ImGui::PopStyleColor();
166 if (jevois::frameNum() % 10 == 0) { ++itsWaitState;
if (itsWaitState > 20) itsWaitState = 0; }
169 static bool autoScroll =
true;
170 static bool scrollToBottom =
true;
172 if (scrollToBottom || (autoScroll && ImGui::GetScrollY() >= ImGui::GetScrollMaxY())) ImGui::SetScrollHereY(1.0f);
173 scrollToBottom =
false;
175 ImGui::PopStyleVar();
176 ImGui::PopTextWrapPos();
181 std::string hint =
"Type queries here...";
182 int flags = ImGuiInputTextFlags_EnterReturnsTrue | ImGuiInputTextFlags_CallbackHistory;
185 ImGui::PushItemFlag(ImGuiItemFlags_Disabled,
true);
186 ImGui::PushStyleVar(ImGuiStyleVar_Alpha, ImGui::GetStyle().Alpha * 0.5f);
187 hint =
"Working... Please wait...";
188 flags |= ImGuiInputTextFlags_ReadOnly;
191 bool reclaim_focus =
false;
192 if (ImGui::InputTextWithHint(
"Input", hint.c_str(), itsInputBuf, IM_ARRAYSIZE(itsInputBuf),
193 flags, &TextEditCallbackStub,
this))
195 itsLastInput = itsInputBuf;
196 itsInputBuf[0] =
'\0';
197 reclaim_focus =
true;
201 scrollToBottom =
true;
205 if (itsHistory.empty() ==
false)
206 for (
int i =
int(itsHistory.size()) - 1; i >= 0; --i)
207 if (itsHistory[i] == itsLastInput) { itsHistory.erase(itsHistory.begin() + i);
break; }
210 itsHistory.push_back(itsLastInput);
211 while (itsHistory.size() > 100) itsHistory.erase(itsHistory.begin());
217 ImGui::PopItemFlag();
218 ImGui::PopStyleVar();
222 if (ImGui::Button(
"Clear chat")) clear();
225 ImGui::SetItemDefaultFocus();
226 if (reclaim_focus) ImGui::SetKeyboardFocusHere(-1);
234 if (data->EventFlag == ImGuiInputTextFlags_CallbackHistory)
236 const int prev_history_pos = itsHistoryPos;
237 if (data->EventKey == ImGuiKey_UpArrow)
239 if (itsHistoryPos == -1) itsHistoryPos = int(itsHistory.size()) - 1;
240 else if (itsHistoryPos > 0) --itsHistoryPos;
242 else if (data->EventKey == ImGuiKey_DownArrow)
244 if (itsHistoryPos != -1 && ++itsHistoryPos >=
int(itsHistory.size())) itsHistoryPos = -1;
247 if (prev_history_pos != itsHistoryPos)
249 std::string
const & history_str = (itsHistoryPos >= 0) ? itsHistory[itsHistoryPos] :
"";
250 data->DeleteChars(0, data->BufTextLen);
251 data->InsertChars(0, history_str.c_str());