rmq icon indicating copy to clipboard operation
rmq copied to clipboard

distribute(:horizontal, alignment: :centered)

Open twerth opened this issue 10 years ago • 10 comments

@markrickert and I were discussing this.

So layout has centered: :horizontal and such, but if you apply a layout to a set of views, it will get applied to each individually. But sometimes you want to apply something like that to a group of views. Dealing with groups is what distribute is good at. So the idea is to add some new params to distribute to handle this.

Perhaps this is overloading distribute too much and we should make a group_layout instead.

Something like this:

[   [a]      [     b     ]                [c] ]

Then this

rmq(a,b,c).distribute(:horizontal, margin: 5, alignment: :centered)

Does this

[            [a] [     b     ] [c]           ]

Or this

rmq(a,b,c).distribute(:horizontal, margin: 5, alignment: :right)

Does this

[                    [a] [     b     ] [c] ]

^ in this case, does a 5 margin get applied between [c] and the parent's right?

twerth avatar Jan 06 '15 20:01 twerth

Now that I reread what I wrote, perhaps a group_layout is better. Like

rmq(a,b,c).group_layout(centered: :horizontal)

In the case above you could do this

rmq(a,b,c).distribute(:horizontal, margin: 5).group_layout(centered: :horizontal)

Then you could do any layout thing, like:

rmq(a,b,c).group_layout(from_left: 2, from_bottom: 5)

And they would all move as a group

twerth avatar Jan 06 '15 20:01 twerth

Yeah, i like the group_layout idea.

markrickert avatar Jan 06 '15 20:01 markrickert

chuck thumbs

GantMan avatar Jan 06 '15 20:01 GantMan

so group_layout only have movement type things, right? Anyone start this?

squidpunch avatar Feb 26 '15 13:02 squidpunch

I don't believe anyone has started on this, though I've coded around it recently to get some similar behavior in my own app.

markrickert avatar Feb 26 '15 16:02 markrickert

Honestly, putting everything on a UIView isn't a terrible solution. It helps with eventually moving it to a partial and adding animations to the whole set. imho

GantMan avatar Feb 28 '15 23:02 GantMan

I guess the workflow would be to add everything to the UIView and then resize_frame_to_fit_subviews and then center the view, huh?

markrickert avatar Mar 02 '15 16:03 markrickert

yup. Containing views ( very HTML DIVish ) but I've seen no major performance issues.

GantMan avatar Mar 02 '15 16:03 GantMan

I'm wondering if instead of doing a bunch of math to layout the views, if we use that approach in this feature behind the scenes to implement the grouped layout?

markrickert avatar Mar 02 '15 16:03 markrickert

rmq(:view1, :view2, :view3).group_layout(centered: horizontal)

# behind the scenes
append(UIView, :centered_horizontal_view).tap do |chv|
  views.each do |v|
    chv.unappend.append(v)
  end
end

or something like that. But i'm not sure if we want to be adding views to the user's app behind the scenes.

markrickert avatar Mar 02 '15 17:03 markrickert