Skip to content

Commit

Permalink
Add option to fully customize the menu
Browse files Browse the repository at this point in the history
  • Loading branch information
pthom committed Dec 14, 2023
1 parent f92384b commit b2f6546
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 8 deletions.
12 changes: 12 additions & 0 deletions src/hello_imgui/hello_imgui.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "hello_imgui/hello_imgui.h"
#include "hello_imgui/internal/backend_impls/runner_factory.h"
#include "hello_imgui/internal/menu_statusbar.h"
#include "hello_imgui/internal/docking_details.h"
#include "imgui_internal.h"
#include <deque>
#include <set>
Expand Down Expand Up @@ -162,4 +164,14 @@ std::string LoadUserPref(const std::string& userPrefName)
return gLastRunner->LoadUserPref(userPrefName);
}


void ShowViewMenu(RunnerParams & runnerParams)
{
DockingDetails::ShowViewMenu(runnerParams);
}
void ShowAppMenu(RunnerParams & runnerParams)
{
Menu_StatusBar::ShowDefaultAppMenu_Quit(runnerParams);
}

} // namespace HelloImGui
22 changes: 22 additions & 0 deletions src/hello_imgui/hello_imgui.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,26 @@ and it is not intended to store large quantities of text data. Use sparingly.
*/
void SaveUserPref(const std::string& userPrefName, const std::string& userPrefContent);
std::string LoadUserPref(const std::string& userPrefName);



/**
@@md# Menu
Hello ImGui provides a default menu and status bar, which you can customize by using the params:
`RunnerParams.imGuiWindowParams.` `showMenuBar` / `showMenu_App` / `showMenu_View`
If you want to fully customize the menu:
* set `showMenuBar` to true, then set `showMenu_App` and `showMenu_View` params to false
* implement the callback `RunnerParams.callbacks.ShowMenus`: it can optionally call `ShowViewMenu` and `ShowAppMenu` (see below).
* `ShowViewMenu(RunnerParams & runnerParams)`: shows the View menu (where you can select the layout
and docked windows visibility).
* `ShowAppMenu(RunnerParams & runnerParams)`: shows the default App menu (including the Quit item)
@@md
*/
void ShowViewMenu(RunnerParams & runnerParams);
void ShowAppMenu(RunnerParams & runnerParams);


}
6 changes: 4 additions & 2 deletions src/hello_imgui/hello_imgui_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -438,8 +438,10 @@ In order to change the application window settings, change the _AppWindowsParams
control over what is drawn behind the Gui.

* `showMenuBar`: _bool, default=false_.
Show Menu bar on top of imgui main window
You can customize the menu via `RunnerCallbacks.ShowMenus()`
Show Menu bar on top of imgui main window.
In order to fully customize the menu, set showMenuBar to true, and set showMenu_App and showMenu_View params to false.
Then, implement the callback `RunnerParams.callbacks.ShowMenus` which can optionally call `HelloImGui::ShowViewMenu`
and `HelloImGui::ShowAppMenu`.

* `showMenu_App`: _bool, default=true_.
If menu bar is shown, include or not the default app menu
Expand Down
7 changes: 5 additions & 2 deletions src/hello_imgui/imgui_window_params.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@ In order to change the application window settings, change the _AppWindowsParams
control over what is drawn behind the Gui.
* `showMenuBar`: _bool, default=false_.
Show Menu bar on top of imgui main window
You can customize the menu via `RunnerCallbacks.ShowMenus()`
Show Menu bar on top of imgui main window.
In order to fully customize the menu, set showMenuBar to true, and set showMenu_App and showMenu_View params to false.
Then, implement the callback `RunnerParams.callbacks.ShowMenus` which can optionally call `HelloImGui::ShowViewMenu`
and `HelloImGui::ShowAppMenu`.
* `showMenu_App`: _bool, default=true_.
If menu bar is shown, include or not the default app menu
Expand Down Expand Up @@ -110,4 +112,5 @@ struct ImGuiWindowParams
bool rememberTheme = true;
};


} // namespace HelloImGui
2 changes: 2 additions & 0 deletions src/hello_imgui/internal/menu_statusbar.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@ namespace Menu_StatusBar
{
void ShowMenu(RunnerParams & runnerParams);
void ShowStatusBar(RunnerParams & params);

void ShowDefaultAppMenu_Quit(RunnerParams & runnerParams);
} // namespace Menu_StatusBar
} // namespace HelloImGui
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,11 @@ void StatusBarGui(AppState& app_state)
}

// The menu gui
void ShowMenuGui()
void ShowMenuGui(HelloImGui::RunnerParams& runnerParams)
{
HelloImGui::ShowAppMenu(runnerParams);
HelloImGui::ShowViewMenu(runnerParams);

if (ImGui::BeginMenu("My Menu"))
{
bool clicked = ImGui::MenuItem("Test me", "", false);
Expand Down Expand Up @@ -512,9 +515,16 @@ int main(int, char**)
//
// Menu bar
//
runnerParams.imGuiWindowParams.showMenuBar = true; // We use the default menu of Hello ImGui
runnerParams.callbacks.ShowMenus = ShowMenuGui; // where we add items to the default menu
runnerParams.callbacks.ShowAppMenuItems = ShowAppMenuItems; // and where add items to the App menu
// Here, we fully customize the menu bar:
// by setting `showMenuBar` to true, and `showMenu_App` and `showMenu_View` to false,
// HelloImGui will display an empty menu bar, which we can fill with our own menu items via the callback `ShowMenus`
runnerParams.imGuiWindowParams.showMenuBar = true;
runnerParams.imGuiWindowParams.showMenu_App = false;
runnerParams.imGuiWindowParams.showMenu_View = false;
// Inside `ShowMenus`, we can call `HelloImGui::ShowViewMenu` and `HelloImGui::ShowAppMenu` if desired
runnerParams.callbacks.ShowMenus = [&runnerParams]() {ShowMenuGui(runnerParams);};
// Optional: add items to Hello ImGui default App menu
runnerParams.callbacks.ShowAppMenuItems = ShowAppMenuItems;

//
// Load user settings at `PostInit` and save them at `BeforeExit`
Expand Down

0 comments on commit b2f6546

Please sign in to comment.