logmeow/fragments/ok_buttons_fragment.h

33 lines
968 B
C
Raw Permalink Normal View History

2023-02-11 15:15:21 +00:00
#pragma once
#include <imgui/imgui.h>
2023-02-24 11:26:48 +00:00
namespace ImGui { bool IsKeyPressed(ImGuiKeyChord key_chord, bool repeat); }; // forward declaration from ../misc.h
2023-02-11 15:15:21 +00:00
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) {
2023-03-29 10:06:50 +00:00
bool action_done = false;
2023-02-11 15:15:21 +00:00
ImVec2 button_size(4 * ImGui::GetFontSize(), 0);
bool ctrl_s_pressed = ImGui::IsKeyPressed(ImGuiMod_Shortcut | ImGuiKey_S);
2023-03-29 10:06:50 +00:00
if (ImGui::Button("OK", button_size) && !action_done) {
2023-02-11 15:15:21 +00:00
ok();
*p_open = false;
2023-03-29 10:06:50 +00:00
action_done = true;
2023-02-11 15:15:21 +00:00
}
2023-03-29 10:06:50 +00:00
2023-02-11 15:15:21 +00:00
ImGui::SameLine();
2023-03-29 10:06:50 +00:00
if (ImGui::Button("Cancel", button_size) && !action_done) {
2023-02-11 15:15:21 +00:00
*p_open = false;
2023-03-29 10:06:50 +00:00
action_done = true;
2023-02-11 15:15:21 +00:00
}
2023-03-29 10:06:50 +00:00
2023-02-11 15:15:21 +00:00
ImGui::SameLine();
2023-03-29 10:06:50 +00:00
if ((ImGui::Button("Apply", button_size) || ctrl_s_pressed) && !action_done) {
2023-02-11 15:15:21 +00:00
apply();
2023-03-29 10:06:50 +00:00
action_done = true;
2023-02-11 15:15:21 +00:00
}
}