Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create ability to set layout direction #83

Open
H2wk opened this issue Jun 5, 2013 · 3 comments
Open

Create ability to set layout direction #83

H2wk opened this issue Jun 5, 2013 · 3 comments

Comments

@H2wk
Copy link

H2wk commented Jun 5, 2013

At the moment I want to scroll only horizontally.

but after calling:

[self.scroller layoutWithSpeed:0.3 completion:nil]; 

My scroll views content size width is set to standard width for detail view which is 706 pixels.

But my Grid has a greater width and it is then not horizontally scrollable.

I was forced to manually set scrollable area (contentSize) after the layoutWithSpeed method.

[Code below]

self.scroller.contentSize = (CGSize){2000,655};
self.scroller.contentLayoutMode = MGLayoutGridStyle;
self.scroller.bottomPadding = 2;

visibleRect.origin = self.scroller.contentOffset;
visibleRect.size = self.scroller.contentSize;
NSLog(@"Scroller Init: %@",NSStringFromCGRect(visibleRect));

MGBox *grid = [MGBox boxWithSize:(CGSize){2000,400}];
grid.contentLayoutMode = MGLayoutGridStyle;

[self.scroller.boxes addObject:grid];

MGBox *box;
for (int i = 0; i < 50; i++) {
    if(i==0 || i==6){
        box = [MGBox boxWithSize:(CGSize){50,50}];
        box.backgroundColor = [UIColor blueColor];
    }else{
        box = [MGBox boxWithSize:(CGSize){100, 100}];
        box.backgroundColor = [UIColor lightGrayColor];
    }
    box.leftMargin = box.topMargin = 10;

    [grid.boxes addObject:box];
}

[grid layoutWithSpeed:0.3 completion:nil];

//Scroller Size is set here progrmatically
[self.scroller layoutWithSpeed:0.3 completion:nil];

visibleRect.origin = self.scroller.contentOffset;
visibleRect.size = self.scroller.contentSize;
NSLog(@"Layout Speed Method: %@",NSStringFromCGRect(visibleRect));

//Manually Set Scrollers size
//self.scroller.contentSize = (CGSize){2000,655};

[self.scroller scrollToView:grid withMargin:10];
@sobri909
Copy link
Owner

sobri909 commented Jun 5, 2013

Yeah, horizontally expanding layouts aren't built in yet. The two built in layout algorithms (grid and table) are designed to expand vertically. They base their content width off the width of the container (eg the parent MGScrollView or MGBox).

It probably wouldn't be a big task to add a new layout algorithm for horizontally expanding grids. Either configurable with a new contentLayoutMode value, or perhaps a boolean to distinguish between vertically expanding and horizontally expanding. The logic would be essentially the same, just with a handful of if conditions and CGFloat additions twiddled around.

If you want to have a crack at it, the relevant code is in MGLayoutManager.m

@dylanjt
Copy link

dylanjt commented Jan 29, 2015

I'll have a crack at it.

@sobri909: to me it makes most sense that this functionality apply only to grid layouts. Is there any reason for this to be adapted for table layouts as well?

@sobri909
Copy link
Owner

I'd prefer to eventually have it available for both layout modes. There are some use cases. But no sense in building something you don't need, so if it's not useful to you, I wouldn't waste time coding it up.

Note that layout code is currently duplicated between the box provider system and the older layout API. It's not ideal working conditions inside MGLayoutManager. Again, I'd say only code it up for the layout engine you need it for (ie box provider or old API). Eventually that stuff should be deduplicated and refactored into something more sensible. Though it's fiddly stuff.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants