[glass] LogView: Add "copy to clipboard" button (#3274)

This commit is contained in:
Starlight220
2021-04-06 23:19:49 +03:00
committed by GitHub
parent fa7240a501
commit a1c87e1e15
2 changed files with 13 additions and 2 deletions

View File

@@ -23,7 +23,7 @@ void LogData::Append(const wpi::Twine& msg) {
}
size_t oldSize = m_buf.size();
wpi::raw_vector_ostream os{m_buf};
wpi::raw_string_ostream os{m_buf};
msg.print(os);
for (size_t newSize = m_buf.size(); oldSize < newSize; ++oldSize) {
if (m_buf[oldSize] == '\n') {
@@ -32,6 +32,10 @@ void LogData::Append(const wpi::Twine& msg) {
}
}
const std::string& LogData::GetBuffer() {
return m_buf;
}
void glass::DisplayLog(LogData* data, bool autoScroll) {
if (data->m_buf.empty()) {
return;
@@ -65,6 +69,11 @@ void LogView::Display() {
if (ImGui::Selectable("Clear")) {
m_data->Clear();
}
const auto& buf = m_data->GetBuffer();
if (ImGui::Selectable("Copy to Clipboard", false,
buf.empty() ? ImGuiSelectableFlags_Disabled : 0)) {
ImGui::SetClipboardText(buf.c_str());
}
ImGui::EndPopup();
}