Sophie

Sophie

distrib > Fedora > 18 > x86_64 > by-pkgid > 8c86774a3e53d77cc119f53a2b94a57a > files > 311

root-tutorial-5.34.14-2.fc18.noarch.rpm

#import <cassert>

#import "Shortcuts.h"

namespace ROOT {
namespace iOS {
namespace Browser {

void PlaceShortcutsInScrollView(NSMutableArray *shortcuts, UIScrollView *scrollView, const CGSize &size, CGFloat addSpace)
{
   //We assume, that 'shortcuts' (views) are already subviews of a scrollview, I do not check it.

   assert(shortcuts != nil && "PlaceShortcutsInScrollView, parameter 'shortcuts' is nil");
   assert(scrollView != nil && "PlaceShortcutsInScrollView, parameter 'scrollView' is nil");
   
   const CGRect scrollFrame = scrollView.frame;
   const CGFloat shortcutWidth = size.width;
   const CGFloat shortcutHeight = size.height;
   const unsigned nPicksInRow = scrollFrame.size.width / (shortcutWidth + addSpace);
   const CGFloat addXY = (scrollFrame.size.width - (shortcutWidth + addSpace) * nPicksInRow) / 2;
   
   NSEnumerator *enumerator = [shortcuts objectEnumerator];
   UIView *v = [enumerator nextObject];
   for (unsigned n = 0; v; v = [enumerator nextObject], ++n) {
      const unsigned col = n % nPicksInRow;
      const unsigned row = n / nPicksInRow;
      
      const CGFloat x = addXY + addSpace / 2 + col * (shortcutWidth + addSpace);
      const CGFloat y = row * shortcutHeight + addXY;

      CGRect frame = v.frame;
      frame.origin = CGPointMake(x, y);
      v.frame = frame;
   }
   
   scrollView.contentSize = CGSizeMake(scrollFrame.size.width, addXY + ([shortcuts count] + nPicksInRow - 1) / nPicksInRow * shortcutHeight);
   scrollView.contentOffset = CGPointZero;
}

}
}
}