Files
allwpilib/glass/src/lib/native/cpp/MainMenuBar.cpp
Peter Johnson 2aed432b4b Add braces to C++ single-line loops and conditionals (NFC) (#2973)
This makes code easier to read and more consistent between C++ and Java.
Also update clang-format settings to always add a line break (even if no braces are used).
2020-12-28 12:58:06 -08:00

58 lines
1.2 KiB
C++

// 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.
#include "glass/MainMenuBar.h"
#include <cstdio>
#include <wpigui.h>
using namespace glass;
void MainMenuBar::AddMainMenu(std::function<void()> menu) {
if (menu) {
m_menus.emplace_back(std::move(menu));
}
}
void MainMenuBar::AddOptionMenu(std::function<void()> menu) {
if (menu) {
m_optionMenus.emplace_back(std::move(menu));
}
}
void MainMenuBar::Display() {
ImGui::BeginMainMenuBar();
if (!m_optionMenus.empty()) {
if (ImGui::BeginMenu("Options")) {
for (auto&& menu : m_optionMenus) {
if (menu) {
menu();
}
}
ImGui::EndMenu();
}
}
wpi::gui::EmitViewMenu();
for (auto&& menu : m_menus) {
if (menu) {
menu();
}
}
#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();
}