Permalink
Browse files

initial launch, pretty *darn* simple tool...

  • Loading branch information...
1 parent 8da9394 commit 5d494c8c0d49ce5220babb4e4b1fc0a5bd8b210a @colinta committed Jun 10, 2012
Showing with 162 additions and 16 deletions.
  1. +19 −2 README.md
  2. +1 −1 Rakefile
  3. +6 −0 app/app_delegate.rb
  4. +50 −0 app/first_controller.rb
  5. +48 −12 lib/boxfloat/view.rb
  6. +38 −1 spec/main_spec.rb
View
21 README.md
@@ -1,7 +1,24 @@
-BoxFloat
+Typewriter
--------
I couldn't get Three20 Launcher to work, but then I thought "really, how hard
could this be?"
-Here's the result!
+This is half of the result. The other half is [Iconid][]
+
+"Typewriter" is able to accept any view, and so is actually a generic "box
+model" library.
+
+It has one mode: as you add subviews, it will "type" them from left to right,
+dropping to a new line when the width of the next view exceeds the typewriter's
+`frame.size.width`.
+
+To use this as an app launcher, just *use* an appropriate view for the subviews!
+
+Todo
+====
+
+* Scrolling
+* Pagination
+
+[Iconid]: https://github.com/colinta/iconid
View
2 Rakefile
@@ -8,5 +8,5 @@ dirs = ['lib', 'app']
Motion::Project::App.setup do |app|
# Use `rake config' to see complete project settings.
app.files = dirs.map{|d| Dir.glob(File.join(app.project_dir, "#{d}/**/*.rb")) }.flatten
- app.name = 'BoxFloat'
+ app.name = 'Typewriter'
end
View
6 app/app_delegate.rb
@@ -1,5 +1,11 @@
class AppDelegate
def application(application, didFinishLaunchingWithOptions:launchOptions)
+ application.setStatusBarStyle(UIStatusBarStyleBlackTranslucent)
+
+ @window = UIWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds)
+ @window.rootViewController = FirstController.new
+ @window.makeKeyAndVisible
+
true
end
end
View
50 app/first_controller.rb
@@ -0,0 +1,50 @@
+
+class FirstController < UIViewController
+
+ def viewDidLoad
+ @typewriter = TypewriterView.alloc.initWithFrame([[0, 0], [320, 400]])
+ self.view.addSubview(@typewriter)
+
+ blue_view = UIView.alloc.initWithFrame([[0, 0], [ 80, 80]])
+ blue_view.backgroundColor = UIColor.blueColor
+ red_view = UIView.alloc.initWithFrame([[0, 0], [120, 120]])
+ red_view.backgroundColor = UIColor.redColor
+
+ green_view = UIView.alloc.initWithFrame([[0, 0], [120, 40]])
+ green_view.backgroundColor = UIColor.greenColor
+ cyan_view = UIView.alloc.initWithFrame([[0, 0], [120, 40]])
+ cyan_view.backgroundColor = UIColor.cyanColor
+
+ green_cyan_combo = TypewriterView.alloc.initWithFrame([[0, 0], [120, 120]])
+ green_cyan_combo.addSubview(green_view)
+ green_cyan_combo.addSubview(cyan_view)
+
+ gray_view = UIView.alloc.initWithFrame([[0, 0], [80, 240]])
+ gray_view.backgroundColor = UIColor.grayColor
+
+ white_view = UIView.alloc.initWithFrame([[0, 0], [80, 120]])
+ white_view.backgroundColor = UIColor.whiteColor
+
+ black_view = UIView.alloc.initWithFrame([[0, 0], [80, 180]])
+ black_view.backgroundColor = UIColor.blackColor
+
+ bw_view = TypewriterView.alloc.initWithFrame([[]])
+
+ [blue_view, red_view, green_cyan_combo, gray_view].each { |view|
+ @typewriter.addSubview(view)
+ }
+ end
+
+ def shouldAutorotateToInterfaceOrientation(orientation)
+ true
+ end
+
+ def willAnimateRotationToInterfaceOrientation(orientation, duration:duration)
+ bframe = @typewriter.frame
+ w, h = bframe.size.width, bframe.size.height
+ bframe.size = h, w
+ @typewriter.frame = bframe
+ @typewriter.setNeedsLayout
+ end
+
+end
View
60 lib/boxfloat/view.rb
@@ -1,24 +1,60 @@
-class BoxFloatView < UIView
+class TypewriterView < UIView
- def apps
- @apps ||= []
+ def initWithFrame(frame)
+ super
+ frame = self.frame # frame could be [[], []] or a CGRect; normalize it.
+
+ layoutSubviews
+
+ self
end
- ##|
- ##| STYLES
- ##| easily stylable using teacup
- ##| * backgroundColor is already supported by UIView
- ##|
+ def frame=(new_frame)
+ super
+ layoutSubviews
+ end
+
+ def clear
+ @x = 0
+ @y = @max_height
+ end
##|
- ##| DRAWING
+ ##| START AT 0, 0, AND START FLOATING
##|
- def drawRect(rect)
- super
+ def layoutSubviews
+ @x = @y = 0 # the coordinates for the next frame
+ @max_height = 0 # the max_height of *all* the rows so far (not just the current row)
+
+ frame = self.frame
+ # the width, which is fixed. when a row would be longer than this, it is
+ # wrapped to the next row.
+ @fixed_width = frame.size.width
+
+ self.subviews.each do |view|
+ add_next(view)
+ end
+ end
+
+ def add_next(view)
+ # ignore the x, y of the added view, we only respect the size
+ view_frame = view.frame
+
+ # new row?
+ self.clear if @x + view_frame.size.width > @fixed_width
+
+ # new max_height?
+ @max_height = @y + view_frame.size.height if @y + view_frame.size.height > @max_height
+
+ view_frame.origin.x = @x
+ @x += view_frame.size.width
+ view_frame.origin.y = @y
+
+ view.frame = view_frame
end
end
-module BoxFloatDelegate
+module TypewriterDelegate
end
View
39 spec/main_spec.rb
@@ -1,9 +1,46 @@
-describe "Application 'boxfloat'" do
+describe "Application 'typewriter'" do
before do
@app = UIApplication.sharedApplication
end
it "has one window" do
@app.windows.size.should == 1
end
+
+ it "has a rootViewController" do
+ @app.windows[0].rootViewController.nil?.should != true
+ end
+
+ it "has a subview, same as its rootViewController" do
+ @app.windows[0].subviews.length.should == 1
+
+ @app.windows[0].subviews[0].should == @app.windows[0].rootViewController.view
+ end
+
+ it "has a TypewriterView" do
+ typewriter = @app.windows[0].subviews[0].subviews[0]
+ typewriter.class.name.should == "TypewriterView"
+ end
+
+ describe "adding subviews to typewriter" do
+
+ before do
+ @app = UIApplication.sharedApplication
+ @typewriter = @app.windows[0].subviews[0].subviews[0]
+ end
+
+ it "has a bunch of subviews" do
+ @typewriter.subviews.length.should > 1
+ end
+
+ it "should not have overlapping subviews" do
+ @typewriter.subviews.each { |subview|
+ @typewriter.subviews.select {|v| v != subview }.each { |check|
+ CGRectIntersectsRect(subview.frame, check.frame).should == false
+ }
+ }
+ end
+
+ end
+
end

0 comments on commit 5d494c8

Please sign in to comment.