Files
allwpilib/glass/src/lib/native/cpp/other/StringChooser.cpp

42 lines
1.1 KiB
C++
Raw Normal View History

2020-12-26 14:31:24 -08:00
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
2025-11-07 19:56:21 -05:00
#include "wpi/glass/other/StringChooser.hpp"
#include <imgui.h>
2025-11-07 20:00:05 -05:00
using namespace wpi::glass;
2025-11-07 20:00:05 -05:00
void wpi::glass::DisplayStringChooser(StringChooserModel* model) {
auto& defaultValue = model->GetDefault();
auto& selected = model->GetSelected();
auto& active = model->GetActive();
auto& options = model->GetOptions();
const char* preview =
selected.empty() ? defaultValue.c_str() : selected.c_str();
const char* label;
if (active == preview) {
label = "GOOD##select";
} else {
label = "BAD ##select";
}
if (ImGui::BeginCombo(label, preview)) {
for (auto&& option : options) {
ImGui::PushID(option.c_str());
bool isSelected = (option == selected);
if (ImGui::Selectable(option.c_str(), isSelected)) {
model->SetSelected(option);
}
if (isSelected) {
ImGui::SetItemDefaultFocus();
}
ImGui::PopID();
}
ImGui::EndCombo();
}
}