Skip to content

Commit 6aa8769

Browse files
committed
Add display manager and display event listeners to example
1 parent e23ab87 commit 6aa8769

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

examples/window_example/main.cpp

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,27 @@
22
#include "nativeapi.h"
33

44
using nativeapi::AppRunner;
5+
using nativeapi::Display;
6+
using nativeapi::DisplayAddedEvent;
7+
using nativeapi::DisplayManager;
8+
using nativeapi::DisplayRemovedEvent;
59
using nativeapi::Tray;
610
using nativeapi::TrayManager;
711
using nativeapi::Window;
812
using nativeapi::WindowManager;
913
using nativeapi::WindowOptions;
1014

1115
int main() {
16+
DisplayManager display_manager = DisplayManager();
1217
TrayManager tray_manager = TrayManager();
1318
WindowManager window_manager = WindowManager();
1419

1520
// Create a new window with options
16-
WindowOptions options;
17-
options.title = "My Window";
18-
options.size.width = 800;
19-
options.size.height = 600;
21+
WindowOptions options = {.title = "Window Example",
22+
.size = {800, 600},
23+
.minimum_size = {400, 300},
24+
.maximum_size = {1920, 1080},
25+
.centered = true};
2026
std::shared_ptr<Window> window_ptr = window_manager.Create(options);
2127

2228
std::shared_ptr<Tray> tray_ptr = tray_manager.Create();
@@ -29,6 +35,15 @@ int main() {
2935
std::cerr << "Failed to create tray." << std::endl;
3036
}
3137

38+
display_manager.AddListener<nativeapi::DisplayAddedEvent>(
39+
[](const nativeapi::DisplayAddedEvent& event) {
40+
std::cout << "Display added: " << event.GetDisplay().id << std::endl;
41+
});
42+
display_manager.AddListener<nativeapi::DisplayRemovedEvent>(
43+
[](const nativeapi::DisplayRemovedEvent& event) {
44+
std::cout << "Display removed: " << event.GetDisplay().id << std::endl;
45+
});
46+
3247
AppRunner runner;
3348
runner.Run(window_ptr);
3449

src/app_runner.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
11
#include "app_runner.h"
2-
#include <iostream>
32

4-
namespace nativeapi {
5-
6-
7-
} // namespace nativeapi
3+
namespace nativeapi {} // namespace nativeapi

0 commit comments

Comments
 (0)