From 2560146da33447f0c6e129c1bdbeda5fe10e9716 Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Sun, 21 Feb 2021 16:35:49 -0800 Subject: [PATCH] [sim] GUI: Add option to show prefix in Other Devices (#3186) Also disable rename popup for this window. --- .../src/main/native/cpp/SimDeviceGui.cpp | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/simulation/halsim_gui/src/main/native/cpp/SimDeviceGui.cpp b/simulation/halsim_gui/src/main/native/cpp/SimDeviceGui.cpp index 95a92f1e0f..4a4de4bb23 100644 --- a/simulation/halsim_gui/src/main/native/cpp/SimDeviceGui.cpp +++ b/simulation/halsim_gui/src/main/native/cpp/SimDeviceGui.cpp @@ -61,6 +61,7 @@ class SimDevicesModel : public glass::Model { } // namespace static SimDevicesModel* gSimDevicesModel; +static bool gSimDevicesShowPrefix = false; void SimDevicesModel::Update() { HALSIM_EnumerateSimDevices( @@ -136,10 +137,14 @@ static void DisplaySimValue(const char* name, void* data, static void DisplaySimDevice(const char* name, void* data, HAL_SimDeviceHandle handle) { - // only show "Foo" portion of "Accel:Foo" - auto [type, id] = wpi::StringRef{name}.split(':'); - if (id.empty()) { - id = type; + wpi::StringRef id{name}; + if (!gSimDevicesShowPrefix) { + // only show "Foo" portion of "Accel:Foo" + wpi::StringRef type; + std::tie(type, id) = id.split(':'); + if (id.empty()) { + id = type; + } } if (glass::BeginDevice(id.data())) { HALSIM_EnumerateSimValues(handle, data, DisplaySimValue); @@ -154,8 +159,14 @@ void SimDeviceGui::Initialize() { [](glass::Window* win, glass::Model* model) { win->SetDefaultPos(1025, 20); win->SetDefaultSize(250, 695); - return glass::MakeFunctionView( - [=] { static_cast(model)->Display(); }); + win->DisableRenamePopup(); + return glass::MakeFunctionView([=] { + if (ImGui::BeginPopupContextItem()) { + ImGui::Checkbox("Show prefix", &gSimDevicesShowPrefix); + ImGui::EndPopup(); + } + static_cast(model)->Display(); + }); }); HALSimGui::halProvider.ShowDefault("Other Devices");