-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlayout_constraint.rs
More file actions
110 lines (103 loc) · 3.91 KB
/
layout_constraint.rs
File metadata and controls
110 lines (103 loc) · 3.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
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
98
99
100
101
102
103
104
105
106
107
108
109
110
use crate::try_catch::try_;
use cocoa::{
appkit::CGFloat,
base::{id, nil},
foundation::{NSString, NSUInteger},
};
use objc::{class, msg_send, sel, sel_impl};
pub trait NSLayoutConstraint: Sized {
unsafe fn constraintWithItem_attribute_relatedBy_toItem_attribute_multiplier_constant_(
_: Self,
view1: id,
attr1: NSLayoutAttribute,
relation: NSLayoutRelation,
view2: id,
attr2: NSLayoutAttribute,
multiplier: CGFloat,
c: CGFloat,
) -> id {
try_(|| {
msg_send![class!(NSLayoutConstraint), constraintWithItem:view1
attribute:attr1
relatedBy:relation
toItem:view2
attribute:attr2
multiplier:multiplier
constant:c]
})
.catch(|exception| {
println!("XXX caught exception: {:?}", exception);
let reason: id = msg_send![exception, reason];
if reason != nil {
let reason = std::ffi::CStr::from_ptr(reason.UTF8String());
let reason = reason.to_str().expect("valid UTF-8");
println!("XXX reason: {}", reason);
}
nil
})
}
unsafe fn constraintsWithVisualFormat_options_metrics_views_(
_: Self,
format: id,
opts: NSLayoutFormatOptions,
metrics: id,
views: id,
) -> id {
try_(|| {
msg_send![class!(NSLayoutConstraint), constraintsWithVisualFormat:format
options:opts
metrics:metrics
views:views]
})
.catch(|exception| {
println!("XXX caught exception: {:?}", exception);
let reason: id = msg_send![exception, reason];
if reason != nil {
let reason = std::ffi::CStr::from_ptr(reason.UTF8String());
let reason = reason.to_str().expect("valid UTF-8");
println!("XXX reason: {}", reason);
}
nil
})
}
unsafe fn activateConstraints_(_: Self, constraints: id) {
msg_send![class!(NSLayoutConstraint), activateConstraints: constraints]
}
}
impl NSLayoutConstraint for id {}
#[repr(i64)] // NSInteger
#[derive(Clone, Copy, Debug, PartialEq)]
pub enum NSLayoutAttribute {
NSLayoutAttributeLeft = 1,
NSLayoutAttributeRight,
NSLayoutAttributeTop,
NSLayoutAttributeBottom,
NSLayoutAttributeLeading,
NSLayoutAttributeTrailing,
NSLayoutAttributeWidth,
NSLayoutAttributeHeight,
NSLayoutAttributeCenterX,
NSLayoutAttributeCenterY,
// NSLayoutAttributeBaseline == NSLayoutAttributeLastBaseline,
// NSLayoutAttributeLastBaseline,
// NSLayoutAttributeFirstBaseline,
// TODO: remaining
NSLayoutAttributeNotAnAttribute = 0,
}
#[repr(i64)] // NSInteger
#[derive(Clone, Copy, Debug, PartialEq)]
pub enum NSLayoutRelation {
NSLayoutRelationLessThanOrEqual = -1,
NSLayoutRelationEqual = 0,
NSLayoutRelationGreaterThanOrEqual = 1,
}
bitflags! {
pub struct NSLayoutFormatOptions : NSUInteger {
const NSLayoutFormatAlignAllLeft = (1 << NSLayoutAttribute::NSLayoutAttributeLeft as i64);
const NSLayoutFormatAlignAllRight = (1 << NSLayoutAttribute::NSLayoutAttributeRight as i64);
const NSLayoutFormatAlignAllTop = (1 << NSLayoutAttribute::NSLayoutAttributeTop as i64);
// TODO: remaining
const NSLayoutFormatAlignAllCenterX = (1 << NSLayoutAttribute::NSLayoutAttributeCenterX as i64);
// TODO: remaining
}
}