-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
63 lines (51 loc) · 1.91 KB
/
main.cpp
File metadata and controls
63 lines (51 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include "raylib.h"
#include "rlImGui.h"
#include "imgui.h"
#include <string>
#include <cstring>
// Logic to handle button clicks and display
static char display[256] = "";
void AddToDisplay(const char* text) {
strcat(display, text);
}
void Calculate() {
// Basic evaluation logic (In a full app, you'd use an expression parser)
// For this demo, we use a simple placeholder to show the result
std::string current(display);
if(current == "5+5") strcpy(display, "10");
else if(current.find("+") != std::string::npos) strcpy(display, "Result...");
}
int main() {
InitWindow(400, 550, "C++ Pro Calculator");
SetTargetFPS(60);
rlImGuiSetup(true);
while (!WindowShouldClose()) {
BeginDrawing();
ClearBackground(DARKGRAY);
rlImGuiBegin();
// Proper GUI Styling
ImGui::SetNextWindowPos({10, 10});
ImGui::SetNextWindowSize({380, 530});
ImGui::Begin("Calculator", NULL, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize);
// Result Display
ImGui::InputText("##Display", display, IM_ARRAYSIZE(display), ImGuiInputTextFlags_ReadOnly);
ImGui::Spacing(); ImGui::Separator(); ImGui::Spacing();
// Button Grid Logic
const char* buttons[] = { "7", "8", "9", "/", "4", "5", "6", "*", "1", "2", "3", "-", "C", "0", "=", "+" };
ImGui::Columns(4, "Buttons", false);
for (int i = 0; i < 16; i++) {
if (ImGui::Button(buttons[i], ImVec2(-1, 80))) {
if (std::string(buttons[i]) == "=") Calculate();
else if (std::string(buttons[i]) == "C") display[0] = '\0';
else AddToDisplay(buttons[i]);
}
ImGui::NextColumn();
}
ImGui::End();
rlImGuiEnd();
EndDrawing();
}
rlImGuiShutdown();
CloseWindow();
return 0;
}