Skip to content
This repository has been archived by the owner on Dec 2, 2021. It is now read-only.

Commit

Permalink
Added CoverLayout and LinkedListViewSequence to readme.
Browse files Browse the repository at this point in the history
  • Loading branch information
IjzerenHein committed Oct 13, 2015
1 parent 58e3e67 commit 55078de
Show file tree
Hide file tree
Showing 2 changed files with 194 additions and 6 deletions.
16 changes: 10 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ In order to make this happen, community contributions would be very welcome to s
- [ListLayout](docs/layouts/ListLayout.md) *(scrollable)*
- [CollectionLayout](docs/layouts/CollectionLayout.md) *(scrollable)*
- [WheelLayout](docs/layouts/WheelLayout.md) *(scrollable)*
- [CoverLayout](docs/layouts/CoverLayout.md) *(scrollable)*

### Resources
- [Documentation](#documentation)
Expand Down Expand Up @@ -151,10 +152,11 @@ The data-source contains the renderables that are to be layed-out.
It can be one of three things:

- An `Array`
- A `ViewSequence`
- A `LinkedListViewSequence`
- A `VirtualViewSequence`
- An `Object` with key/value pairs

In case of an `Array` or `ViewSequence`, use `context.next()` in your
In case of an `Array` or a `ViewSequence`, use `context.next()` in your
layout-function to enumerate all the renderables in the data-source:

```javascript
Expand Down Expand Up @@ -249,14 +251,15 @@ Layout helpers are special classes that simplify writing layout functions.

|Layout|DataSource|Scrollable|Description|
|---|---|---|---|
|[ProportionalLayout](docs/layouts/ProportionalLayout.md)|ViewSequence / Array|No|Lays out renderables sequentially and sizes them proportionally.|
|[ProportionalLayout](docs/layouts/ProportionalLayout.md)|LinkedListViewSequence / Array|No|Lays out renderables sequentially and sizes them proportionally.|
|[HeaderFooterLayout](docs/layouts/HeaderFooterLayout.md)|Id-based|No|Layout containing a top-header, bottom- footer and content.|
|[NavBarLayout](docs/layouts/NavBarLayout.md)|Id-based|No|Layout containing one or more left and right items and a title.|
|[TabBarLayout](docs/layouts/TabBarLayout.md)|Id-based|No|Tab-bar layout.|
|*Scrollable layouts:*|
|[ListLayout](docs/layouts/ListLayout.md)|ViewSequence / Array|Yes|List layout with margins, spacing and optionally sticky headers.|
|[CollectionLayout](docs/layouts/CollectionLayout.md)|ViewSequence / Array|Yes|Lays out renderables in a grid with a specific width & height.|
|[WheelLayout](docs/layouts/WheelLayout.md)|ViewSequence / Array|Yes|Lays out renderables in a wheel (slot-machine) formation.|
|[ListLayout](docs/layouts/ListLayout.md)|LinkedListViewSequence / Array|Yes|List layout with margins, spacing and optionally sticky headers.|
|[CollectionLayout](docs/layouts/CollectionLayout.md)|LinkedListViewSequence / Array|Yes|Lays out renderables in a grid with a specific width & height.|
|[WheelLayout](docs/layouts/WheelLayout.md)|LinkedListViewSequence / Array|Yes|Lays out renderables in a wheel (slot-machine) formation.|
|[CoverLayout](docs/layouts/CoverLayout.md)|LinkedListViewSequence / Array|Yes|Lays out renderables in a wheel (slot-machine) formation.|


## Documentation
Expand All @@ -273,6 +276,7 @@ Layout helpers are special classes that simplify writing layout functions.
|[LayoutContext](docs/LayoutContext.md)|Context used for writing layout-functions.|
|[LayoutUtility](docs/LayoutUtility.md)|Utility class containing helper functions.|
|[VirtualViewSequence](docs/VirtualViewSequence.md)|Infinite view-sequence which uses a factory delegate to create renderables.|
|[LinkedListViewSequence](docs/LinkedListViewSequence.md)|Linked-list based View-sequence which resolves various issues with the stock famo.us ViewSequence.|


## Roadmap
Expand Down
184 changes: 184 additions & 0 deletions src/layouts/FontLayout.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
/**
* This Source Code is licensed under the MIT license. If a copy of the
* MIT-license was not distributed with this file, You can obtain one at:
* http://opensource.org/licenses/mit-license.html.
*
* @author: Hein Rutjes (IjzerenHein)
* @license MIT
* @copyright Gloey Apps, 2014
*/

/*global define, console*/
/*eslint no-console: 0*/

/**
* Lays out renderables as a font text string.
*
* |options|type|description|
* |---|---|---|
* |`itemSize`|Size|Size (width or height) of an item to layout.|
* |`[diameter]`|Number|Diameter of the wheel in pixels (default: `3 x itemSize`).|
* |`[radialOpacity]`|Number|Opacity (0..1) at the diameter edges of the wheel (default: 1).|
*
* Example:
*
* ```javascript
* var ContainerSurface = require('famous/surfaces/ContainerSurface');
* var ScrollController = require('famous-flex/ScrollController');
* var WheelLayout = require('famous-flex/layouts/WheelLayout');
*
* // Create scroll-wheel
* var scrollWheel = new ScrollController({
* layout: WheelLayout,
* layoutOptions: {
* itemSize: 100, // item has height of 100 pixels
* radialOpacity: 0.5 // make items at the edges more transparent
* },
* dataSource: [
* new Surface({content: 'item 1'}),
* new Surface({content: 'item 2'}),
* new Surface({content: 'item 3'})
* ]
* });
*
* // Create a container-surface for clipping and give it a nice perspective
* var container = new ContainerSurface({
* properties: {
* overflow: 'hidden'
* }
* });
* container.context.setPerspective(1500);
* container.add(scrollWheel);
* ```
* @module
*/
define(function(require, exports, module) {

// import dependencies
var Utility = require('famous/utilities/Utility');

// Define capabilities of this layout function
var capabilities = {
sequence: true,
direction: [Utility.Direction.X, Utility.Direction.Y]
};

// Character-segments are layed out in clockwise order:
// ---0---
// 5 1
// |--6--|
// 4 2
// ---3---
//
var charMap = {
'0': 0x3F,
'1': 0x06,
'2': 0x5B,
'3': 0x4F,
'4': 0x66,
'5': 0x6D,
'6': 0x7D,
'7': 0x07,
'8': 0x7F,
'9': 0x6F,
'?': 0x53,
'-': 0x40,
'A': 0x77,
'B': 0x7C,
'C': 0x39,
'D': 0x5E,
'E': 0x79,
'F': 0x71,
'G': 0x6F,
'H': 0x76,
'I': 0x06,
'J': 0x0E,
'K': 0x7F,
'L': 0x38,
'M': 0xD4,
'N': 0x54,
'O': 0x5C,
'P': 0x73,
'Q': 0x67,
'R': 0x50,
'S': 0x6D,
'T': 0x78,
'U': 0x3E,
'V': 0x3E,
'W': 0x7F,
'X': 0x7F,
'Y': 0x7F,
'Z': 0x7F
};

// Segments that make up a characters in clockwise order:
// [translateX, translateY, rotation, lineOffsetX, lineOffsetY]
var segmentMap = [
[0, 0, 0, 1, 0],
[1, 0, 0.25, 2, 1],
[1, 1, 0.25, 2, 2],
[0, 2, 0, 1, 2],
[0, 1, 0.25, 1, 2],
[0, 0, 0.25, 1, 1],
[0, 1, 0, 1, 1],
[0.5, 1, 0.25, 1.5, 2]
];

// Data
var size;
var direction;
var text;
var spacing;
var node;
var offset;
var set = {
size: [0, 0],
translate: [0, 0, 0],
rotate: [0, 0, 0]
};

/**
* Font-layout
*/
function FontLayout(context, options) {

// Prepare
size = context.size;
direction = context.direction;
text = options.text || 'KLMNOPQRSTUVW';
spacing = (options.spacing === undefined) ? 10 : options.spacing;
offset = 0;
set.size[0] = options.segmentSize ? options.segmentSize[0] : 20;
set.size[1] = options.segmentSize ? options.segmentSize[1] : 4;

for (var i = 0; i < text.length; i++) {
var charSegments = charMap[text.charAt(i)] || charMap['?'];
for (var j = 0; j < 8; j++) {
if (charSegments & (1 << j)) {
node = context.next();
if (!node) {
return;
}
var segment = segmentMap[j];
set.translate[0] = (set.size[0] * segment[0]) + (segment[3] * set.size[1]);
set.translate[1] = (set.size[0] * segment[1]) + (segment[4] * set.size[1]);
set.translate[direction] += offset;
set.rotate[2] = (segment[2] * Math.PI * 2);
set.scrollLength = i ? 0 : (direction ? (set.size[0] * 2) : set.size[1]);
if ((j === 0) && (i < (text.length - 1))) {
set.scrollLength += spacing;
}
context.set(node, set);
}
}

// Advance offset for next character
offset += (direction ? (set.size[0] * 2) : set.size[0]) + spacing;
}
}

FontLayout.Capabilities = capabilities;
FontLayout.Name = 'FontLayout';
FontLayout.Description = 'Font layout';
module.exports = FontLayout;
});

0 comments on commit 55078de

Please sign in to comment.