Skip to content

Commit

Permalink
Playing around with layout code
Browse files Browse the repository at this point in the history
  • Loading branch information
seanhess committed Jul 1, 2011
1 parent e0454df commit 0274c08
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 26 deletions.
2 changes: 1 addition & 1 deletion Demo/HeliumDemo/ExampleViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
self.view.backgroundColor = [UIColor grayColor];
self.view.backgroundColor = [UIColor whiteColor];
self.title = @"Example";
}
return self;
Expand Down
3 changes: 2 additions & 1 deletion Demo/HeliumDemo/HeliumDemoAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#import "HEViewControllable.h"
#import "HEParser.h"
#import "HELoader.h"
#import "HEShakeWindow.h"

@implementation HeliumDemoAppDelegate

Expand All @@ -28,7 +29,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
UIViewController * viewController = page.viewController;

// Override point for customization after application launch.
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window = [[HEShakeWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[self.window addSubview:viewController.view];
self.window.rootViewController = viewController;
[self.window makeKeyAndVisible];
Expand Down
26 changes: 13 additions & 13 deletions Demo/static/scroll.hml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<Container title="Scroll">
<Scroll contentHeight="1000" background="#00FF00">
<Container background="#FF0000" width="100" height="80"/>
<Container background="#FF0000" width="100" height="80" top="100"/>
<Container background="#FF0000" width="100" height="80" top="200"/>
<Container background="#FF0000" width="100" height="80" top="300"/>
<Container background="#FF0000" width="100" height="80" top="400"/>
<Container background="#FF0000" width="100" height="80" top="500"/>
<Container background="#FF0000" width="100" height="80" top="600"/>
<Container background="#FF0000" width="100" height="80" top="700"/>
<Container background="#FF0000" width="100" height="80" top="800"/>
<Container background="#FF0000" width="100" height="80" top="900"/>
<Navigation title="Scroll">
<Scroll contentHeight="1000" background="#00FF00" title="Scroller">
<Container background="#FF0000" left="80" right="80" height="80"/>
<Container background="#FF0000" left="80" right="80" height="80" top="100"/>
<Container background="#FF0000" left="80" right="80" height="80" top="200"/>
<Container background="#FF0000" left="80" right="80" height="80" top="300"/>
<Container background="#FF0000" left="80" right="80" height="80" top="400"/>
<Container background="#FF0000" left="80" right="80" height="80" top="500"/>
<Container background="#FF0000" left="80" right="80" height="80" top="600"/>
<Container background="#FF0000" left="80" right="80" height="80" top="700"/>
<Container background="#FF0000" left="80" right="80" height="80" top="800"/>
<Container background="#FF0000" left="80" right="80" height="80" top="900"/>
</Scroll>
</Container>
</Navigation>
2 changes: 1 addition & 1 deletion Demo/static/tabs.hml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
-->


<Scroll load="bundle://scroll.hml" title="Scroll2" icon="Star-Favorites.png"/>
<Navigation load="bundle://scroll.hml" title="Scroll2" icon="Star-Favorites.png"/>

<Navigation>
<Container background="#FFFFFF" title="Nav" icon="Star-Favorites.png">
Expand Down
4 changes: 2 additions & 2 deletions Helium/HEView.m
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ - (void) didInitialize {
}

// You have to set the autoresizing mask to get the frame to fire when the superview's frame changes
self.view.autoresizingMask = UIViewAutoresizingFlexibleWidth;
self.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[self.view addObserver:self forKeyPath:@"frame" options:0 context:nil];

// Add children
Expand All @@ -102,7 +102,7 @@ - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(N
if (keyPath == @"frame") {
[self.view removeObserver:self forKeyPath:@"frame"];

if (self.view.superview)
//if (self.view.superview)
[self layout];
}
}
Expand Down
28 changes: 20 additions & 8 deletions Helium/UIView+Layout.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,16 @@ - (void) calculateLayoutWithLeft:(NSNumber *)left top:(NSNumber *)top right:(NSN

- (void)calculateLayoutWithLeft:(NSNumber*)left top:(NSNumber*)top right:(NSNumber*)right bottom:(NSNumber*)bottom width:(NSNumber*)width height:(NSNumber*)height nativeWidth:(NSNumber*)nativeWidth nativeHeight:(NSNumber*)nativeHeight {

NSAssert(self.superview, @"Missing superview when calculating size!");
//NSAssert(self.superview, @"Missing superview when calculating size!");


UIViewAutoresizing mask = UIViewAutoresizingNone;


CGFloat fullWidth = self.frame.size.width;
CGFloat fullHeight = self.frame.size.height;

CGFloat startX = self.frame.origin.x;
CGFloat startY = self.frame.origin.y;


// -width: calculate width based on left and right
Expand Down Expand Up @@ -57,7 +61,7 @@ - (void)calculateLayoutWithLeft:(NSNumber*)left top:(NSNumber*)top right:(NSNumb
w = nativeWidth.intValue;

else {
w = self.superview.bounds.size.width - left.intValue - right.intValue;
w = fullWidth - left.intValue - right.intValue;
mask = mask | UIViewAutoresizingFlexibleWidth;
}

Expand All @@ -70,17 +74,21 @@ - (void)calculateLayoutWithLeft:(NSNumber*)left top:(NSNumber*)top right:(NSNumb
h = nativeHeight.intValue;

else {
h = self.superview.bounds.size.height - top.intValue - bottom.intValue;
h = fullHeight - top.intValue - bottom.intValue;
mask = mask | UIViewAutoresizingFlexibleHeight;
}




// X

if (startX) {
x = startX;
}

if (shouldPegRight) {
x = self.superview.bounds.size.width - right.intValue - w;
else if (shouldPegRight) {
x = fullWidth - right.intValue - w;
mask = mask | UIViewAutoresizingFlexibleLeftMargin;
}

Expand All @@ -90,9 +98,13 @@ - (void)calculateLayoutWithLeft:(NSNumber*)left top:(NSNumber*)top right:(NSNumb


// Y

if (startY) {
y = startY;
}

if (shouldPegBottom) {
y = self.superview.bounds.size.height - bottom.intValue - h;
else if (shouldPegBottom) {
y = fullHeight - bottom.intValue - h;
mask = mask | UIViewAutoresizingFlexibleTopMargin;
}

Expand Down

0 comments on commit 0274c08

Please sign in to comment.