27 lines
802 B
C++
27 lines
802 B
C++
#pragma once
|
|
|
|
#include <imgui/imgui.h>
|
|
namespace ImGui { bool IsKeyPressed(ImGuiKeyChord key_chord, bool repeat); }; // forward declaration from ../misc.h
|
|
|
|
void ok_buttons_fragment(bool* p_open, auto ok, auto apply);
|
|
|
|
// function bodies must be in the header because https://stackoverflow.com/a/999383
|
|
|
|
void ok_buttons_fragment(bool* p_open, auto ok, auto apply) {
|
|
ImVec2 button_size(4 * ImGui::GetFontSize(), 0);
|
|
bool ctrl_s_pressed = ImGui::IsKeyPressed(ImGuiMod_Shortcut | ImGuiKey_S);
|
|
|
|
if (ImGui::Button("OK", button_size)) {
|
|
ok();
|
|
*p_open = false;
|
|
}
|
|
ImGui::SameLine();
|
|
if (ImGui::Button("Cancel", button_size)) {
|
|
*p_open = false;
|
|
}
|
|
ImGui::SameLine();
|
|
if (ImGui::Button("Apply", button_size) || ctrl_s_pressed) {
|
|
apply();
|
|
}
|
|
}
|