blob: 2c4d3712562c4fcc05bb19967d7d087a97f57a5c [file] [log] [blame]
Austin Schuh812d0d12021-11-04 20:16:48 -07001// Copyright (c) FIRST and other WPILib contributors.
2// Open Source Software; you can modify and/or share it under the terms of
3// the WPILib BSD license file in the root directory of this project.
4
5#include "glass/MainMenuBar.h"
6
7#include <cstdio>
8
9#include <wpigui.h>
10
11using namespace glass;
12
13void MainMenuBar::AddMainMenu(std::function<void()> menu) {
14 if (menu) {
15 m_menus.emplace_back(std::move(menu));
16 }
17}
18
19void MainMenuBar::AddOptionMenu(std::function<void()> menu) {
20 if (menu) {
21 m_optionMenus.emplace_back(std::move(menu));
22 }
23}
24
25void MainMenuBar::Display() {
26 ImGui::BeginMainMenuBar();
27
28 if (!m_optionMenus.empty()) {
29 if (ImGui::BeginMenu("Options")) {
30 for (auto&& menu : m_optionMenus) {
31 if (menu) {
32 menu();
33 }
34 }
35 ImGui::EndMenu();
36 }
37 }
38
39 wpi::gui::EmitViewMenu();
40
41 for (auto&& menu : m_menus) {
42 if (menu) {
43 menu();
44 }
45 }
46
47#if 0
48 char str[64];
49 std::snprintf(str, sizeof(str), "%.3f ms/frame (%.1f FPS)",
50 1000.0f / ImGui::GetIO().Framerate,
51 ImGui::GetIO().Framerate);
52 ImGui::SameLine(ImGui::GetWindowWidth() - ImGui::CalcTextSize(str).x -
53 10);
54 ImGui::Text("%s", str);
55#endif
56 ImGui::EndMainMenuBar();
57}