distribute(:horizontal, alignment: :centered)
@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?
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
Yeah, i like the group_layout idea.
![]()
so group_layout only have movement type things, right? Anyone start this?
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.
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
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?
yup. Containing views ( very HTML DIVish ) but I've seen no major performance issues.
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?
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.