21 ImGuiContext* g = ImGui::GetCurrentContext();
26 for (
const ImGuiStyleMod& mod : g->StyleVarStack) {
27 if (mod.VarIdx == idx) {
28 return ImVec2(mod.BackupFloat[0], mod.BackupFloat[1]);
31 const ImGuiStyleVarInfo* info = ImGui::GetStyleVarInfo(idx);
32 return *
static_cast<const ImVec2*
>(info->GetVarPtr(&g->Style));
83 std::string base = label;
84 static const std::string kUtf8Ellipsis =
"\xE2\x80\xA6";
85 if (base.size() >= 3 && base.compare(base.size() - 3, 3,
"...") == 0) {
86 base.resize(base.size() - 3);
87 }
else if (base.size() >= kUtf8Ellipsis.size() &&
88 base.compare(base.size() - kUtf8Ellipsis.size(),
89 kUtf8Ellipsis.size(), kUtf8Ellipsis) == 0) {
90 base.resize(base.size() - kUtf8Ellipsis.size());
92 return "Confirm " + base +
"?";
97 std::function<
void(
const std::string&, std::function<
void()>)>
98 popup_opened_callback) {
110 ImGui::BeginDisabled();
114 std::string display_label = item.
label;
115 if (!item.
icon.empty()) {
116 display_label = item.
icon +
" " + item.
label;
121 const bool has_custom_color = item.
color.x != 1.0f ||
122 item.
color.y != 1.0f ||
124 const bool push_color = item.
destructive || has_custom_color;
128 ImGuiID confirm_id = 0;
129 const int frame = ImGui::GetFrameCount();
131 confirm_id = ImGui::GetID(item.
label.c_str());
133 confirm.NoteRendered(confirm_id, frame);
134 armed = confirm.IsArmed(confirm_id, frame);
136 if (!item.
icon.empty()) {
137 text = item.
icon +
" " + text;
139 display_label = text +
"###" + item.
label;
142 const char* shortcut =
143 armed ?
"click again"
147 ImGui::PushStyleColor(ImGuiCol_Text,
152 ImGui::PushItemFlag(ImGuiItemFlags_AutoClosePopups, armed);
156 ? ImGui::MenuItem(display_label.c_str(), shortcut, checked)
157 : ImGui::MenuItem(display_label.c_str(), shortcut);
159 ImGui::PopItemFlag();
162 ImGui::PopStyleColor();
164 if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled)) {
165 if (armed && item.
tooltip.empty()) {
166 ImGui::SetTooltip(
"This cannot be undone.");
167 }
else if (!item.
tooltip.empty()) {
168 ImGui::SetTooltip(
"%s", item.
tooltip.c_str());
183 if (item.
popup.has_value() && item.
popup->auto_open_on_select &&
184 popup_opened_callback) {
185 popup_opened_callback(item.
popup->popup_id,
186 item.
popup->render_callback);
191 if (ImGui::BeginMenu(display_label.c_str())) {
192 for (
const auto& subitem : item.
subitems) {
201 ImGui::EndDisabled();
void RenderCanvasMenu(const CanvasMenuDefinition &menu, std::function< void(const std::string &, std::function< void()>)> popup_opened_callback)
Render a complete menu definition.
void RenderMenuItem(const CanvasMenuItem &item, std::function< void(const std::string &, std::function< void()>)> popup_opened_callback)
Render a single menu item.