-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
97 lines (77 loc) · 2.41 KB
/
Program.cs
File metadata and controls
97 lines (77 loc) · 2.41 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#if IS_WIN_X64 || IS_WIN_X86 || IS_WIN_ARM
#define WINDOWS
global using CrossForms.Native.Win32;
#elif IS_LINUX_X64 || IS_LINUX_ARM
#define LINUX
global using CrossForms.Native.Stub;
#elif IS_OSX_X64
#define MACOS
global using CrossForms.Native.MacOS;
using System.Runtime.InteropServices;
#else
global using CrossForms.Native.Stub;
#endif
using CrossForms;
using CrossForms.Native;
using CrossForms.Native.Common;
try {
var app = new NSApplication();
app.SetActivationPolicy(NSApplication.ActivationPolicy.Regular);
var mainWindow = new NSWindow(
new CGRect(0, 0, 400, 300),
NSWindow.StyleMask.Titled | NSWindow.StyleMask.Closable | NSWindow.StyleMask.Resizable,
2
);
mainWindow.Title = "CrossForms App";
var btn = new NSButton("Test button");
btn.OnClick(() => {
Console.WriteLine("CLICK!!!");
});
mainWindow.Append(btn);
btn.TopAnchor.ConstraintToAnchor(mainWindow.ContentView.TopAnchor, 8).Active = true;
var btn2 = new NSButton("Test button 2");
btn2.OnClick(() => {
mainWindow.Title = "CrossForms App " + DateTime.Now.Ticks;
});
// btn2.SetFrameOrigin(0, 0);
// btn2.SetFrameOrigin(0, 300 - 22 - btn2.Frame.size.height);
mainWindow.Append(btn2);
btn2.TopAnchor.ConstraintToAnchor(btn.BottomAnchor, 5).Active = true;
mainWindow.OnClose(() => {
if (!app.isRunning) return;
Console.WriteLine("main window closed");
app.Terminate();
});
app.Run();
// var NSApplication = new ObjClass();
// var result = ObjC.InitApp();
// if (result.success) Console.WriteLine($"Ok({result.value})");
// else Console.WriteLine($"Err({result.error})");
// result.Dispose();
// var NSApplication = ObjC.GetClass("NSApplication");
// Console.WriteLine(NSApplication);
// NativeApplication.Start();
// Application.mainWindow = new Form("MainWindow", "Тестовое окно");
// var testBtn1 = new Button("Hello!") {
// x = 10,
// y = 10,
// width = 200
// };
// testBtn1.OnClick += (sender, e) => {
// Console.WriteLine($"Button 1 click at ({e.x}; {e.y})");
// };
// Application.mainWindow.Append(testBtn1);
// var testBtn2 = new Button("Ещё кнопка") {
// x = 10,
// y = 35,
// width = 100
// };
// testBtn2.OnClick += (sender, e) => {
// Console.WriteLine($"Button 2 click at ({e.x}; {e.y})");
// };
// Application.mainWindow.Append(testBtn2);
// Application.mainWindow.Show();
// Application.Run();
} catch (NativeException err) {
Console.Error.WriteLine(err.ToString());
}