-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathmain.cpp
More file actions
73 lines (53 loc) · 2.19 KB
/
Copy pathmain.cpp
File metadata and controls
73 lines (53 loc) · 2.19 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
64
65
66
67
68
69
70
71
72
73
#include <iostream>
#include <memory>
#include "nativeapi.h"
using namespace nativeapi;
int main() {
std::cout << "Application Example" << std::endl;
// Get the Application singleton
auto& app = Application::GetInstance();
std::cout << "Application initialized automatically" << std::endl;
std::cout << "Single instance: " << (app.IsSingleInstance() ? "Yes" : "No") << std::endl;
// Add event listeners
auto started_listener =
app.AddListener<ApplicationStartedEvent>([](const ApplicationStartedEvent& event) {
std::cout << "Application started event received" << std::endl;
});
auto quit_listener = app.AddListener<ApplicationQuitRequestedEvent>(
[](const ApplicationQuitRequestedEvent& event) {
std::cout << "Application quit requested event received" << std::endl;
});
auto activated_listener =
app.AddListener<ApplicationActivatedEvent>([](const ApplicationActivatedEvent& event) {
std::cout << "Application activated event received" << std::endl;
});
auto deactivated_listener =
app.AddListener<ApplicationDeactivatedEvent>([](const ApplicationDeactivatedEvent& event) {
std::cout << "Application deactivated event received" << std::endl;
});
// Create a simple window (automatically registered)
auto& window_manager = WindowManager::GetInstance();
auto window = std::make_shared<Window>();
window->SetTitle("Application Example Window");
if (!window) {
std::cerr << "Failed to create window" << std::endl;
return 1;
}
// Set as primary window
app.SetPrimaryWindow(window);
std::cout << "Window created successfully" << std::endl;
std::cout << "Window ID: " << window->GetId() << std::endl;
// Show the window
window->Show();
std::cout << "Starting application event loop..." << std::endl;
std::cout << "Press Ctrl+C to quit" << std::endl;
// Run the application
int exit_code = app.Run();
std::cout << "Application exited with code: " << exit_code << std::endl;
// Clean up listeners
app.RemoveListener(started_listener);
app.RemoveListener(quit_listener);
app.RemoveListener(activated_listener);
app.RemoveListener(deactivated_listener);
return exit_code;
}