ui: Make monitor text selectable

This commit is contained in:
Erik Abair 2022-06-03 23:11:12 -07:00 committed by mborgerson
parent 176b574403
commit 69dcbe9b30
2 changed files with 28 additions and 3 deletions

View File

@ -35,8 +35,8 @@
#define TYPE_CHARDEV_XEMU_MONITOR "chardev-xemu-monitor"
static Chardev *mon_chr;
static char mon_buffer[8*4096];
static const size_t mon_buffer_size = 8*4096;
static char mon_buffer[12*4096];
static const size_t mon_buffer_size = sizeof(mon_buffer);
static size_t offset;
static void char_xemu_class_init(ObjectClass *oc, void *data);

View File

@ -53,7 +53,32 @@ void MonitorWindow::Draw()
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(4,1)); // Tighten spacing
ImGui::PushFont(g_font_mgr.m_fixed_width_font);
ImGui::TextUnformatted(xemu_get_monitor_buffer());
// FIXME: Replace scroll to bottom hack when https://github.com/ocornut/imgui/issues/1972 is resolved.
// ImGui does not provide any mechanism to adjust scrolling in an InputTextMultiline and does not
// provide any other widget that allows for selectable text.
char *buffer = xemu_get_monitor_buffer();
size_t buffer_len = strlen(buffer);
// Calculating the precise size will cause an unnecessary vertical scrollbar in the InputTextMultiline.
int num_newlines = 2;
const char *start = buffer;
while (start) {
start = strchr(start, '\n');
if (start) {
++num_newlines;
++start;
}
}
float input_height = fmax(ImGui::GetWindowHeight(),
g_font_mgr.m_fixed_width_font->FontSize * num_newlines);
ImGui::PushID("#MonitorOutput");
ImGui::InputTextMultiline("",
buffer,
buffer_len,
ImVec2(-1.0f, input_height),
ImGuiInputTextFlags_ReadOnly|ImGuiInputTextFlags_NoUndoRedo);
ImGui::PopID();
ImGui::PopFont();
if (ScrollToBottom || (AutoScroll && ImGui::GetScrollY() >= ImGui::GetScrollMaxY())) {