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
|
|
|
|
|
|
|
|
#include "glass/MainMenuBar.h"
|
|
|
|
|
|
|
|
|
|
#include <cstdio>
|
|
|
|
|
|
|
|
|
|
#include <wpigui.h>
|
|
|
|
|
|
|
|
|
|
using namespace glass;
|
|
|
|
|
|
|
|
|
|
void MainMenuBar::AddMainMenu(std::function<void()> menu) {
|
2020-12-28 12:58:06 -08:00
|
|
|
if (menu) {
|
|
|
|
|
m_menus.emplace_back(std::move(menu));
|
|
|
|
|
}
|
2020-09-12 10:55:46 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainMenuBar::AddOptionMenu(std::function<void()> menu) {
|
2020-12-28 12:58:06 -08:00
|
|
|
if (menu) {
|
|
|
|
|
m_optionMenus.emplace_back(std::move(menu));
|
|
|
|
|
}
|
2020-09-12 10:55:46 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainMenuBar::Display() {
|
|
|
|
|
ImGui::BeginMainMenuBar();
|
|
|
|
|
|
|
|
|
|
if (!m_optionMenus.empty()) {
|
|
|
|
|
if (ImGui::BeginMenu("Options")) {
|
|
|
|
|
for (auto&& menu : m_optionMenus) {
|
2020-12-28 12:58:06 -08:00
|
|
|
if (menu) {
|
|
|
|
|
menu();
|
|
|
|
|
}
|
2020-09-12 10:55:46 -07:00
|
|
|
}
|
|
|
|
|
ImGui::EndMenu();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
wpi::gui::EmitViewMenu();
|
|
|
|
|
|
|
|
|
|
for (auto&& menu : m_menus) {
|
2020-12-28 12:58:06 -08:00
|
|
|
if (menu) {
|
|
|
|
|
menu();
|
|
|
|
|
}
|
2020-09-12 10:55:46 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
|
char str[64];
|
|
|
|
|
std::snprintf(str, sizeof(str), "%.3f ms/frame (%.1f FPS)",
|
|
|
|
|
1000.0f / ImGui::GetIO().Framerate,
|
|
|
|
|
ImGui::GetIO().Framerate);
|
|
|
|
|
ImGui::SameLine(ImGui::GetWindowWidth() - ImGui::CalcTextSize(str).x -
|
|
|
|
|
10);
|
|
|
|
|
ImGui::Text("%s", str);
|
|
|
|
|
#endif
|
|
|
|
|
ImGui::EndMainMenuBar();
|
|
|
|
|
}
|