Simulation GUI: Add support for custom names (#2292)

This allows users to right click on just about any name in the GUI (e.g. "PWM[0]") and rename it (e.g. "Left Motor [0]"). The index portion is not editable. The name is saved into imgui.ini so it's persistent.
This commit is contained in:
Peter Johnson
2020-01-20 22:47:36 -08:00
committed by GitHub
parent bb184ed481
commit 9d7b087972
11 changed files with 232 additions and 97 deletions

View File

@@ -23,6 +23,17 @@ void NameInfo::GetName(char* buf, size_t size, const char* defaultName,
}
}
void NameInfo::GetName(char* buf, size_t size, const char* defaultName,
int index, int index2) {
if (m_name[0] != '\0') {
std::snprintf(buf, size, "%s [%d,%d]###Name%d", m_name, index, index2,
index);
} else {
std::snprintf(buf, size, "%s[%d,%d]###Name%d", defaultName, index, index2,
index);
}
}
bool NameInfo::ReadIni(wpi::StringRef name, wpi::StringRef value) {
if (name != "name") return false;
size_t len = (std::min)(value.size(), sizeof(m_name) - 1);
@@ -35,6 +46,12 @@ void NameInfo::WriteIni(ImGuiTextBuffer* out) {
out->appendf("name=%s\n", m_name);
}
void NameInfo::PushEditNameId(int index) {
char id[64];
std::snprintf(id, sizeof(id), "Name%d", index);
ImGui::PushID(id);
}
void NameInfo::PopupEditName(int index) {
char id[64];
std::snprintf(id, sizeof(id), "Name%d", index);