colinta / teacup

This project has been sunset in favor of MotionKit
github.com/motion-kit/motion-kit
Other
602 stars 85 forks source link

Proposal for special class-specific setters. #40

Closed colinta closed 12 years ago

colinta commented 12 years ago

I've mentioned this before, want to bring it up again.

Easiest example is UIButton. Setting title: calls setTitle(value, forState: UIControlStateNormal). But what about setImage(value, forState: UIControlStateNormal) and setImage(value, forState: UIControlStateHighlighted)?

I propose that we fix this by adding a way to attach procs to labels, and those become the new "setter" for that property.

UIButton.apply :title { |view, value|
  view.setTitle(value, forState: UIControlStateNormal)
}

style :my_button,
  title: 'Click me'

This would have the side effect (benefit?) that you could create your own shorthands, and we wouldn't have to add them to core teacup (which would just continue to grow - :unamused:)

MyView.apply :hidden { |view, is_hidden|
  self.layer.opacity = is_hidden ? 0 : 1
}
colinta commented 12 years ago

I think apply is a bad name, but it popped into my head first.

colinta commented 12 years ago

I'm playing with this in my assign branch branch.

colinta commented 12 years ago

Also added is a debug feature. Just add debug: true to your style, or to the view, and it will show you what and HOW it is assigning a property (whether it is using a setter, a property, or a "handler")

colinta commented 12 years ago

I guess this is my new feature branch. Another proposal:

subview(UIButton, :name)
subview(UIButton, :email)

Later, when I want to use those views

self.view[:name]
self.view[:email]

Access them by stylename! Since stylenames can be used on more than one view, there is also an all method

self.view.all :email
colinta commented 12 years ago

I moved the subview-getter code into sweettea, they are available in teacup as viewsWithStylename and viewWithStylename.