diff --git a/engine/src/flutter/examples/README.md b/engine/src/flutter/examples/README.md deleted file mode 100644 index deb0f3cf10..0000000000 --- a/engine/src/flutter/examples/README.md +++ /dev/null @@ -1,16 +0,0 @@ -Sky Examples -============ - -This directory contains several examples of using Sky. Each of these is an -individual Dart application package. If you wish to run them with `sky_tool` -then you will want to run `pub get` inside their directory before running -`./packages/sky/sky_tool start`. - -1. *Hello, world.* The [hello world app](hello_world) is a basic app that shows - the text "hello, world." - -2. *Stocks.* The [stocks app](stocks) is an example of a typical mobile app - built using Sky. The app shows a list of all the stocks in the NASDAQ. - -3. *Widgets.* The [widgets app](widgets) contains a number of Sky widgets so - you can experiment with them in a simple container. diff --git a/engine/src/flutter/examples/hello_world/hello_world.dart b/engine/src/flutter/examples/hello_world/hello_world.dart deleted file mode 100644 index e20978844d..0000000000 --- a/engine/src/flutter/examples/hello_world/hello_world.dart +++ /dev/null @@ -1,11 +0,0 @@ -// Copyright 2015 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -import 'package:sky/framework/fn.dart'; - -class HelloWorldApp extends App { - UINode build() { - return new Text('Hello, world!'); - } -} diff --git a/engine/src/flutter/examples/hello_world/main.sky b/engine/src/flutter/examples/hello_world/main.sky deleted file mode 100644 index a32206943c..0000000000 --- a/engine/src/flutter/examples/hello_world/main.sky +++ /dev/null @@ -1,7 +0,0 @@ - diff --git a/engine/src/flutter/examples/hello_world/pubspec.yaml b/engine/src/flutter/examples/hello_world/pubspec.yaml deleted file mode 100644 index fb27d11e6b..0000000000 --- a/engine/src/flutter/examples/hello_world/pubspec.yaml +++ /dev/null @@ -1,3 +0,0 @@ -name: hello_world -dependencies: - sky: any diff --git a/engine/src/flutter/examples/lib/solid_color_box.dart b/engine/src/flutter/examples/lib/solid_color_box.dart deleted file mode 100644 index b6624c666f..0000000000 --- a/engine/src/flutter/examples/lib/solid_color_box.dart +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright 2015 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -import 'dart:sky' as sky; -import 'package:sky/rendering/object.dart'; -import 'package:sky/rendering/box.dart'; - -class RenderSolidColorBox extends RenderDecoratedBox { - final Size desiredSize; - final Color backgroundColor; - - RenderSolidColorBox(Color backgroundColor, { this.desiredSize: Size.infinite }) - : backgroundColor = backgroundColor, - super(decoration: new BoxDecoration(backgroundColor: backgroundColor)); - - double getMinIntrinsicWidth(BoxConstraints constraints) { - return constraints.constrainHeight( - this.desiredSize == Size.infinite ? 0.0 : desiredSize.width - ); - } - - double getMaxIntrinsicWidth(BoxConstraints constraints) { - return constraints.constrainWidth( - this.desiredSize == Size.infinite ? 0.0 : desiredSize.width - ); - } - - double getMinIntrinsicHeight(BoxConstraints constraints) { - return constraints.constrainHeight( - this.desiredSize == Size.infinite ? 0.0 : desiredSize.height - ); - } - - double getMaxIntrinsicHeight(BoxConstraints constraints) { - return constraints.constrainHeight( - this.desiredSize == Size.infinite ? 0.0 : desiredSize.height - ); - } - - void performLayout() { - size = constraints.constrain(desiredSize); - } - - void handleEvent(sky.Event event, BoxHitTestEntry entry) { - if (event.type == 'pointerdown') - decoration = new BoxDecoration(backgroundColor: const Color(0xFFFF0000)); - else if (event.type == 'pointerup') - decoration = new BoxDecoration(backgroundColor: backgroundColor); - } -} diff --git a/engine/src/flutter/examples/mine_digger/mine_digger.dart b/engine/src/flutter/examples/mine_digger/mine_digger.dart deleted file mode 100644 index aa205638cd..0000000000 --- a/engine/src/flutter/examples/mine_digger/mine_digger.dart +++ /dev/null @@ -1,373 +0,0 @@ -// Copyright 2015 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -import 'dart:sky' as sky; -import 'dart:math'; - -import 'package:sky/rendering/flex.dart'; -import 'package:sky/widgets/basic.dart'; -import 'package:sky/widgets/scaffold.dart'; -import 'package:sky/widgets/tool_bar.dart'; -import 'package:sky/widgets/theme.dart'; -import 'package:sky/theme/colors.dart' as colors; -import 'package:sky/painting/text_style.dart'; - -// Classic minesweeper-inspired game. The mouse controls are standard except -// for left + right combo which is not implemented. For touch, the duration of -// the pointer determines probing versus flagging. -// -// There are only 3 classes to understand. Game, which is contains all the -// logic and two UI classes: CoveredMineNode and ExposedMineNode, none of them -// holding state. - -class Game { - static const int rows = 9; - static const int cols = 9; - static const int totalMineCount = 11; - - static const int coveredCell = 0; - static const int explodedCell = 1; - static const int clearedCell = 2; - static const int flaggedCell = 3; - static const int shownCell = 4; - - static final List textStyles = new List(); - - final App app; - - bool alive; - bool hasWon; - int detectedCount; - int randomSeed; - - // |cells| keeps track of the positions of the mines. - List> cells; - // |uiState| keeps track of the visible player progess. - List> uiState; - - Game(this.app) { - randomSeed = 22; - // Colors for each mine count: - // 0 - none, 1 - blue, 2-green, 3-red, 4-black, 5-dark red .. etc. - textStyles.add( - new TextStyle(color: const Color(0xFF555555), fontWeight: bold)); - textStyles.add( - new TextStyle(color: const Color(0xFF0094FF), fontWeight: bold)); - textStyles.add( - new TextStyle(color: const Color(0xFF13A023), fontWeight: bold)); - textStyles.add( - new TextStyle(color: const Color(0xFFDA1414), fontWeight: bold)); - textStyles.add( - new TextStyle(color: const Color(0xFF1E2347), fontWeight: bold)); - textStyles.add( - new TextStyle(color: const Color(0xFF7F0037), fontWeight: bold)); - textStyles.add( - new TextStyle(color: const Color(0xFFE93BE9), fontWeight: bold)); - initialize(); - } - - void initialize() { - alive = true; - hasWon = false; - detectedCount = 0; - // Build the arrays. - cells = new List>(); - uiState = new List>(); - for (int iy = 0; iy != rows; iy++) { - cells.add(new List()); - uiState.add(new List()); - for (int ix = 0; ix != cols; ix++) { - cells[iy].add(false); - uiState[iy].add(coveredCell); - } - } - // Place the mines. - Random random = new Random(++randomSeed); - for (int mc = 0; mc != totalMineCount; mc++) { - int rx = random.nextInt(rows); - int ry = random.nextInt(cols); - if (cells[ry][rx]) { - // Mine already there. Try again. - --mc; - } else { - cells[ry][rx] = true; - } - } - } - - Widget buildBoard() { - bool hasCoveredCell = false; - List flexRows = new List(); - for (int iy = 0; iy != 9; iy++) { - List row = new List(); - for (int ix = 0; ix != 9; ix++) { - int state = uiState[iy][ix]; - int count = mineCount(ix, iy); - - if (!alive) { - if (state != explodedCell) - state = cells[iy][ix] ? shownCell : state; - } - - if (state == coveredCell) { - row.add(new CoveredMineNode( - this, - flagged: false, - posX: ix, posY: iy)); - // Mutating |hasCoveredCell| here is hacky, but convenient, same - // goes for mutating |hasWon| below. - hasCoveredCell = true; - } else if (state == flaggedCell) { - row.add(new CoveredMineNode( - this, - flagged: true, - posX: ix, posY: iy)); - } else { - row.add(new ExposedMineNode( - state: state, - count: count)); - } - } - flexRows.add( - new Flex( - row, - direction: FlexDirection.horizontal, - justifyContent: FlexJustifyContent.center, - key: 'flex_row($iy)' - )); - } - - if (!hasCoveredCell) { - // all cells uncovered. Are all mines flagged? - if ((detectedCount == totalMineCount) && alive) { - hasWon = true; - } - } - - return new Container( - key: 'minefield', - padding: new EdgeDims.all(10.0), - margin: new EdgeDims.all(10.0), - decoration: new BoxDecoration(backgroundColor: const Color(0xFF6B6B6B)), - child: new Flex( - flexRows, - direction: FlexDirection.vertical, - key: 'flxv')); - } - - Widget buildToolBar() { - String banner = hasWon ? - 'Awesome!!' : alive ? - 'Mine Digger [$detectedCount-$totalMineCount]': 'Kaboom! [press here]'; - - return new ToolBar( - // FIXME: Strange to have the toolbar be tapable. - center: new Listener( - onPointerDown: handleBannerPointerDown, - child: new Text(banner, style: Theme.of(this.app).text.title) - ) - ); - } - - Widget buildUI() { - // FIXME: We need to build the board before we build the toolbar because - // we compute the win state during build step. - Widget board = buildBoard(); - return new Scaffold( - toolbar: buildToolBar(), - body: new Container( - child: new Center(child: board), - decoration: new BoxDecoration(backgroundColor: colors.Grey[50]) - ) - ); - } - - void handleBannerPointerDown(sky.PointerEvent event) { - initialize(); - app.setState((){}); - } - - // User action. The user uncovers the cell which can cause losing the game. - void probe(int x, int y) { - if (!alive) - return; - if (uiState[y][x] == flaggedCell) - return; - // Allowed to probe. - if (cells[y][x]) { - // Probed on a mine --> dead!! - uiState[y][x] = explodedCell; - alive = false; - } else { - // No mine, uncover nearby if possible. - cull(x, y); - } - app.setState((){}); - } - - // User action. The user is sure a mine is at this location. - void flag(int x, int y) { - if (uiState[y][x] == flaggedCell) { - uiState[y][x] = coveredCell; - --detectedCount; - } else { - uiState[y][x] = flaggedCell; - ++detectedCount; - } - app.setState((){}); - } - - // Recursively uncovers cells whose totalMineCount is zero. - void cull(int x, int y) { - if ((x < 0) || (x > rows - 1)) - return; - if ((y < 0) || (y > cols - 1)) - return; - - if (uiState[y][x] == clearedCell) - return; - uiState[y][x] = clearedCell; - - if (mineCount(x, y) > 0) - return; - - cull(x - 1, y); - cull(x + 1, y); - cull(x, y - 1); - cull(x, y + 1 ); - cull(x - 1, y - 1); - cull(x + 1, y + 1); - cull(x + 1, y - 1); - cull(x - 1, y + 1); - } - - int mineCount(int x, int y) { - int count = 0; - int my = cols - 1; - int mx = rows - 1; - - count += x > 0 ? bombs(x - 1, y) : 0; - count += x < mx ? bombs(x + 1, y) : 0; - count += y > 0 ? bombs(x, y - 1) : 0; - count += y < my ? bombs(x, y + 1 ) : 0; - - count += (x > 0) && (y > 0) ? bombs(x - 1, y - 1) : 0; - count += (x < mx) && (y < my) ? bombs(x + 1, y + 1) : 0; - count += (x < mx) && (y > 0) ? bombs(x + 1, y - 1) : 0; - count += (x > 0) && (y < my) ? bombs(x - 1, y + 1) : 0; - - return count; - } - - int bombs(int x, int y) { - return cells[y][x] ? 1 : 0; - } -} - -Widget makeCell(Widget widget) { - return new Container( - padding: new EdgeDims.all(1.0), - height: 27.0, width: 27.0, - decoration: new BoxDecoration(backgroundColor: const Color(0xFFC0C0C0)), - margin: new EdgeDims.all(2.0), - child: widget); -} - -Widget makeInnerCell(Widget widget) { - return new Container( - padding: new EdgeDims.all(1.0), - margin: new EdgeDims.all(3.0), - height: 17.0, width: 17.0, - child: widget); -} - -class CoveredMineNode extends Component { - final Game game; - final bool flagged; - final int posX; - final int posY; - Stopwatch stopwatch; - - CoveredMineNode(this.game, {this.flagged, this.posX, this.posY}); - - void _handlePointerDown(sky.PointerEvent event) { - if (event.buttons == 1) { - game.probe(posX, posY); - } else if (event.buttons == 2) { - game.flag(posX, posY); - } else { - // Touch event. - stopwatch = new Stopwatch()..start(); - } - } - - void _handlePointerUp(sky.PointerEvent event) { - if (stopwatch == null) - return; - // Pointer down was a touch event. - var ms = stopwatch.elapsedMilliseconds; - if (stopwatch.elapsedMilliseconds < 250) { - game.probe(posX, posY); - } else { - // Long press flags. - game.flag(posX, posY); - } - stopwatch = null; - } - - Widget build() { - Widget text = flagged ? - makeInnerCell(new StyledText(elements : [Game.textStyles[5], '\u2691'])) : - null; - - Container inner = new Container( - margin: new EdgeDims.all(2.0), - height: 17.0, width: 17.0, - decoration: new BoxDecoration(backgroundColor: const Color(0xFFD9D9D9)), - child: text); - - return makeCell(new Listener( - child: inner, - onPointerDown: _handlePointerDown, - onPointerUp: _handlePointerUp)); - } -} - -class ExposedMineNode extends Component { - final int state; - final int count; - - ExposedMineNode({this.state, this.count}); - - Widget build() { - StyledText text; - if (state == Game.clearedCell) { - // Uncovered cell with nearby mine count. - if (count != 0) - text = new StyledText(elements : [Game.textStyles[count], '$count']); - } else { - // Exploded mine or shown mine for 'game over'. - int color = state == Game.explodedCell ? 3 : 0; - text = new StyledText(elements : [Game.textStyles[color], '\u2600']); - } - - return makeCell(makeInnerCell(text)); - } -} - -class MineDiggerApp extends App { - Game game; - - MineDiggerApp() { - game = new Game(this); - } - - Widget build() { - return game.buildUI(); - } -} - -void main() { - runApp(new MineDiggerApp()); -} diff --git a/engine/src/flutter/home.dart b/engine/src/flutter/home.dart deleted file mode 100644 index a5a282ca03..0000000000 --- a/engine/src/flutter/home.dart +++ /dev/null @@ -1,87 +0,0 @@ -// Copyright 2015 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -import 'dart:sky'; - -import 'package:mojom/intents/intents.mojom.dart'; -import 'package:sky/framework/shell.dart' as shell; -import 'package:sky/theme/colors.dart' as colors; -import 'package:sky/theme/edges.dart'; -import 'package:sky/theme/typography.dart' as typography; -import 'package:sky/widgets/material.dart'; -import 'package:sky/widgets/raised_button.dart'; -import 'package:sky/widgets/scaffold.dart'; -import 'package:sky/widgets/tool_bar.dart'; -import 'package:sky/widgets/basic.dart'; - -void launch(String relativeUrl) { - Uri url = Uri.base.resolve(relativeUrl); - url = url.replace(scheme: 'sky'); - - ActivityManagerProxy activityManager = new ActivityManagerProxy.unbound(); - Intent intent = new Intent() - ..action = 'android.intent.action.VIEW' - ..url = url.toString(); - shell.requestService(null, activityManager); - activityManager.ptr.startActivity(intent); -} - -class SkyDemo extends Component { - String text; - String href; - - SkyDemo(String text, this.href) : this.text = text, super(key: text); - - void _handlePress() { - launch(href); - } - - Widget build() { - return new ConstrainedBox( - constraints: const BoxConstraints.expandWidth(), - child: new RaisedButton( - child: new Text(text), - onPressed: _handlePress - ) - ); - } -} - -class SkyHome extends App { - Widget build() { - List children = [ - new SkyDemo('Stocks App', 'examples/stocks2/lib/stock_app.dart'), - new SkyDemo('Asteroids Game', 'examples/game/main.dart'), - new SkyDemo('Interactive Flex', 'examples/rendering/interactive_flex.dart'), - new SkyDemo('Sector Layout', 'examples/widgets/sector.dart'), - new SkyDemo('Touch Demo', 'examples/rendering/touch_demo.dart'), - new SkyDemo('Minedigger Game', 'examples/mine_digger/mine_digger.dart'), - - // TODO(eseidel): We could use to separate these groups? - new SkyDemo('Old Stocks App', 'examples/stocks/main.sky'), - new SkyDemo('Old Touch Demo', 'examples/raw/touch-demo.sky'), - new SkyDemo('Old Spinning Square', 'examples/raw/spinning-square.sky'), - - new SkyDemo('Licences (Old)', 'LICENSES.sky'), - ]; - - return new Scaffold( - toolbar: new ToolBar( - center: new Text('Sky Demos', style: typography.white.title), - backgroundColor: colors.Blue[500]), - body: new Material( - edge: MaterialEdge.canvas, - child: new Flex( - children, - direction: FlexDirection.vertical, - justifyContent: FlexJustifyContent.spaceAround - ) - ) - ); - } -} - -void main() { - runApp(new SkyHome()); -} diff --git a/engine/src/flutter/tests/examples/sector.dart b/engine/src/flutter/tests/examples/sector.dart index 2085cc82e9..155daab21f 100644 --- a/engine/src/flutter/tests/examples/sector.dart +++ b/engine/src/flutter/tests/examples/sector.dart @@ -6,7 +6,7 @@ import 'dart:async'; import 'package:sky/widgets/widget.dart'; -import '../../examples/widgets/sector.dart'; +import '../../sdk/lib/example/widgets/sector.dart'; import '../resources/display_list.dart'; main() async { diff --git a/engine/src/flutter/tests/examples/stocks.dart b/engine/src/flutter/tests/examples/stocks.dart index 6d014daf05..a2276a0bbe 100644 --- a/engine/src/flutter/tests/examples/stocks.dart +++ b/engine/src/flutter/tests/examples/stocks.dart @@ -6,7 +6,7 @@ import 'dart:async'; import 'package:sky/widgets/widget.dart'; -import '../../examples/stocks2/lib/stock_app.dart'; +import '../../sdk/lib/example/stocks2/lib/stock_app.dart'; import '../resources/display_list.dart'; class TestStocksApp extends StocksApp { diff --git a/engine/src/flutter/tests/examples/styled_text.dart b/engine/src/flutter/tests/examples/styled_text.dart index 137ec0cd94..7de07db6d9 100644 --- a/engine/src/flutter/tests/examples/styled_text.dart +++ b/engine/src/flutter/tests/examples/styled_text.dart @@ -6,7 +6,7 @@ import 'dart:async'; import 'package:sky/widgets/widget.dart'; -import '../../examples/widgets/styled_text.dart'; +import '../../sdk/lib/example/widgets/styled_text.dart'; import '../resources/display_list.dart'; main() async { diff --git a/engine/src/flutter/tests/examples/tabs.dart b/engine/src/flutter/tests/examples/tabs.dart index a691a9bd99..75d678cbb5 100644 --- a/engine/src/flutter/tests/examples/tabs.dart +++ b/engine/src/flutter/tests/examples/tabs.dart @@ -6,7 +6,7 @@ import 'dart:async'; import 'package:sky/widgets/widget.dart'; -import '../../examples/widgets/tabs.dart'; +import '../../sdk/lib/example/widgets/tabs.dart'; import '../resources/display_list.dart'; main() async { diff --git a/engine/src/flutter/tests/raw/sector_layout.dart b/engine/src/flutter/tests/raw/sector_layout.dart index e3abc94e4a..ecb59de424 100644 --- a/engine/src/flutter/tests/raw/sector_layout.dart +++ b/engine/src/flutter/tests/raw/sector_layout.dart @@ -4,7 +4,7 @@ import 'dart:async'; -import '../../examples/rendering/sector_layout.dart'; +import '../../sdk/lib/example/rendering/sector_layout.dart'; import '../resources/display_list.dart'; void main() { diff --git a/engine/src/flutter/tools/deploy_sdk.py b/engine/src/flutter/tools/deploy_sdk.py index ec147dbb37..dcedc66d1a 100755 --- a/engine/src/flutter/tools/deploy_sdk.py +++ b/engine/src/flutter/tools/deploy_sdk.py @@ -106,7 +106,6 @@ def main(): ensure_dir_exists(sdk_root) # Manually clear sdk_root above to avoid deleting dot-files. delete_all_non_hidden_files_in_directory(sdk_root, args.non_interactive) - copy(src_path('sky/examples'), sdk_path('examples')) copy(src_path('sky/sdk/README.md'), sdk_root)