-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNSView.c3
94 lines (82 loc) · 3.03 KB
/
NSView.c3
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
// objc_Foundation
module objc_foundation @if(env::DARWIN) @link(env::DARWIN, "Cocoa.framework");
//"CoreFoundation.framework");
//, "AppKit.framework", "Cocoa.framework");
import std::io;
// Get view frame using direct struct return
fn NSRect nsView_frame(void* view) {
NSRect frame = {};
if (view == null) return frame;
// Get frame using direct selector call
void* sel = objc_foundation::sel_registerName("frame");
void* frameValue = ((CallInit0)&objc_msgSend)(view, sel);
if (frameValue != null) {
frame = *(NSRect*)frameValue;
}
return frame;
}
// Set view frame directly
fn void nsView_setFrame(void* view, NSRect frame) {
if (view == null) return;
void* sel = objc_foundation::sel_registerName("setFrame:");
((CallInit1)&objc_msgSend)(view, sel, &frame);
}
// Get view bounds
fn NSRect nsView_bounds(void* view) {
NSRect bounds = {};
if (view == null) return bounds;
void* sel = sel_registerName("bounds");
void* boundsValue = ((CallInit0)&objc_msgSend)(view, sel);
if (boundsValue != null) {
bounds = *(NSRect*)boundsValue;
}
return bounds;
}
// Check if view has subview
fn bool nsView_isDescendantOfView(void* view, void* ancestor) {
if (view == null || ancestor == null) return false;
void* sel = sel_registerName("isDescendantOfView:");
return (bool)((CallInit1)&objc_msgSend)(view, sel, ancestor);
}
// Set translatesAutoresizingMaskIntoConstraints
fn void nsView_setTranslatesAutoresizingMaskIntoConstraints(void* view, bool flag) {
if (view == null) return;
void* sel = sel_registerName("setTranslatesAutoresizingMaskIntoConstraints:");
((CallInit1)&objc_msgSend)(view, sel, (void*)(long)flag);
}
// Set frame size
fn void nsView_setFrameSize(void* view, NSSize size) {
if (view == null) return;
void* sel = sel_registerName("setFrameSize:");
((CallInit1)&objc_msgSend)(view, sel, &size);
}
// Set frame origin
fn void nsView_setFrameOrigin(void* view, NSPoint origin) {
if (view == null) return;
void* sel = sel_registerName("setFrameOrigin:");
((CallInit1)&objc_msgSend)(view, sel, &origin);
}
// Set needs display
fn void nsView_setNeedsDisplay(void* view, bool flag) {
if (view == null) return;
void* sel = sel_registerName("setNeedsDisplay:");
((CallInit1)&objc_msgSend)(view, sel, (void*)(long)flag);
}
// Set hidden
fn void nsView_setHidden(void* view, bool flag) {
if (view == null) return;
void* sel = sel_registerName("setHidden:");
((CallInit1)&objc_msgSend)(view, sel, (void*)(long)flag);
}
// Set content view's wantsLayer property
fn void nsView_setWantsLayer(void* view, bool wants) {
if (view == null) return;
void* sel = objc_foundation::sel_registerName("setWantsLayer:");
((CallInit1)&objc_msgSend)(view, sel, (void*)(long)wants);
}
// Set view's background color
fn void nsView_setBackgroundColor(void* view, void* color) {
if (view == null) return;
void* sel = objc_foundation::sel_registerName("setBackgroundColor:");
((CallInit1)&objc_msgSend)(view, sel, color);
}