Skip to content

Commit

Permalink
initial launch, pretty *darn* simple tool...
Browse files Browse the repository at this point in the history
  • Loading branch information
colinta committed Jun 10, 2012
1 parent 8da9394 commit 5d494c8
Show file tree
Hide file tree
Showing 6 changed files with 162 additions and 16 deletions.
21 changes: 19 additions & 2 deletions README.md
@@ -1,7 +1,24 @@
BoxFloat Typewriter
-------- --------


I couldn't get Three20 Launcher to work, but then I thought "really, how hard I couldn't get Three20 Launcher to work, but then I thought "really, how hard
could this be?" 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
2 changes: 1 addition & 1 deletion Rakefile
Expand Up @@ -8,5 +8,5 @@ dirs = ['lib', 'app']
Motion::Project::App.setup do |app| Motion::Project::App.setup do |app|
# Use `rake config' to see complete project settings. # Use `rake config' to see complete project settings.
app.files = dirs.map{|d| Dir.glob(File.join(app.project_dir, "#{d}/**/*.rb")) }.flatten app.files = dirs.map{|d| Dir.glob(File.join(app.project_dir, "#{d}/**/*.rb")) }.flatten
app.name = 'BoxFloat' app.name = 'Typewriter'
end end
6 changes: 6 additions & 0 deletions app/app_delegate.rb
@@ -1,5 +1,11 @@
class AppDelegate class AppDelegate
def application(application, didFinishLaunchingWithOptions:launchOptions) def application(application, didFinishLaunchingWithOptions:launchOptions)
application.setStatusBarStyle(UIStatusBarStyleBlackTranslucent)

@window = UIWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds)
@window.rootViewController = FirstController.new
@window.makeKeyAndVisible

true true
end end
end end
50 changes: 50 additions & 0 deletions 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
60 changes: 48 additions & 12 deletions lib/boxfloat/view.rb
@@ -1,24 +1,60 @@


class BoxFloatView < UIView class TypewriterView < UIView


def apps def initWithFrame(frame)
@apps ||= [] super
frame = self.frame # frame could be [[], []] or a CGRect; normalize it.

layoutSubviews

self
end end


##| def frame=(new_frame)
##| STYLES super
##| easily stylable using teacup layoutSubviews
##| * backgroundColor is already supported by UIView end
##|
def clear
@x = 0
@y = @max_height
end


##| ##|
##| DRAWING ##| START AT 0, 0, AND START FLOATING
##| ##|
def drawRect(rect) def layoutSubviews
super @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


end end


module BoxFloatDelegate module TypewriterDelegate
end end
39 changes: 38 additions & 1 deletion spec/main_spec.rb
@@ -1,9 +1,46 @@
describe "Application 'boxfloat'" do describe "Application 'typewriter'" do
before do before do
@app = UIApplication.sharedApplication @app = UIApplication.sharedApplication
end end


it "has one window" do it "has one window" do
@app.windows.size.should == 1 @app.windows.size.should == 1
end 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 end

0 comments on commit 5d494c8

Please sign in to comment.