-
Notifications
You must be signed in to change notification settings - Fork 2
/
AppController.j
126 lines (96 loc) · 3.95 KB
/
AppController.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
/*
* AppController.j
* StackView
*
* Created by You on September 24, 2010.
* Copyright 2010, Your Company All rights reserved.
*/
@import <Foundation/CPObject.j>
@import <MessageBoard/MessageBoard.j>
@implementation AppController : CPObject
{
CPView _stackView;
CPArray _stackDatasource;
CPTextField _textFieldPadding;
CPTextField _textFieldWidth;
}
- (void)applicationDidFinishLaunching:(CPNotification)aNotification
{
var theWindow = [[CPWindow alloc] initWithContentRect:CGRectMakeZero() styleMask:CPBorderlessBridgeWindowMask];
var contentView = [theWindow contentView];
// stack view
_stackDatasource = [
[self generateDummyView:"toto" height:30 color:[CPColor greenColor]],
[self generateDummyView:@"titi" height:60 color:[CPColor yellowColor]],
[self generateDummyView:@"tutu" height:50 color:[CPColor redColor]]
];
_stackView = [[TNStackView alloc] initWithFrame:CGRectMake(10, 50, 300, 600)];
[_stackView setBackgroundColor:[CPColor colorWithHexString:@"c7c7c7"]];
[_stackView setDataSource:_stackDatasource];
[_stackView reload];
[contentView addSubview:_stackView];
// controls
var buttonAdd = [[CPButton alloc] initWithFrame:CGRectMake(10, 10, 100, 24)];
[buttonAdd setTitle:@"Add dummy"];
[buttonAdd setTarget:self];
[buttonAdd setAction:@selector(addDummy:)];
[contentView addSubview:buttonAdd];
var _textFieldPadding = [CPTextField textFieldWithStringValue:@"1" placeholder:@"padding" width:100];
[_textFieldPadding setFrame:CGRectMake(150, 6, 100, 30)];
[_textFieldPadding setFloatValue:[_stackView padding]];
[_textFieldPadding setTarget:self];
[_textFieldPadding setAction:@selector(setPadding:)];
[contentView addSubview:_textFieldPadding];
var buttonPadding = [[CPButton alloc] initWithFrame:CGRectMake(250, 10, 100, 24)];
[buttonPadding setTitle:@"Set padding"];
[buttonPadding setTarget:self];
[buttonPadding setAction:@selector(setPadding:)];
[contentView addSubview:buttonPadding];
var _textFieldWidth = [CPTextField textFieldWithStringValue:@"100" placeholder:@"width" width:100];
[_textFieldWidth setFrame:CGRectMake(370, 6, 100, 30)];
[_textFieldWidth setTarget:self];
[_textFieldWidth setAction:@selector(setWidth:)];
[_textFieldWidth setFloatValue:[_stackView frameSize].width];
[contentView addSubview:_textFieldWidth];
var buttonWidth = [[CPButton alloc] initWithFrame:CGRectMake(470, 10, 100, 24)];
[buttonWidth setTitle:@"Set width"];
[buttonWidth setTarget:self];
[buttonWidth setAction:@selector(setWidth:)];
[contentView addSubview:buttonWidth];
var buttonReverse = [[CPButton alloc] initWithFrame:CGRectMake(600, 10, 100, 24)];
[buttonReverse setTitle:@"Reverse"];
[buttonReverse setTarget:self];
[buttonReverse setAction:@selector(reverse:)];
[contentView addSubview:buttonReverse];
[theWindow orderFront:self];
}
- (CPView)generateDummyView:(CPString)aLabel height:(int)aHeight color:(CPColor)aColor
{
var dummy = [[CPView alloc] initWithFrame:CGRectMake(0,0,100, aHeight)];
var label = [[CPTextField alloc] initWithFrame:CGRectMake(10, 10, 100, 30)];
[dummy setBackgroundColor:aColor];
[label setStringValue:aLabel];
[dummy addSubview:label];
return dummy;
}
- (IBAction)addDummy:(id)sender
{
[_stackDatasource addObject:[self generateDummyView:@"generated!" height:30 color:[CPColor grayColor]]];
[_stackView reload];
}
- (IBAction)setPadding:(id)sender
{
[_stackView setPadding:[_textFieldPadding floatValue]];
[_stackView reload];
}
- (IBAction)setWidth:(id)sender
{
var size = [_stackView frameSize];
size.width = [_textFieldWidth floatValue];
[_stackView setFrameSize:size];
}
- (IBAction)reverse:(id)sender
{
[_stackView reverse:sender];
}
@end