colinta / teacup

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

Feature Request Auto Layout Quarters #61

Closed GantMan closed 11 years ago

GantMan commented 11 years ago

I'd like Quarter positions in Auto layout. Tried to do a quick fork, but I see you're directly correlating attributes so new concepts have no place.

so center_x correlates to NSLayoutAttributeCenterX

I think it would be clean/clear/idiomatic for there to be quarters and perhaps eventually a grid system for AutoLayout. I added the attribute, but it fails since it's unsupported directly, it bombs out constraint.rb:234

I have no problem adding a .times(0.5) but I think aligning it with the quarter1_x or some other predefined grid logic, might be advantageous and more legible. I'm more than willing to help, but I'm at a loss as to how you'd want to add these (non-apple) supported alignments, or even if they are something you'd want.

colinta commented 11 years ago

I REALLY like the "grid system" idea, but i am also at a loss as to how that would look in the current DSL...

mattsgarrison commented 11 years ago

I was chatting with Gant in person, instead of quarters, an arbitrary grid would be nicer (or a denser grid, for better layout control for the iPads and iPhone5's).

I could see this headed the direction of CSS grid frameworks (a la Bootstrap), where a :superview correlates somewhat to a Bootstrap .container, constrain_lefts could be calculated similar to .span1, .span2.offset2, span12 being equivalent to :full_width and so on.

I'm also not sure yet how this would fit into Teacup's DSL or Autolayout's offered commands, but providing a bit of familiarity to CSS frameworks would bridge the gap for Rubyists even more. We'll brainstorm on this a bit more.

colinta commented 11 years ago

I've been thinking about an addition to teacup that provides "partials" (though i'm not sure the name is perfect). These would be more methods like subview and layout that have the additional behavior of using custom UIView (containers), UICollectionView, or UITableView instances. Code will speak louder than words:

class MyController < UIViewController

  def init
    super.tap do
      @items = ['Mr. Orange', 'Mr. White', 'Mr. Pink']
    end
  end

  layout do
    # these are just ideas, off the top of my head.  take with a spoonful of salt.

    # all views added here will be stacked one on top of the other
    # uses UICollectionView *maybe*, or maybe just does its own frame addition
    flow(:vertical) do
      # easy table view - declare the cell class and items, assigns the textLabel.
      # should be easy to provide custom cell formatting
      table(
        cell: UITableViewCell,  # or a custom cell
        items: @items,
        )

      # I'm imagining this as being integrated with Clayallsopp's formotion gem
      @form = form() do
        @username = string('Username')
        @is_fantastic = boolean('Fantastic?')
      end

      # grid, with 4 pixels around the sides, and 8 pixels between each view
      grid([2, 2], padding: 4, spacing: 8) do
        subview(UIView)  # 1st position, e.g. at [0, 0]
        subview(UIView)  # 2nd position, e.g. at [1, 0]
        subview(UIView)  # 3rd position, e.g. at [0, 1]
        subview(UIView)  # 4th position, e.g. at [1, 1]
      end

      # collection views, see mateus' collection view playground
      # https://github.com/seanlilmateus/CollectionViewPlayGround
      collection(:cover_flow) do |cover_flow|
        # views are added here, and there should be a way to provide them using
        # *either* delegates or blocks.  e.g.
        cover_flow.items = ->{ @items }
      end
    end
  end

end
GantMan commented 11 years ago

how did that collection views thing slip through without me ever seeing it!? I'm going to mess with it ASAP.

colinta commented 11 years ago

I think partials will be a part of sweettea, not part of core teacup. Since auto-layout supports any kind of grid system, I'm marking this as "done" :smiley: