5#include "imgui/imgui.h"
23 const char* direction) {
24 if (!target.has_value()) {
29 snprintf(buf,
sizeof(buf),
"%s: [%03X] %s", direction, *target,
35 const std::optional<int>& target,
36 const std::string& tooltip,
37 const std::function<
void(
int)>& on_navigate) {
38 const bool enabled = target.has_value();
40 ImGui::BeginDisabled();
42 const bool pressed = ImGui::ArrowButton(
id, dir);
46 if (enabled && ImGui::IsItemHovered() && !tooltip.empty()) {
47 ImGui::SetTooltip(
"%s", tooltip.c_str());
49 if (pressed && enabled && on_navigate) {
64 const int col = room_id % kRoomMatrixCols;
65 const int row = room_id / kRoomMatrixCols;
69 out.
west = RoomIfValid(col > 0 ? room_id - 1 : -1);
70 out.
east = RoomIfValid(col < (kRoomMatrixCols - 1) ? room_id + 1 : -1);
71 out.
north = RoomIfValid(row > 0 ? room_id - kRoomMatrixCols : -1);
73 RoomIfValid(row < (kRoomMatrixRows - 1) ? room_id + kRoomMatrixCols : -1);
78 const std::function<
void(
int)>& on_navigate) {
82 const std::string tip_w = MakeTooltip(n.
west,
"West");
83 const std::string tip_n = MakeTooltip(n.
north,
"North");
84 const std::string tip_s = MakeTooltip(n.
south,
"South");
85 const std::string tip_e = MakeTooltip(n.
east,
"East");
87 bool navigated =
false;
89 ArrowButtonWithTooltip(
"West", ImGuiDir_Left, n.
west, tip_w, on_navigate);
92 ArrowButtonWithTooltip(
"North", ImGuiDir_Up, n.
north, tip_n, on_navigate);
94 navigated |= ArrowButtonWithTooltip(
"South", ImGuiDir_Down, n.
south, tip_s,
97 navigated |= ArrowButtonWithTooltip(
"East", ImGuiDir_Right, n.
east, tip_e,
Editors are the view controllers for the application.
std::string GetRoomLabel(int id)
Convenience function to get a room label.
constexpr int kNumberOfRooms