-
Notifications
You must be signed in to change notification settings - Fork 0
/
WidgetsView.j
132 lines (84 loc) · 2.95 KB
/
WidgetsView.j
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
@import <AppKit/CPCollectionView.j>
@import <AppKit/CPSearchField.j>
@import <AppKit/CPImageView.j>
@implementation WidgetItem : CPCollectionViewItem
{
CPTextField _label;
CPTextField _description;
CPImageView _image;
id _prototype;
}
-(void) setRepresentedObject:(JSObject)data
{
if (!_label)
{
[_view addCSSStyle:@"widgetItem"]
_label = [CPTextField labelWithString:@""];
[_label setFont:[CPFont boldSystemFontOfSize:13.0]];
[_view addSubview:_label];
}
if(!_description)
{
_description = [CPTextField labelWithString:@""];
[_description setFont:[CPFont fontWithName:@"Arial,sans-serif" size:12.0 italic:YES]];
[_description setTextColor:[CPColor colorWithWhite:0.46 alpha:1.0]];
[_description setLineBreakMode:CPLineBreakByWordWrapping];
[_view addSubview:_description];
}
if(!_image)
{
_image = [[CPImageView alloc] init];
[_view addSubview:_image];
}
_prototype = data["itemPrototype"];
[_image setImage:data["image"]];
[_image setFrame:data["imageFrame"]];
[_label setStringValue:data["label"]];
[_label sizeToFit];
[_label setFrameOrigin:CGPointMake(80, 8)];
[_description setStringValue:data["description"]];
[_description sizeToFitInWidth:200];
[_description setFrameOrigin:CGPointMake(80, CGRectGetMaxY(_label._frame)+3)];
}
@end
@implementation WidgetsView : CPView
{
CPCollectionView _widgetList;
CPView _searchBar;
CPSearchField _searchField;
}
-(id) initWithFrame:(CGRect)aFrame
{
self = [super initWithFrame:aFrame];
if( self )
{
_searchBar = [[CPView alloc] initWithFrame:CGRectMake(0,0, aFrame.size.width, 50)];
[_searchBar addCSSStyle:@"widgetSearchBar"];
_searchField = [[CPSearchField alloc] initWithFrame:CGRectMake(12,12, aFrame.size.width - 24, 26)];
[_searchField setPlaceholder:@"Search Components"];
[_searchField setFont:[CPFont systemFontOfSize:14.0]];
[_searchBar addSubview:_searchField];
_widgetList = [[CPCollectionView alloc] initWithFrame:CGRectMake(0, 50, aFrame.size.width, aFrame.size.height-50)];
[_widgetList setAutoresizingMask:CPViewWidthSizable|CPViewHeightSizable];
[_widgetList setMaximumNumberOfColumns:1];
[_widgetList setVerticalMargin:0];
[_widgetList setHorizontalMargin:0];
[_widgetList setMinItemSize:CGSizeMake(aFrame.size.width, 60)];
var widgetItem = [[WidgetItem alloc] init];
[widgetItem setView:[[CPView alloc] initWithFrame:CGRectMake(0,0,aFrame.size.width, 60)]];
[_widgetList setItemPrototype:widgetItem];
[_widgetList setContent:[
{
label : @"Push Button",
description : "Executes an action when clicked.",
itemPrototype : [CPButton buttonWithTitle:@"Button"],
imageFrame : CGRectMake(3,8, 70, 38),
image : [CPImage imageNamed:@"buttonWidget.png"]
}
]];
[self addSubview:_searchBar];
[self addSubview:_widgetList];
}
return self;
}
@end