diff --git a/sdk/example/color/color-chooser.sky b/sdk/example/color/color-chooser.sky deleted file mode 100644 index ad66cf993ff..00000000000 --- a/sdk/example/color/color-chooser.sky +++ /dev/null @@ -1,96 +0,0 @@ -#!mojo mojo:sky_viewer - - - -
- -

Select Color

-
- -
diff --git a/sdk/example/color/color-wheel.png b/sdk/example/color/color-wheel.png deleted file mode 100644 index 97dc31c22a8..00000000000 Binary files a/sdk/example/color/color-wheel.png and /dev/null differ diff --git a/sdk/example/color/pubspec.yaml b/sdk/example/color/pubspec.yaml deleted file mode 100644 index c3320617b13..00000000000 --- a/sdk/example/color/pubspec.yaml +++ /dev/null @@ -1,3 +0,0 @@ -name: color -dependencies: - sky: any diff --git a/sdk/example/widgets/hello_widgets.dart b/sdk/example/hello_world/lib/main.dart similarity index 88% rename from sdk/example/widgets/hello_widgets.dart rename to sdk/example/hello_world/lib/main.dart index 34c1f7e5847..699c117c939 100644 --- a/sdk/example/widgets/hello_widgets.dart +++ b/sdk/example/hello_world/lib/main.dart @@ -6,7 +6,7 @@ import 'package:sky/widgets/basic.dart'; class HelloWorldApp extends App { Widget build() { - return new Text('Hello, widgets!'); + return new Text('Hello, world!'); } } diff --git a/sdk/example/hello_world/main.sky b/sdk/example/hello_world/main.sky deleted file mode 100644 index a32206943c2..00000000000 --- a/sdk/example/hello_world/main.sky +++ /dev/null @@ -1,7 +0,0 @@ - diff --git a/sdk/example/hello_world/pubspec.yaml b/sdk/example/hello_world/pubspec.yaml index fb27d11e6b7..be33d87b1a9 100644 --- a/sdk/example/hello_world/pubspec.yaml +++ b/sdk/example/hello_world/pubspec.yaml @@ -1,3 +1,7 @@ name: hello_world +author: Chromium Authors +description: Hello, world using Sky +homepage: https://github.com/domokit/sky_sdk/tree/master/packages/sky/example/hello_world +version: 0.0.1 dependencies: - sky: any + sky: '>=0.0.10 <1.0.0' diff --git a/sdk/example/stocks/README.md b/sdk/example/old/stocks/README.md similarity index 100% rename from sdk/example/stocks/README.md rename to sdk/example/old/stocks/README.md diff --git a/sdk/example/stocks2/data/stock_data_0.json b/sdk/example/old/stocks/data/stock_data_0.json similarity index 100% rename from sdk/example/stocks2/data/stock_data_0.json rename to sdk/example/old/stocks/data/stock_data_0.json diff --git a/sdk/example/stocks2/data/stock_data_1.json b/sdk/example/old/stocks/data/stock_data_1.json similarity index 100% rename from sdk/example/stocks2/data/stock_data_1.json rename to sdk/example/old/stocks/data/stock_data_1.json diff --git a/sdk/example/stocks2/data/stock_data_10.json b/sdk/example/old/stocks/data/stock_data_10.json similarity index 100% rename from sdk/example/stocks2/data/stock_data_10.json rename to sdk/example/old/stocks/data/stock_data_10.json diff --git a/sdk/example/stocks2/data/stock_data_11.json b/sdk/example/old/stocks/data/stock_data_11.json similarity index 100% rename from sdk/example/stocks2/data/stock_data_11.json rename to sdk/example/old/stocks/data/stock_data_11.json diff --git a/sdk/example/stocks2/data/stock_data_12.json b/sdk/example/old/stocks/data/stock_data_12.json similarity index 100% rename from sdk/example/stocks2/data/stock_data_12.json rename to sdk/example/old/stocks/data/stock_data_12.json diff --git a/sdk/example/stocks2/data/stock_data_13.json b/sdk/example/old/stocks/data/stock_data_13.json similarity index 100% rename from sdk/example/stocks2/data/stock_data_13.json rename to sdk/example/old/stocks/data/stock_data_13.json diff --git a/sdk/example/stocks2/data/stock_data_14.json b/sdk/example/old/stocks/data/stock_data_14.json similarity index 100% rename from sdk/example/stocks2/data/stock_data_14.json rename to sdk/example/old/stocks/data/stock_data_14.json diff --git a/sdk/example/stocks2/data/stock_data_15.json b/sdk/example/old/stocks/data/stock_data_15.json similarity index 100% rename from sdk/example/stocks2/data/stock_data_15.json rename to sdk/example/old/stocks/data/stock_data_15.json diff --git a/sdk/example/stocks2/data/stock_data_16.json b/sdk/example/old/stocks/data/stock_data_16.json similarity index 100% rename from sdk/example/stocks2/data/stock_data_16.json rename to sdk/example/old/stocks/data/stock_data_16.json diff --git a/sdk/example/stocks2/data/stock_data_17.json b/sdk/example/old/stocks/data/stock_data_17.json similarity index 100% rename from sdk/example/stocks2/data/stock_data_17.json rename to sdk/example/old/stocks/data/stock_data_17.json diff --git a/sdk/example/stocks2/data/stock_data_18.json b/sdk/example/old/stocks/data/stock_data_18.json similarity index 100% rename from sdk/example/stocks2/data/stock_data_18.json rename to sdk/example/old/stocks/data/stock_data_18.json diff --git a/sdk/example/stocks2/data/stock_data_19.json b/sdk/example/old/stocks/data/stock_data_19.json similarity index 100% rename from sdk/example/stocks2/data/stock_data_19.json rename to sdk/example/old/stocks/data/stock_data_19.json diff --git a/sdk/example/stocks2/data/stock_data_2.json b/sdk/example/old/stocks/data/stock_data_2.json similarity index 100% rename from sdk/example/stocks2/data/stock_data_2.json rename to sdk/example/old/stocks/data/stock_data_2.json diff --git a/sdk/example/stocks2/data/stock_data_20.json b/sdk/example/old/stocks/data/stock_data_20.json similarity index 100% rename from sdk/example/stocks2/data/stock_data_20.json rename to sdk/example/old/stocks/data/stock_data_20.json diff --git a/sdk/example/stocks2/data/stock_data_21.json b/sdk/example/old/stocks/data/stock_data_21.json similarity index 100% rename from sdk/example/stocks2/data/stock_data_21.json rename to sdk/example/old/stocks/data/stock_data_21.json diff --git a/sdk/example/stocks2/data/stock_data_22.json b/sdk/example/old/stocks/data/stock_data_22.json similarity index 100% rename from sdk/example/stocks2/data/stock_data_22.json rename to sdk/example/old/stocks/data/stock_data_22.json diff --git a/sdk/example/stocks2/data/stock_data_23.json b/sdk/example/old/stocks/data/stock_data_23.json similarity index 100% rename from sdk/example/stocks2/data/stock_data_23.json rename to sdk/example/old/stocks/data/stock_data_23.json diff --git a/sdk/example/stocks2/data/stock_data_24.json b/sdk/example/old/stocks/data/stock_data_24.json similarity index 100% rename from sdk/example/stocks2/data/stock_data_24.json rename to sdk/example/old/stocks/data/stock_data_24.json diff --git a/sdk/example/stocks2/data/stock_data_25.json b/sdk/example/old/stocks/data/stock_data_25.json similarity index 100% rename from sdk/example/stocks2/data/stock_data_25.json rename to sdk/example/old/stocks/data/stock_data_25.json diff --git a/sdk/example/stocks2/data/stock_data_26.json b/sdk/example/old/stocks/data/stock_data_26.json similarity index 100% rename from sdk/example/stocks2/data/stock_data_26.json rename to sdk/example/old/stocks/data/stock_data_26.json diff --git a/sdk/example/stocks2/data/stock_data_27.json b/sdk/example/old/stocks/data/stock_data_27.json similarity index 100% rename from sdk/example/stocks2/data/stock_data_27.json rename to sdk/example/old/stocks/data/stock_data_27.json diff --git a/sdk/example/stocks2/data/stock_data_28.json b/sdk/example/old/stocks/data/stock_data_28.json similarity index 100% rename from sdk/example/stocks2/data/stock_data_28.json rename to sdk/example/old/stocks/data/stock_data_28.json diff --git a/sdk/example/stocks2/data/stock_data_29.json b/sdk/example/old/stocks/data/stock_data_29.json similarity index 100% rename from sdk/example/stocks2/data/stock_data_29.json rename to sdk/example/old/stocks/data/stock_data_29.json diff --git a/sdk/example/stocks2/data/stock_data_3.json b/sdk/example/old/stocks/data/stock_data_3.json similarity index 100% rename from sdk/example/stocks2/data/stock_data_3.json rename to sdk/example/old/stocks/data/stock_data_3.json diff --git a/sdk/example/stocks2/data/stock_data_4.json b/sdk/example/old/stocks/data/stock_data_4.json similarity index 100% rename from sdk/example/stocks2/data/stock_data_4.json rename to sdk/example/old/stocks/data/stock_data_4.json diff --git a/sdk/example/stocks2/data/stock_data_5.json b/sdk/example/old/stocks/data/stock_data_5.json similarity index 100% rename from sdk/example/stocks2/data/stock_data_5.json rename to sdk/example/old/stocks/data/stock_data_5.json diff --git a/sdk/example/stocks2/data/stock_data_6.json b/sdk/example/old/stocks/data/stock_data_6.json similarity index 100% rename from sdk/example/stocks2/data/stock_data_6.json rename to sdk/example/old/stocks/data/stock_data_6.json diff --git a/sdk/example/stocks2/data/stock_data_7.json b/sdk/example/old/stocks/data/stock_data_7.json similarity index 100% rename from sdk/example/stocks2/data/stock_data_7.json rename to sdk/example/old/stocks/data/stock_data_7.json diff --git a/sdk/example/stocks2/data/stock_data_8.json b/sdk/example/old/stocks/data/stock_data_8.json similarity index 100% rename from sdk/example/stocks2/data/stock_data_8.json rename to sdk/example/old/stocks/data/stock_data_8.json diff --git a/sdk/example/stocks2/data/stock_data_9.json b/sdk/example/old/stocks/data/stock_data_9.json similarity index 100% rename from sdk/example/stocks2/data/stock_data_9.json rename to sdk/example/old/stocks/data/stock_data_9.json diff --git a/sdk/example/stocks/lib/stock_app.dart b/sdk/example/old/stocks/lib/stock_app.dart similarity index 100% rename from sdk/example/stocks/lib/stock_app.dart rename to sdk/example/old/stocks/lib/stock_app.dart diff --git a/sdk/example/old/stocks/lib/stock_arrow.dart b/sdk/example/old/stocks/lib/stock_arrow.dart new file mode 100644 index 00000000000..5395984f25c --- /dev/null +++ b/sdk/example/old/stocks/lib/stock_arrow.dart @@ -0,0 +1,93 @@ +// 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:math'; +import 'package:sky/framework/fn.dart'; +import 'package:sky/framework/layout.dart'; + +class StockArrow extends Component { + static final Style _style = new Style(''' + width: 40px; + height: 40px; + align-items: center; + justify-content: center; + border-radius: 40px; + margin-right: 16px; + border: 1px solid transparent;''' + ); + + static final Style _upStyle = new Style(''' + width: 0; + height: 0; + border-left: 9px solid transparent; + border-right: 9px solid transparent; + margin-bottom: 3px; + border-bottom: 9px solid white;''' + ); + + static final Style _downStyle = new Style(''' + width: 0; + height: 0; + border-left: 9px solid transparent; + border-right: 9px solid transparent; + margin-top: 3px; + border-top: 9px solid white''' + ); + + double percentChange; + + StockArrow({ Object key, this.percentChange }) : super(key: key); + + // TODO(abarth): These should use sky/framework/theme/colors.dart. + final List _kRedColors = [ + '#E57373', + '#EF5350', + '#F44336', + '#E53935', + '#D32F2F', + '#C62828', + '#B71C1C', + ]; + + // TODO(abarth): These should use sky/framework/theme/colors.dart. + final List _kGreenColors = [ + '#81C784', + '#66BB6A', + '#4CAF50', + '#43A047', + '#388E3C', + '#2E7D32', + '#1B5E20', + ]; + + int _colorIndexForPercentChange(double percentChange) { + // Currently the max is 10%. + double maxPercent = 10.0; + return max(0, ((percentChange.abs() / maxPercent) * _kGreenColors.length).floor()); + } + + String _colorForPercentChange(double percentChange) { + if (percentChange > 0) + return _kGreenColors[_colorIndexForPercentChange(percentChange)]; + return _kRedColors[_colorIndexForPercentChange(percentChange)]; + } + + UINode build() { + String border = _colorForPercentChange(percentChange).toString(); + bool up = percentChange > 0; + String type = up ? 'bottom' : 'top'; + + return new FlexContainer( + inlineStyle: 'border-color: $border', + direction: FlexDirection.Row, + style: _style, + children: [ + new Container( + inlineStyle: 'border-$type-color: $border', + style: up ? _upStyle : _downStyle + ) + ] + ); + } +} diff --git a/sdk/example/stocks2/lib/stock_data.dart b/sdk/example/old/stocks/lib/stock_data.dart similarity index 95% rename from sdk/example/stocks2/lib/stock_data.dart rename to sdk/example/old/stocks/lib/stock_data.dart index 075add26757..39201714fcb 100644 --- a/sdk/example/stocks2/lib/stock_data.dart +++ b/sdk/example/old/stocks/lib/stock_data.dart @@ -4,7 +4,6 @@ import 'dart:convert'; import 'dart:math'; - import 'package:sky/framework/net/fetch.dart'; // Snapshot from http://www.nasdaq.com/screening/company-list.aspx @@ -60,7 +59,7 @@ class StockDataFetcher { } void _fetchNextChunk() { - fetchBody('../data/stock_data_${_currentChunk++}.json').then((Response response) { + fetchBody('data/stock_data_${_currentChunk++}.json').then((Response response) { String json = response.bodyAsString(); JsonDecoder decoder = new JsonDecoder(); diff --git a/sdk/example/stocks2/lib/stock_list.dart b/sdk/example/old/stocks/lib/stock_list.dart similarity index 66% rename from sdk/example/stocks2/lib/stock_list.dart rename to sdk/example/old/stocks/lib/stock_list.dart index 4b36783d186..c0fbe44ee07 100644 --- a/sdk/example/stocks2/lib/stock_list.dart +++ b/sdk/example/old/stocks/lib/stock_list.dart @@ -2,30 +2,22 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import 'package:sky/widgets/fixed_height_scrollable.dart'; -import 'package:sky/widgets/basic.dart'; - +import 'package:sky/framework/components/fixed_height_scrollable.dart'; +import 'package:sky/framework/fn.dart'; import 'stock_data.dart'; import 'stock_row.dart'; class Stocklist extends FixedHeightScrollable { - - Stocklist({ - String key, - this.stocks, - this.query - }) : super(itemHeight: StockRow.kHeight, key: key); - String query; List stocks; - void syncFields(Stocklist source) { - query = source.query; - stocks = source.stocks; - super.syncFields(source); - } + Stocklist({ + Object key, + this.stocks, + this.query + }) : super(key: key); - List buildItems(int start, int count) { + List buildItems(int start, int count) { var filteredStocks = stocks.where((stock) { return query == null || stock.symbol.contains(new RegExp(query, caseSensitive: false)); diff --git a/sdk/example/old/stocks/lib/stock_menu.dart b/sdk/example/old/stocks/lib/stock_menu.dart new file mode 100644 index 00000000000..33d19831685 --- /dev/null +++ b/sdk/example/old/stocks/lib/stock_menu.dart @@ -0,0 +1,44 @@ +// 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'; +import 'package:sky/framework/layout.dart'; +import 'package:sky/framework/components/popup_menu.dart'; +import 'package:sky/framework/components/checkbox.dart'; +import 'package:sky/framework/theme/view_configuration.dart'; + +class StockMenu extends Component { + static final Style _style = new Style(''' + position: absolute; + right: 8px; + top: ${8 + kStatusBarHeight}px;'''); + + PopupMenuController controller; + + StockMenu({Object key, this.controller, this.autorefresh: false, this.onAutorefreshChanged}) : super(key: key); + + final bool autorefresh; + final ValueChanged onAutorefreshChanged; + + static FlexBoxParentData _flex1 = new FlexBoxParentData()..flex = 1; + + UINode build() { + var checkbox = new Checkbox( + checked: this.autorefresh, + onChanged: this.onAutorefreshChanged + ); + + return new StyleNode( + new PopupMenu( + controller: controller, + items: [ + [new Text('Add stock')], + [new Text('Remove stock')], + [new ParentDataNode(new Text('Autorefresh'), _flex1), checkbox], + ], + level: 4), + _style + ); + } +} diff --git a/sdk/example/old/stocks/lib/stock_row.dart b/sdk/example/old/stocks/lib/stock_row.dart new file mode 100644 index 00000000000..a0ef8bcf297 --- /dev/null +++ b/sdk/example/old/stocks/lib/stock_row.dart @@ -0,0 +1,72 @@ +// 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/components/ink_well.dart'; +import 'package:sky/framework/fn.dart'; +import 'package:sky/framework/layout.dart'; +import 'package:sky/framework/theme/typography.dart' as typography; +import 'stock_arrow.dart'; +import 'stock_data.dart'; + +class StockRow extends Component { + static final Style _style = new Style(''' + align-items: center; + border-bottom: 1px solid #F4F4F4; + padding-top: 16px; + padding-left: 16px; + padding-right: 16px; + padding-bottom: 20px;''' + ); + + static final FlexBoxParentData _tickerFlex = new FlexBoxParentData()..flex = 1; + + static final Style _lastSaleStyle = new Style(''' + text-align: right; + padding-right: 16px;''' + ); + + static final Style _changeStyle = new Style(''' + ${typography.black.caption}; + text-align: right;''' + ); + + Stock stock; + + StockRow({Stock stock}) : super(key: stock.symbol) { + this.stock = stock; + } + + UINode build() { + String lastSale = "\$${stock.lastSale.toStringAsFixed(2)}"; + + String changeInPrice = "${stock.percentChange.toStringAsFixed(2)}%"; + if (stock.percentChange > 0) + changeInPrice = "+" + changeInPrice; + + List children = [ + new StockArrow( + percentChange: stock.percentChange + ), + new ParentDataNode( + new Container( + key: 'Ticker', + children: [new Text(stock.symbol)] + ), + _tickerFlex + ), + new Container( + key: 'LastSale', + style: _lastSaleStyle, + children: [new Text(lastSale)] + ), + new Container( + key: 'Change', + style: _changeStyle, + children: [new Text(changeInPrice)] + ) + ]; + + return new StyleNode(new InkWell(children: children), _style); + } +} diff --git a/sdk/example/stocks/main.sky b/sdk/example/old/stocks/main.sky similarity index 100% rename from sdk/example/stocks/main.sky rename to sdk/example/old/stocks/main.sky diff --git a/sdk/example/stocks2/pubspec.yaml b/sdk/example/old/stocks/pubspec.yaml similarity index 90% rename from sdk/example/stocks2/pubspec.yaml rename to sdk/example/old/stocks/pubspec.yaml index d946687866c..06ec3dfe17c 100644 --- a/sdk/example/stocks2/pubspec.yaml +++ b/sdk/example/old/stocks/pubspec.yaml @@ -4,4 +4,4 @@ description: A demo application using Sky that shows stock data homepage: https://github.com/domokit/sky_sdk/tree/master/sdk/lib/example/stocks version: 0.0.1 dependencies: - sky: '>=0.0.10 <1.0.0' + sky: '>=0.0.1 <1.0.0' diff --git a/sdk/example/raw/launcher.dart b/sdk/example/raw/launcher.dart deleted file mode 100644 index 96dfc39bfef..00000000000 --- a/sdk/example/raw/launcher.dart +++ /dev/null @@ -1,57 +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:math"; -import 'dart:sky'; - -import 'package:sky/framework/shell.dart' as shell; -import 'package:mojom/intents/intents.mojom.dart'; - -Picture draw(int a, int r, int g, int b) { - Size size = new Size(view.width, view.height); - - PictureRecorder recorder = new PictureRecorder(); - Canvas canvas = new Canvas(recorder, size); - double radius = size.shortestSide * 0.45; - - Paint paint = new Paint()..color = new Color.fromARGB(a, r, g, b); - canvas.drawRect(new Rect.fromSize(size), paint); - return recorder.endRecording(); -} - -bool handleEvent(Event event) { - if (event.type == "pointerdown") { - view.picture = draw(255, 0, 0, 255); - view.scheduleFrame(); - return true; - } - - if (event.type == "pointerup") { - view.picture = draw(255, 255, 255, 0); - view.scheduleFrame(); - - ActivityManagerProxy activityManager = new ActivityManagerProxy.unbound(); - Intent intent = new Intent() - ..action = 'android.intent.action.VIEW' - ..url = 'sky://localhost:9888/sky/sdk/lib/example/raw/hello_world.dart'; - shell.requestService(null, activityManager); - activityManager.ptr.startActivity(intent); - return true; - } - - if (event.type == "back") { - print("Pressed back button."); - return true; - } - - return false; -} - -void main() { - print("Hello, world"); - view.picture = draw(255, 255, 255, 0); - view.scheduleFrame(); - - view.setEventCallback(handleEvent); -} diff --git a/sdk/example/rendering/interactive_flex.dart b/sdk/example/rendering/interactive_flex.dart index 0868ffc0ba9..7fd1d50125c 100644 --- a/sdk/example/rendering/interactive_flex.dart +++ b/sdk/example/rendering/interactive_flex.dart @@ -14,7 +14,7 @@ import 'package:sky/rendering/object.dart'; import 'package:sky/rendering/paragraph.dart'; import 'package:sky/rendering/sky_binding.dart'; -import '../lib/solid_color_box.dart'; +import 'solid_color_box.dart'; class Touch { final double x; diff --git a/sdk/example/rendering/justify_content.dart b/sdk/example/rendering/justify_content.dart index 68001009524..768b9a8b125 100644 --- a/sdk/example/rendering/justify_content.dart +++ b/sdk/example/rendering/justify_content.dart @@ -12,7 +12,7 @@ import 'package:sky/rendering/object.dart'; import 'package:sky/rendering/paragraph.dart'; import 'package:sky/rendering/sky_binding.dart'; -import '../lib/solid_color_box.dart'; +import 'solid_color_box.dart'; // Attempts to draw // http://www.w3.org/TR/2015/WD-css-flexbox-1-20150514/images/flex-pack.svg diff --git a/sdk/example/rendering/render_paragraph.dart b/sdk/example/rendering/render_paragraph.dart index 29252b412e3..4d96887504c 100644 --- a/sdk/example/rendering/render_paragraph.dart +++ b/sdk/example/rendering/render_paragraph.dart @@ -11,7 +11,7 @@ import 'package:sky/rendering/object.dart'; import 'package:sky/rendering/paragraph.dart'; import 'package:sky/rendering/sky_binding.dart'; -import '../lib/solid_color_box.dart'; +import 'solid_color_box.dart'; void main() { RenderFlex flexRoot = new RenderFlex(direction: FlexDirection.vertical); diff --git a/sdk/example/lib/solid_color_box.dart b/sdk/example/rendering/solid_color_box.dart similarity index 100% rename from sdk/example/lib/solid_color_box.dart rename to sdk/example/rendering/solid_color_box.dart diff --git a/sdk/example/rendering/spinning_flex.dart b/sdk/example/rendering/spinning_flex.dart index 3e1d5504648..67b404b6321 100644 --- a/sdk/example/rendering/spinning_flex.dart +++ b/sdk/example/rendering/spinning_flex.dart @@ -11,7 +11,7 @@ import 'package:sky/rendering/flex.dart'; import 'package:sky/rendering/sky_binding.dart'; import 'package:vector_math/vector_math.dart'; -import '../lib/solid_color_box.dart'; +import 'solid_color_box.dart'; double timeBase; RenderTransform transformBox; diff --git a/sdk/example/stocks2/lib/stock_app.dart b/sdk/example/stocks/lib/main.dart similarity index 100% rename from sdk/example/stocks2/lib/stock_app.dart rename to sdk/example/stocks/lib/main.dart diff --git a/sdk/example/stocks/lib/stock_arrow.dart b/sdk/example/stocks/lib/stock_arrow.dart index 5395984f25c..95da3307423 100644 --- a/sdk/example/stocks/lib/stock_arrow.dart +++ b/sdk/example/stocks/lib/stock_arrow.dart @@ -2,92 +2,74 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import 'dart:math'; -import 'package:sky/framework/fn.dart'; -import 'package:sky/framework/layout.dart'; +import 'dart:math' as math; +import 'dart:sky' as sky; + +import 'package:sky/rendering/box.dart'; +import 'package:sky/rendering/object.dart'; +import 'package:sky/theme/colors.dart' as colors; +import 'package:sky/widgets/basic.dart'; class StockArrow extends Component { - static final Style _style = new Style(''' - width: 40px; - height: 40px; - align-items: center; - justify-content: center; - border-radius: 40px; - margin-right: 16px; - border: 1px solid transparent;''' - ); - static final Style _upStyle = new Style(''' - width: 0; - height: 0; - border-left: 9px solid transparent; - border-right: 9px solid transparent; - margin-bottom: 3px; - border-bottom: 9px solid white;''' - ); + StockArrow({ String key, this.percentChange }) : super(key: key); - static final Style _downStyle = new Style(''' - width: 0; - height: 0; - border-left: 9px solid transparent; - border-right: 9px solid transparent; - margin-top: 3px; - border-top: 9px solid white''' - ); - - double percentChange; - - StockArrow({ Object key, this.percentChange }) : super(key: key); - - // TODO(abarth): These should use sky/framework/theme/colors.dart. - final List _kRedColors = [ - '#E57373', - '#EF5350', - '#F44336', - '#E53935', - '#D32F2F', - '#C62828', - '#B71C1C', - ]; - - // TODO(abarth): These should use sky/framework/theme/colors.dart. - final List _kGreenColors = [ - '#81C784', - '#66BB6A', - '#4CAF50', - '#43A047', - '#388E3C', - '#2E7D32', - '#1B5E20', - ]; + final double percentChange; int _colorIndexForPercentChange(double percentChange) { - // Currently the max is 10%. double maxPercent = 10.0; - return max(0, ((percentChange.abs() / maxPercent) * _kGreenColors.length).floor()); + double normalizedPercentChange = math.min(percentChange.abs(), maxPercent) / maxPercent; + return 100 + (normalizedPercentChange * 8.0).floor() * 100; } - String _colorForPercentChange(double percentChange) { + Color _colorForPercentChange(double percentChange) { if (percentChange > 0) - return _kGreenColors[_colorIndexForPercentChange(percentChange)]; - return _kRedColors[_colorIndexForPercentChange(percentChange)]; + return colors.Green[_colorIndexForPercentChange(percentChange)]; + return colors.Red[_colorIndexForPercentChange(percentChange)]; } - UINode build() { - String border = _colorForPercentChange(percentChange).toString(); - bool up = percentChange > 0; - String type = up ? 'bottom' : 'top'; + Widget build() { + // TODO(jackson): This should change colors with the theme + Color color = _colorForPercentChange(percentChange); + const double kSize = 40.0; + var arrow = new CustomPaint(callback: (sky.Canvas canvas, Size size) { + Paint paint = new Paint()..color = color; + paint.strokeWidth = 1.0; + const double padding = 2.0; + assert(padding > paint.strokeWidth / 2.0); // make sure the circle remains inside the box + double r = (kSize - padding) / 2.0; // radius of the circle + double centerX = padding + r; + double centerY = padding + r; - return new FlexContainer( - inlineStyle: 'border-color: $border', - direction: FlexDirection.Row, - style: _style, - children: [ - new Container( - inlineStyle: 'border-$type-color: $border', - style: up ? _upStyle : _downStyle - ) - ] + // Draw the arrow. + double w = 8.0; + double h = 5.0; + double arrowY; + if (percentChange < 0.0) { + h = -h; + arrowY = centerX + 1.0; + } else { + arrowY = centerX - 1.0; + } + Path path = new Path(); + path.moveTo(centerX, arrowY - h); // top of the arrow + path.lineTo(centerX + w, arrowY + h); + path.lineTo(centerX - w, arrowY + h); + path.close(); + paint.setStyle(sky.PaintingStyle.fill); + canvas.drawPath(path, paint); + + // Draw a circle that circumscribes the arrow. + paint.setStyle(sky.PaintingStyle.stroke); + canvas.drawCircle(new Point(centerX, centerY), r, paint); + }); + + return new Container( + child: arrow, + width: kSize, + height: kSize, + margin: const EdgeDims.symmetric(horizontal: 5.0) ); } + } diff --git a/sdk/example/stocks/lib/stock_data.dart b/sdk/example/stocks/lib/stock_data.dart index 39201714fcb..075add26757 100644 --- a/sdk/example/stocks/lib/stock_data.dart +++ b/sdk/example/stocks/lib/stock_data.dart @@ -4,6 +4,7 @@ import 'dart:convert'; import 'dart:math'; + import 'package:sky/framework/net/fetch.dart'; // Snapshot from http://www.nasdaq.com/screening/company-list.aspx @@ -59,7 +60,7 @@ class StockDataFetcher { } void _fetchNextChunk() { - fetchBody('data/stock_data_${_currentChunk++}.json').then((Response response) { + fetchBody('../data/stock_data_${_currentChunk++}.json').then((Response response) { String json = response.bodyAsString(); JsonDecoder decoder = new JsonDecoder(); diff --git a/sdk/example/stocks2/lib/stock_home.dart b/sdk/example/stocks/lib/stock_home.dart similarity index 100% rename from sdk/example/stocks2/lib/stock_home.dart rename to sdk/example/stocks/lib/stock_home.dart diff --git a/sdk/example/stocks/lib/stock_list.dart b/sdk/example/stocks/lib/stock_list.dart index c0fbe44ee07..4b36783d186 100644 --- a/sdk/example/stocks/lib/stock_list.dart +++ b/sdk/example/stocks/lib/stock_list.dart @@ -2,22 +2,30 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import 'package:sky/framework/components/fixed_height_scrollable.dart'; -import 'package:sky/framework/fn.dart'; +import 'package:sky/widgets/fixed_height_scrollable.dart'; +import 'package:sky/widgets/basic.dart'; + import 'stock_data.dart'; import 'stock_row.dart'; class Stocklist extends FixedHeightScrollable { + + Stocklist({ + String key, + this.stocks, + this.query + }) : super(itemHeight: StockRow.kHeight, key: key); + String query; List stocks; - Stocklist({ - Object key, - this.stocks, - this.query - }) : super(key: key); + void syncFields(Stocklist source) { + query = source.query; + stocks = source.stocks; + super.syncFields(source); + } - List buildItems(int start, int count) { + List buildItems(int start, int count) { var filteredStocks = stocks.where((stock) { return query == null || stock.symbol.contains(new RegExp(query, caseSensitive: false)); diff --git a/sdk/example/stocks/lib/stock_menu.dart b/sdk/example/stocks/lib/stock_menu.dart index 33d19831685..3d6450d27a5 100644 --- a/sdk/example/stocks/lib/stock_menu.dart +++ b/sdk/example/stocks/lib/stock_menu.dart @@ -2,43 +2,42 @@ // 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'; -import 'package:sky/framework/layout.dart'; -import 'package:sky/framework/components/popup_menu.dart'; -import 'package:sky/framework/components/checkbox.dart'; +import 'package:sky/widgets/checkbox.dart'; +import 'package:sky/widgets/popup_menu.dart'; +import 'package:sky/widgets/basic.dart'; import 'package:sky/framework/theme/view_configuration.dart'; class StockMenu extends Component { - static final Style _style = new Style(''' - position: absolute; - right: 8px; - top: ${8 + kStatusBarHeight}px;'''); - PopupMenuController controller; - - StockMenu({Object key, this.controller, this.autorefresh: false, this.onAutorefreshChanged}) : super(key: key); + StockMenu({ + String key, + this.controller, + this.autorefresh: false, + this.onAutorefreshChanged + }) : super(key: key); + final PopupMenuController controller; final bool autorefresh; final ValueChanged onAutorefreshChanged; - static FlexBoxParentData _flex1 = new FlexBoxParentData()..flex = 1; - - UINode build() { + Widget build() { var checkbox = new Checkbox( - checked: this.autorefresh, + value: this.autorefresh, onChanged: this.onAutorefreshChanged ); - return new StyleNode( - new PopupMenu( + return new Positioned( + child: new PopupMenu( controller: controller, items: [ - [new Text('Add stock')], - [new Text('Remove stock')], - [new ParentDataNode(new Text('Autorefresh'), _flex1), checkbox], + new Text('Add stock'), + new Text('Remove stock'), + new Flex([new Flexible(child: new Text('Autorefresh')), checkbox]), ], - level: 4), - _style + level: 4 + ), + right: 8.0, + top: 8.0 + kStatusBarHeight ); } } diff --git a/sdk/example/stocks/lib/stock_row.dart b/sdk/example/stocks/lib/stock_row.dart index a0ef8bcf297..c13b66f2c22 100644 --- a/sdk/example/stocks/lib/stock_row.dart +++ b/sdk/example/stocks/lib/stock_row.dart @@ -2,71 +2,62 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import 'package:sky/framework/components/ink_well.dart'; -import 'package:sky/framework/fn.dart'; -import 'package:sky/framework/layout.dart'; -import 'package:sky/framework/theme/typography.dart' as typography; +import 'package:sky/painting/text_style.dart'; +import 'package:sky/rendering/box.dart'; +import 'package:sky/widgets/ink_well.dart'; +import 'package:sky/widgets/basic.dart'; +import 'package:sky/widgets/theme.dart'; + import 'stock_arrow.dart'; import 'stock_data.dart'; class StockRow extends Component { - static final Style _style = new Style(''' - align-items: center; - border-bottom: 1px solid #F4F4F4; - padding-top: 16px; - padding-left: 16px; - padding-right: 16px; - padding-bottom: 20px;''' - ); - static final FlexBoxParentData _tickerFlex = new FlexBoxParentData()..flex = 1; + StockRow({ Stock stock }) : this.stock = stock, super(key: stock.symbol); - static final Style _lastSaleStyle = new Style(''' - text-align: right; - padding-right: 16px;''' - ); + final Stock stock; - static final Style _changeStyle = new Style(''' - ${typography.black.caption}; - text-align: right;''' - ); + static const double kHeight = 79.0; - Stock stock; - - StockRow({Stock stock}) : super(key: stock.symbol) { - this.stock = stock; - } - - UINode build() { + Widget build() { String lastSale = "\$${stock.lastSale.toStringAsFixed(2)}"; String changeInPrice = "${stock.percentChange.toStringAsFixed(2)}%"; - if (stock.percentChange > 0) - changeInPrice = "+" + changeInPrice; + if (stock.percentChange > 0) changeInPrice = "+" + changeInPrice; - List children = [ - new StockArrow( - percentChange: stock.percentChange - ), - new ParentDataNode( - new Container( - key: 'Ticker', - children: [new Text(stock.symbol)] - ), - _tickerFlex - ), + List children = [ new Container( - key: 'LastSale', - style: _lastSaleStyle, - children: [new Text(lastSale)] + child: new StockArrow(percentChange: stock.percentChange), + margin: const EdgeDims.only(right: 5.0) ), - new Container( - key: 'Change', - style: _changeStyle, - children: [new Text(changeInPrice)] + new Flexible( + child: new Text(stock.symbol), + flex: 2 + ), + new Flexible( + child: new Text( + lastSale, + style: const TextStyle(textAlign: TextAlign.right) + ) + ), + new Flexible( + child: new Text( + changeInPrice, + style: Theme.of(this).text.caption.copyWith(textAlign: TextAlign.right) + ) ) ]; - return new StyleNode(new InkWell(children: children), _style); + // TODO(hansmuller): An explicit |height| shouldn't be needed + return new InkWell( + child: new Container( + padding: const EdgeDims(16.0, 16.0, 20.0, 16.0), + height: kHeight, + decoration: const BoxDecoration( + border: const Border( + bottom: const BorderSide(color: const Color(0xFFF4F4F4)))), + child: new Flex(children) + ) + ); } } diff --git a/sdk/example/stocks2/lib/stock_settings.dart b/sdk/example/stocks/lib/stock_settings.dart similarity index 100% rename from sdk/example/stocks2/lib/stock_settings.dart rename to sdk/example/stocks/lib/stock_settings.dart diff --git a/sdk/example/hello_world/hello_world.dart b/sdk/example/stocks/lib/stock_types.dart similarity index 54% rename from sdk/example/hello_world/hello_world.dart rename to sdk/example/stocks/lib/stock_types.dart index e20978844d1..9b031110d7a 100644 --- a/sdk/example/hello_world/hello_world.dart +++ b/sdk/example/stocks/lib/stock_types.dart @@ -2,10 +2,4 @@ // 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!'); - } -} +enum StockMode { optimistic, pessimistic } diff --git a/sdk/example/stocks/pubspec.yaml b/sdk/example/stocks/pubspec.yaml index 06ec3dfe17c..d946687866c 100644 --- a/sdk/example/stocks/pubspec.yaml +++ b/sdk/example/stocks/pubspec.yaml @@ -4,4 +4,4 @@ description: A demo application using Sky that shows stock data homepage: https://github.com/domokit/sky_sdk/tree/master/sdk/lib/example/stocks version: 0.0.1 dependencies: - sky: '>=0.0.1 <1.0.0' + sky: '>=0.0.10 <1.0.0' diff --git a/sdk/example/stocks2/README.md b/sdk/example/stocks2/README.md deleted file mode 100644 index 83f97d0db16..00000000000 --- a/sdk/example/stocks2/README.md +++ /dev/null @@ -1,4 +0,0 @@ -This is a copy of the stocks app... with everything removed. - -The goal is to eventually replace the stocks app with this one, by -adding it back bit by bit as we port it to RenderNode. diff --git a/sdk/example/stocks2/lib/stock_arrow.dart b/sdk/example/stocks2/lib/stock_arrow.dart deleted file mode 100644 index 95da3307423..00000000000 --- a/sdk/example/stocks2/lib/stock_arrow.dart +++ /dev/null @@ -1,75 +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:math' as math; -import 'dart:sky' as sky; - -import 'package:sky/rendering/box.dart'; -import 'package:sky/rendering/object.dart'; -import 'package:sky/theme/colors.dart' as colors; -import 'package:sky/widgets/basic.dart'; - -class StockArrow extends Component { - - StockArrow({ String key, this.percentChange }) : super(key: key); - - final double percentChange; - - int _colorIndexForPercentChange(double percentChange) { - double maxPercent = 10.0; - double normalizedPercentChange = math.min(percentChange.abs(), maxPercent) / maxPercent; - return 100 + (normalizedPercentChange * 8.0).floor() * 100; - } - - Color _colorForPercentChange(double percentChange) { - if (percentChange > 0) - return colors.Green[_colorIndexForPercentChange(percentChange)]; - return colors.Red[_colorIndexForPercentChange(percentChange)]; - } - - Widget build() { - // TODO(jackson): This should change colors with the theme - Color color = _colorForPercentChange(percentChange); - const double kSize = 40.0; - var arrow = new CustomPaint(callback: (sky.Canvas canvas, Size size) { - Paint paint = new Paint()..color = color; - paint.strokeWidth = 1.0; - const double padding = 2.0; - assert(padding > paint.strokeWidth / 2.0); // make sure the circle remains inside the box - double r = (kSize - padding) / 2.0; // radius of the circle - double centerX = padding + r; - double centerY = padding + r; - - // Draw the arrow. - double w = 8.0; - double h = 5.0; - double arrowY; - if (percentChange < 0.0) { - h = -h; - arrowY = centerX + 1.0; - } else { - arrowY = centerX - 1.0; - } - Path path = new Path(); - path.moveTo(centerX, arrowY - h); // top of the arrow - path.lineTo(centerX + w, arrowY + h); - path.lineTo(centerX - w, arrowY + h); - path.close(); - paint.setStyle(sky.PaintingStyle.fill); - canvas.drawPath(path, paint); - - // Draw a circle that circumscribes the arrow. - paint.setStyle(sky.PaintingStyle.stroke); - canvas.drawCircle(new Point(centerX, centerY), r, paint); - }); - - return new Container( - child: arrow, - width: kSize, - height: kSize, - margin: const EdgeDims.symmetric(horizontal: 5.0) - ); - } - -} diff --git a/sdk/example/stocks2/lib/stock_menu.dart b/sdk/example/stocks2/lib/stock_menu.dart deleted file mode 100644 index 3d6450d27a5..00000000000 --- a/sdk/example/stocks2/lib/stock_menu.dart +++ /dev/null @@ -1,43 +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/widgets/checkbox.dart'; -import 'package:sky/widgets/popup_menu.dart'; -import 'package:sky/widgets/basic.dart'; -import 'package:sky/framework/theme/view_configuration.dart'; - -class StockMenu extends Component { - - StockMenu({ - String key, - this.controller, - this.autorefresh: false, - this.onAutorefreshChanged - }) : super(key: key); - - final PopupMenuController controller; - final bool autorefresh; - final ValueChanged onAutorefreshChanged; - - Widget build() { - var checkbox = new Checkbox( - value: this.autorefresh, - onChanged: this.onAutorefreshChanged - ); - - return new Positioned( - child: new PopupMenu( - controller: controller, - items: [ - new Text('Add stock'), - new Text('Remove stock'), - new Flex([new Flexible(child: new Text('Autorefresh')), checkbox]), - ], - level: 4 - ), - right: 8.0, - top: 8.0 + kStatusBarHeight - ); - } -} diff --git a/sdk/example/stocks2/lib/stock_row.dart b/sdk/example/stocks2/lib/stock_row.dart deleted file mode 100644 index c13b66f2c22..00000000000 --- a/sdk/example/stocks2/lib/stock_row.dart +++ /dev/null @@ -1,63 +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/painting/text_style.dart'; -import 'package:sky/rendering/box.dart'; -import 'package:sky/widgets/ink_well.dart'; -import 'package:sky/widgets/basic.dart'; -import 'package:sky/widgets/theme.dart'; - -import 'stock_arrow.dart'; -import 'stock_data.dart'; - -class StockRow extends Component { - - StockRow({ Stock stock }) : this.stock = stock, super(key: stock.symbol); - - final Stock stock; - - static const double kHeight = 79.0; - - Widget build() { - String lastSale = "\$${stock.lastSale.toStringAsFixed(2)}"; - - String changeInPrice = "${stock.percentChange.toStringAsFixed(2)}%"; - if (stock.percentChange > 0) changeInPrice = "+" + changeInPrice; - - List children = [ - new Container( - child: new StockArrow(percentChange: stock.percentChange), - margin: const EdgeDims.only(right: 5.0) - ), - new Flexible( - child: new Text(stock.symbol), - flex: 2 - ), - new Flexible( - child: new Text( - lastSale, - style: const TextStyle(textAlign: TextAlign.right) - ) - ), - new Flexible( - child: new Text( - changeInPrice, - style: Theme.of(this).text.caption.copyWith(textAlign: TextAlign.right) - ) - ) - ]; - - // TODO(hansmuller): An explicit |height| shouldn't be needed - return new InkWell( - child: new Container( - padding: const EdgeDims(16.0, 16.0, 20.0, 16.0), - height: kHeight, - decoration: const BoxDecoration( - border: const Border( - bottom: const BorderSide(color: const Color(0xFFF4F4F4)))), - child: new Flex(children) - ) - ); - } -} diff --git a/sdk/example/stocks2/lib/stock_types.dart b/sdk/example/stocks2/lib/stock_types.dart deleted file mode 100644 index e7f06ff11d1..00000000000 --- a/sdk/example/stocks2/lib/stock_types.dart +++ /dev/null @@ -1 +0,0 @@ -enum StockMode { optimistic, pessimistic } diff --git a/sdk/example/widgets/spinning_mixed.dart b/sdk/example/widgets/spinning_mixed.dart index ffcac6f4b89..f5145894b95 100644 --- a/sdk/example/widgets/spinning_mixed.dart +++ b/sdk/example/widgets/spinning_mixed.dart @@ -13,8 +13,7 @@ import 'package:sky/widgets/raised_button.dart'; import 'package:sky/widgets/widget.dart'; import 'package:vector_math/vector_math.dart'; -import '../lib/solid_color_box.dart'; -import '../../tests/resources/display_list.dart'; +import '../rendering/solid_color_box.dart'; // Solid colour, RenderObject version void addFlexChildSolidColor(RenderFlex parent, sky.Color backgroundColor, { int flex: 0 }) { @@ -61,8 +60,6 @@ Widget builder() { double timeBase; RenderTransform transformBox; -final TestRenderView tester = new TestRenderView(); - void rotate(double timeStamp) { if (timeBase == null) timeBase = timeStamp; diff --git a/sdk/home.dart b/sdk/home.dart index 1d142bab278..9e2733b3b72 100644 --- a/sdk/home.dart +++ b/sdk/home.dart @@ -51,18 +51,13 @@ class SkyDemo extends Component { class SkyHome extends App { Widget build() { List children = [ - new SkyDemo('Stocks App', 'example/stocks2/lib/stock_app.dart'), + new SkyDemo('Stocks App', 'example/stocks/lib/main.dart'), new SkyDemo('Asteroids Game', 'example/game/main.dart'), new SkyDemo('Interactive Flex', 'example/rendering/interactive_flex.dart'), new SkyDemo('Sector Layout', 'example/widgets/sector.dart'), new SkyDemo('Touch Demo', 'example/rendering/touch_demo.dart'), new SkyDemo('Minedigger Game', 'example/mine_digger/lib/main.dart'), - // TODO(eseidel): We could use to separate these groups? - new SkyDemo('Old Stocks App', 'example/stocks/main.sky'), - new SkyDemo('Old Touch Demo', 'example/raw/touch-demo.sky'), - new SkyDemo('Old Spinning Square', 'example/raw/spinning-square.sky'), - new SkyDemo('Licences (Old)', 'LICENSES.sky'), ]; diff --git a/tests/examples/stocks.dart b/tests/examples/stocks.dart index bcc715648c9..4db95d2f005 100644 --- a/tests/examples/stocks.dart +++ b/tests/examples/stocks.dart @@ -6,7 +6,7 @@ import 'dart:async'; import 'package:sky/widgets/widget.dart'; -import '../../sdk/example/stocks2/lib/stock_app.dart'; +import '../../sdk/example/stocks/lib/main.dart'; import '../resources/display_list.dart'; class TestStocksApp extends StocksApp { diff --git a/tools/webkitpy/layout_tests/run_webkit_tests.py b/tools/webkitpy/layout_tests/run_webkit_tests.py index 35d76a00adf..c53ad9b3653 100644 --- a/tools/webkitpy/layout_tests/run_webkit_tests.py +++ b/tools/webkitpy/layout_tests/run_webkit_tests.py @@ -397,7 +397,7 @@ def run_analyzer(port, options, args, logging_stream): sky_tools_dir = os.path.dirname(os.path.dirname(test_dir)) analyzer_path = os.path.join(sky_tools_dir, 'skyanalyzer') src_dir = os.path.dirname(os.path.dirname(sky_tools_dir)) - analyzer_target_path = os.path.join(src_dir, 'sky/sdk/example/stocks2/lib/stock_app.dart') + analyzer_target_path = os.path.join(src_dir, 'sky/sdk/example/stocks/lib/main.dart') analyzer_args = [ analyzer_path, build_dir,