forked from Tricertops/KeepLayout
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKeepTypes.m
96 lines (64 loc) · 1.96 KB
/
KeepTypes.m
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
//
// KeepTypes.m
// Keep Layout
//
// Created by Martin Kiss on 19.6.13.
// Copyright (c) 2013 Triceratops. All rights reserved.
//
#import "KeepTypes.h"
extern NSString *KeepPriorityDescription(KeepPriority priority) {
NSString *name = @"";
if (priority >= (KeepPriorityRequired + KeepPriorityHigh) / 2) {
priority -= KeepPriorityRequired;
name = @"required";
}
else if (priority >= (KeepPriorityHigh + KeepPriorityLow) / 2) {
priority -= KeepPriorityHigh;
name = @"high";
}
else if (priority >= (KeepPriorityLow + KeepPriorityFitting) / 2) {
priority -= KeepPriorityLow;
name = @"low";
}
else {
priority -= KeepPriorityFitting;
name = @"fitting";
}
if (priority) {
name = [name stringByAppendingFormat:@"(%@%i)", (priority > 0? @"+" : @""), (uint32_t)priority];
}
return name;
}
const KeepValue KeepNone = {
.value = CGFLOAT_MIN,
.priority = 0,
};
BOOL KeepValueIsNone(KeepValue keepValue) {
return (keepValue.value == CGFLOAT_MIN || keepValue.priority <= 0);
}
KeepValue KeepValueMake(CGFloat value, KeepPriority priority) {
return (KeepValue) {
.value = value,
.priority = priority,
};
}
KeepValue KeepRequired(CGFloat value) {
return KeepValueMake(value, KeepPriorityRequired);
}
KeepValue KeepHigh(CGFloat value) {
return KeepValueMake(value, KeepPriorityHigh);
}
KeepValue KeepLow(CGFloat value) {
return KeepValueMake(value, KeepPriorityLow);
}
KeepValue KeepFitting(CGFloat value) {
return KeepValueMake(value, KeepPriorityFitting);
}
NSString *KeepValueDescription(KeepValue value) {
if (KeepValueIsNone(value)) return @"none";
NSString *description = @(value.value).stringValue;
if (value.priority != KeepPriorityRequired) {
description = [description stringByAppendingFormat:@"@%@", @(value.priority).stringValue];
}
return description;
}