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.
|
2020-09-12 10:55:46 -07:00
|
|
|
|
2025-11-07 19:56:21 -05:00
|
|
|
#include "wpi/glass/other/StringChooser.hpp"
|
2020-09-12 10:55:46 -07:00
|
|
|
|
|
|
|
|
#include <imgui.h>
|
|
|
|
|
|
2025-11-07 20:00:05 -05:00
|
|
|
using namespace wpi::glass;
|
2020-09-12 10:55:46 -07:00
|
|
|
|
2025-11-07 20:00:05 -05:00
|
|
|
void wpi::glass::DisplayStringChooser(StringChooserModel* model) {
|
2020-09-12 10:55:46 -07:00
|
|
|
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);
|
|
|
|
|
}
|
2020-12-28 12:58:06 -08:00
|
|
|
if (isSelected) {
|
|
|
|
|
ImGui::SetItemDefaultFocus();
|
|
|
|
|
}
|
2020-09-12 10:55:46 -07:00
|
|
|
ImGui::PopID();
|
|
|
|
|
}
|
|
|
|
|
ImGui::EndCombo();
|
|
|
|
|
}
|
|
|
|
|
}
|