mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
[sim] GUI: Add option to show prefix in Other Devices (#3186)
Also disable rename popup for this window.
This commit is contained in:
@@ -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<glass::DeviceTreeModel*>(model)->Display(); });
|
||||
win->DisableRenamePopup();
|
||||
return glass::MakeFunctionView([=] {
|
||||
if (ImGui::BeginPopupContextItem()) {
|
||||
ImGui::Checkbox("Show prefix", &gSimDevicesShowPrefix);
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
static_cast<glass::DeviceTreeModel*>(model)->Display();
|
||||
});
|
||||
});
|
||||
HALSimGui::halProvider.ShowDefault("Other Devices");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user