Merge remote-tracking branch 'upstream/master'
@ -6,12 +6,9 @@ group("examples") {
|
|||||||
testonly = true
|
testonly = true
|
||||||
|
|
||||||
deps = [
|
deps = [
|
||||||
"//examples/demo_launcher",
|
|
||||||
"//examples/fitness",
|
"//examples/fitness",
|
||||||
"//examples/game",
|
"//examples/game",
|
||||||
"//examples/mine_digger",
|
"//examples/mine_digger",
|
||||||
"//examples/rendering",
|
|
||||||
"//examples/stocks",
|
"//examples/stocks",
|
||||||
"//examples/widgets",
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -2,15 +2,22 @@ Flutter Examples
|
|||||||
================
|
================
|
||||||
|
|
||||||
This directory contains several examples of using Flutter. Each of these is an
|
This directory contains several examples of using Flutter. Each of these is an
|
||||||
individual Dart application package. If you wish to run them with `sky_tool`
|
individual Dart application package.
|
||||||
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
|
To run a sample with the `flutter` tool, run `pub get` inside its directory,
|
||||||
|
then run `flutter start`. (See the
|
||||||
|
[getting started guide](https://flutter.github.io/getting-started/) to install
|
||||||
|
the `flutter` tool.)
|
||||||
|
|
||||||
|
Available examples include:
|
||||||
|
|
||||||
|
- *Hello, world.* The [hello world app](hello_world) is a basic app that shows
|
||||||
the text "hello, world."
|
the text "hello, world."
|
||||||
|
|
||||||
2. *Stocks.* The [stocks app](stocks) is an example of a typical mobile app
|
- *Stocks.* The [stocks app](stocks) is an example of a typical mobile app
|
||||||
built using Flutter. The app shows a list of all the stocks in the NASDAQ.
|
built using Flutter. The app shows a list of all the stocks in the NASDAQ.
|
||||||
|
|
||||||
3. *Widgets.* The [widgets app](widgets) contains a number of Flutter widgets so
|
- *Widgets.* The [widget apps](widgets) demonstrate a number of Flutter widgets
|
||||||
you can experiment with them in a simple container.
|
so you can experiment with them in a simple container. There is no main.dart
|
||||||
|
in this directory because each file is a standalone sample. To run a
|
||||||
|
particular file, use `flutter start -t filename.dart`.
|
||||||
|
@ -2,8 +2,7 @@
|
|||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
import 'package:sky/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:sky/widgets.dart';
|
|
||||||
|
|
||||||
class Field extends StatelessComponent {
|
class Field extends StatelessComponent {
|
||||||
Field({
|
Field({
|
||||||
@ -95,7 +94,7 @@ final ThemeData theme = new ThemeData(
|
|||||||
);
|
);
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
runApp(new App(
|
runApp(new MaterialApp(
|
||||||
title: 'Address Book',
|
title: 'Address Book',
|
||||||
theme: theme,
|
theme: theme,
|
||||||
routes: <String, RouteBuilder>{
|
routes: <String, RouteBuilder>{
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
name: address_book
|
name: address_book
|
||||||
dependencies:
|
dependencies:
|
||||||
sky: any
|
flutter: ">=0.0.3 <0.1.0"
|
||||||
sky_tools: any
|
sky_tools: any
|
||||||
dependency_overrides:
|
dependency_overrides:
|
||||||
material_design_icons:
|
material_design_icons:
|
||||||
path: ../../sky/packages/material_design_icons
|
path: ../../sky/packages/material_design_icons
|
||||||
sky:
|
flutter:
|
||||||
path: ../../sky/packages/sky
|
path: ../../sky/packages/sky
|
||||||
|
@ -1,28 +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("//sky/build/sky_app.gni")
|
|
||||||
|
|
||||||
sky_app("demo_launcher") {
|
|
||||||
main_dart = "lib/main.dart"
|
|
||||||
manifest = "sky.yaml"
|
|
||||||
|
|
||||||
if (is_android) {
|
|
||||||
apk_name = "SkyDemo"
|
|
||||||
|
|
||||||
bundles = [
|
|
||||||
"//examples/fitness",
|
|
||||||
"//examples/game",
|
|
||||||
"//examples/mine_digger",
|
|
||||||
"//examples/rendering:interactive_flex",
|
|
||||||
"//examples/stocks",
|
|
||||||
"//examples/widgets:cards",
|
|
||||||
]
|
|
||||||
|
|
||||||
deps = [
|
|
||||||
"//examples/demo_launcher/apk:java",
|
|
||||||
"//examples/demo_launcher/apk:resources",
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,20 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<!-- 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.
|
|
||||||
-->
|
|
||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="org.domokit.sky.demo" android:versionCode="24" android:versionName="0.0.24">
|
|
||||||
|
|
||||||
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="21" />
|
|
||||||
<uses-permission android:name="android.permission.INTERNET" />
|
|
||||||
<uses-feature android:name="android.hardware.sensor.accelerometer" android:required="true" />
|
|
||||||
|
|
||||||
<application android:icon="@mipmap/ic_launcher" android:label="Sky" android:name="SkyDemoApplication">
|
|
||||||
<activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize" android:documentLaunchMode="always" android:hardwareAccelerated="true" android:launchMode="standard" android:name="SkyDemoActivity" android:theme="@android:style/Theme.Black.NoTitleBar">
|
|
||||||
<intent-filter>
|
|
||||||
<action android:name="android.intent.action.MAIN" />
|
|
||||||
<category android:name="android.intent.category.LAUNCHER" />
|
|
||||||
</intent-filter>
|
|
||||||
</activity>
|
|
||||||
</application>
|
|
||||||
</manifest>
|
|
@ -1,27 +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.
|
|
||||||
|
|
||||||
assert(is_android)
|
|
||||||
|
|
||||||
import("//build/config/android/config.gni")
|
|
||||||
import("//build/config/android/rules.gni")
|
|
||||||
|
|
||||||
android_library("java") {
|
|
||||||
java_files = [
|
|
||||||
"org/domokit/sky/demo/SkyDemoActivity.java",
|
|
||||||
"org/domokit/sky/demo/SkyDemoApplication.java",
|
|
||||||
]
|
|
||||||
|
|
||||||
deps = [
|
|
||||||
"//base:base_java",
|
|
||||||
"//mojo/public/java:bindings",
|
|
||||||
"//mojo/public/java:system",
|
|
||||||
"//sky/shell:java",
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
android_resources("resources") {
|
|
||||||
resource_dirs = [ "res" ]
|
|
||||||
android_manifest = "AndroidManifest.xml"
|
|
||||||
}
|
|
@ -1,8 +0,0 @@
|
|||||||
Icon image comes from:
|
|
||||||
https://openclipart.org/detail/30073/tango%20weather%20few%20clouds
|
|
||||||
and is public domain.
|
|
||||||
|
|
||||||
Icon resources were generated using:
|
|
||||||
http://romannurik.github.io/AndroidAssetStudio/icons-launcher.html
|
|
||||||
which produces art under CC 3.0:
|
|
||||||
http://creativecommons.org/licenses/by/3.0/
|
|
@ -1,31 +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.
|
|
||||||
|
|
||||||
package org.domokit.sky.demo;
|
|
||||||
|
|
||||||
import android.content.Intent;
|
|
||||||
|
|
||||||
import org.domokit.sky.shell.SkyActivity;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Main activity for SkyDemo.
|
|
||||||
*/
|
|
||||||
public class SkyDemoActivity extends SkyActivity {
|
|
||||||
@Override
|
|
||||||
protected void onSkyReady() {
|
|
||||||
Intent intent = getIntent();
|
|
||||||
String action = intent.getAction();
|
|
||||||
|
|
||||||
if (Intent.ACTION_VIEW.equals(action)) {
|
|
||||||
String bundleName = intent.getStringExtra("bundleName");
|
|
||||||
if (bundleName != null && loadBundleByName(bundleName)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
loadUrl(intent.getDataString());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
super.onSkyReady();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,30 +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.
|
|
||||||
|
|
||||||
package org.domokit.sky.demo;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
|
|
||||||
import org.domokit.sky.shell.ResourceExtractor;
|
|
||||||
import org.domokit.sky.shell.SkyApplication;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* SkyDemo implementation of {@link android.app.Application}
|
|
||||||
*/
|
|
||||||
public class SkyDemoApplication extends SkyApplication {
|
|
||||||
private static final String[] DEMO_RESOURCES = {
|
|
||||||
"cards.skyx",
|
|
||||||
"fitness.skyx",
|
|
||||||
"game.skyx",
|
|
||||||
"interactive_flex.skyx",
|
|
||||||
"mine_digger.skyx",
|
|
||||||
"stocks.skyx",
|
|
||||||
};
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onBeforeResourceExtraction(ResourceExtractor extractor) {
|
|
||||||
super.onBeforeResourceExtraction(extractor);
|
|
||||||
extractor.addResources(DEMO_RESOURCES);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1 +0,0 @@
|
|||||||
First version published to production from our service account.
|
|
@ -1,7 +0,0 @@
|
|||||||
Fixed a common startup crasher on Android systems before 5.0
|
|
||||||
Fixed to not draw behind the status bar on before Android 5.0
|
|
||||||
First release from new http://github.com/domokit/sky_engine repository.
|
|
||||||
|
|
||||||
I suspect there may still be some crashes we will be fixing
|
|
||||||
in the coming days as we set up systems to catch these crashes
|
|
||||||
before they are shipped to users.
|
|
@ -1 +0,0 @@
|
|||||||
Fixes crash on Nexus 6
|
|
@ -1,3 +0,0 @@
|
|||||||
Huge speed improvements in Asteroids.
|
|
||||||
Fixed startup crash on many devices.
|
|
||||||
Lots of various other widget fixes.
|
|
@ -1,2 +0,0 @@
|
|||||||
- No longer crashes on Android M Developer Preview
|
|
||||||
- 3x scrolling speed improvement.
|
|
@ -1,3 +0,0 @@
|
|||||||
Small updates for various demos
|
|
||||||
Asteroids has sounds, Fitness has charting, etc.
|
|
||||||
This app is slowly being replaced by publishing individual apps.
|
|
@ -1 +0,0 @@
|
|||||||
Minor updates to various demos including game.
|
|
Before Width: | Height: | Size: 6.1 KiB |
Before Width: | Height: | Size: 3.3 KiB |
Before Width: | Height: | Size: 9.3 KiB |
Before Width: | Height: | Size: 17 KiB |
Before Width: | Height: | Size: 26 KiB |
Before Width: | Height: | Size: 280 KiB |
Before Width: | Height: | Size: 24 KiB |
Before Width: | Height: | Size: 56 KiB |
@ -1,212 +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/material.dart';
|
|
||||||
import 'package:sky/painting.dart';
|
|
||||||
import 'package:sky/services.dart';
|
|
||||||
import 'package:sky/widgets.dart';
|
|
||||||
|
|
||||||
AssetBundle _initBundle() {
|
|
||||||
if (rootBundle != null)
|
|
||||||
return rootBundle;
|
|
||||||
const String _kAssetBase = '..';
|
|
||||||
return new NetworkAssetBundle(Uri.base.resolve(_kAssetBase));
|
|
||||||
}
|
|
||||||
|
|
||||||
final AssetBundle _bundle = _initBundle();
|
|
||||||
|
|
||||||
void launch(String relativeUrl, String bundle) {
|
|
||||||
// TODO(eseidel): This is a hack to keep non-skyx examples working for now:
|
|
||||||
Uri productionBase = Uri.parse(
|
|
||||||
'https://domokit.github.io/example/demo_launcher/lib/main.dart');
|
|
||||||
Uri base = rootBundle == null ? Uri.base : productionBase;
|
|
||||||
Uri url = base.resolve(relativeUrl);
|
|
||||||
|
|
||||||
ComponentName component = new ComponentName()
|
|
||||||
..packageName = 'org.domokit.sky.demo'
|
|
||||||
..className = 'org.domokit.sky.demo.SkyDemoActivity';
|
|
||||||
Intent intent = new Intent()
|
|
||||||
..action = 'android.intent.action.VIEW'
|
|
||||||
..component = component
|
|
||||||
..flags = MULTIPLE_TASK | NEW_DOCUMENT
|
|
||||||
..url = url.toString();
|
|
||||||
|
|
||||||
if (bundle != null) {
|
|
||||||
StringExtra extra = new StringExtra()
|
|
||||||
..name = 'bundleName'
|
|
||||||
..value = bundle;
|
|
||||||
intent.stringExtras = [extra];
|
|
||||||
}
|
|
||||||
|
|
||||||
activity.startActivity(intent);
|
|
||||||
}
|
|
||||||
|
|
||||||
class FlutterDemo {
|
|
||||||
FlutterDemo({
|
|
||||||
name,
|
|
||||||
this.href,
|
|
||||||
this.bundle,
|
|
||||||
this.description,
|
|
||||||
this.textTheme,
|
|
||||||
this.decoration
|
|
||||||
}) : name = name, key = new Key(name);
|
|
||||||
final String name;
|
|
||||||
final Key key;
|
|
||||||
final String href;
|
|
||||||
final String bundle;
|
|
||||||
final String description;
|
|
||||||
final TextTheme textTheme;
|
|
||||||
final BoxDecoration decoration;
|
|
||||||
}
|
|
||||||
|
|
||||||
List<FlutterDemo> demos = [
|
|
||||||
new FlutterDemo(
|
|
||||||
name: 'Stocks',
|
|
||||||
href: '../../stocks/lib/main.dart',
|
|
||||||
bundle: 'stocks.skyx',
|
|
||||||
description: 'Multi-screen app with scrolling list',
|
|
||||||
textTheme: Typography.black,
|
|
||||||
decoration: new BoxDecoration(
|
|
||||||
backgroundImage: new BackgroundImage(
|
|
||||||
image: _bundle.loadImage('assets/stocks_thumbnail.png'),
|
|
||||||
fit: ImageFit.cover
|
|
||||||
)
|
|
||||||
)
|
|
||||||
),
|
|
||||||
new FlutterDemo(
|
|
||||||
name: 'Asteroids',
|
|
||||||
href: '../../game/lib/main.dart',
|
|
||||||
bundle: 'game.skyx',
|
|
||||||
description: '2D game using sprite sheets',
|
|
||||||
textTheme: Typography.white,
|
|
||||||
decoration: new BoxDecoration(
|
|
||||||
backgroundImage: new BackgroundImage(
|
|
||||||
image: _bundle.loadImage('assets/game_thumbnail.png'),
|
|
||||||
fit: ImageFit.cover
|
|
||||||
)
|
|
||||||
)
|
|
||||||
),
|
|
||||||
new FlutterDemo(
|
|
||||||
name: 'Fitness',
|
|
||||||
href: '../../fitness/lib/main.dart',
|
|
||||||
bundle: 'fitness.skyx',
|
|
||||||
description: 'Track progress towards healthy goals',
|
|
||||||
textTheme: Typography.white,
|
|
||||||
decoration: new BoxDecoration(
|
|
||||||
backgroundColor: Colors.indigo[500]
|
|
||||||
)
|
|
||||||
),
|
|
||||||
new FlutterDemo(
|
|
||||||
name: 'Swipe Away',
|
|
||||||
href: '../../widgets/card_collection.dart',
|
|
||||||
bundle: 'cards.skyx',
|
|
||||||
description: 'Infinite list of swipeable cards',
|
|
||||||
textTheme: Typography.white,
|
|
||||||
decoration: new BoxDecoration(
|
|
||||||
backgroundColor: Colors.redAccent[200]
|
|
||||||
)
|
|
||||||
),
|
|
||||||
new FlutterDemo(
|
|
||||||
name: 'Interactive Text',
|
|
||||||
href: '../../rendering/interactive_flex.dart',
|
|
||||||
bundle: 'interactive_flex.skyx',
|
|
||||||
description: 'Swipe to reflow the app',
|
|
||||||
textTheme: Typography.white,
|
|
||||||
decoration: new BoxDecoration(
|
|
||||||
backgroundColor: const Color(0xFF0081C6)
|
|
||||||
)
|
|
||||||
),
|
|
||||||
// new SkyDemo(
|
|
||||||
|
|
||||||
// 'Touch Demo', '../../rendering/touch_demo.dart', 'Simple example showing handling of touch events at a low level'),
|
|
||||||
new FlutterDemo(
|
|
||||||
name: 'Minedigger Game',
|
|
||||||
href: '../../mine_digger/lib/main.dart',
|
|
||||||
bundle: 'mine_digger.skyx',
|
|
||||||
description: 'Clone of the classic Minesweeper game',
|
|
||||||
textTheme: Typography.white,
|
|
||||||
decoration: new BoxDecoration(
|
|
||||||
backgroundColor: Colors.black
|
|
||||||
)
|
|
||||||
),
|
|
||||||
|
|
||||||
// TODO(jackson): This doesn't seem to be working
|
|
||||||
// new SkyDemo('Licenses', 'LICENSES.sky'),
|
|
||||||
];
|
|
||||||
|
|
||||||
const double kCardHeight = 120.0;
|
|
||||||
const EdgeDims kListPadding = const EdgeDims.all(4.0);
|
|
||||||
|
|
||||||
class DemoCard extends StatelessComponent {
|
|
||||||
DemoCard({ Key key, this.demo }) : super(key: key);
|
|
||||||
|
|
||||||
final FlutterDemo demo;
|
|
||||||
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return new Container(
|
|
||||||
height: kCardHeight,
|
|
||||||
child: new Card(
|
|
||||||
child: new Container(
|
|
||||||
decoration: demo.decoration,
|
|
||||||
child: new InkWell(
|
|
||||||
onTap: () => launch(demo.href, demo.bundle),
|
|
||||||
child: new Container(
|
|
||||||
margin: const EdgeDims.only(top: 24.0, left: 24.0),
|
|
||||||
child: new Column([
|
|
||||||
new Text(demo.name, style: demo.textTheme.title),
|
|
||||||
new Flexible(
|
|
||||||
child: new Text(demo.description, style: demo.textTheme.subhead)
|
|
||||||
)
|
|
||||||
],
|
|
||||||
alignItems: FlexAlignItems.start
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class DemoList extends StatelessComponent {
|
|
||||||
Widget _buildDemoCard(BuildContext context, FlutterDemo demo) {
|
|
||||||
return new DemoCard(key: demo.key, demo: demo);
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return new ScrollableList<FlutterDemo>(
|
|
||||||
items: demos,
|
|
||||||
itemExtent: kCardHeight,
|
|
||||||
itemBuilder: _buildDemoCard,
|
|
||||||
padding: kListPadding
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final ThemeData _theme = new ThemeData(
|
|
||||||
brightness: ThemeBrightness.light,
|
|
||||||
primarySwatch: Colors.teal
|
|
||||||
);
|
|
||||||
|
|
||||||
class DemoHome extends StatelessComponent {
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return new Scaffold(
|
|
||||||
toolBar: new ToolBar(center: new Text('Sky Demos')),
|
|
||||||
body: new Material(
|
|
||||||
type: MaterialType.canvas,
|
|
||||||
child: new DemoList()
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
runApp(new App(
|
|
||||||
title: 'Flutter Demos',
|
|
||||||
theme: _theme,
|
|
||||||
routes: {
|
|
||||||
'/': (RouteArguments args) => new DemoHome()
|
|
||||||
}
|
|
||||||
));
|
|
||||||
}
|
|
@ -1,9 +0,0 @@
|
|||||||
name: demo_launcher
|
|
||||||
dependencies:
|
|
||||||
sky: any
|
|
||||||
sky_tools: any
|
|
||||||
dependency_overrides:
|
|
||||||
material_design_icons:
|
|
||||||
path: ../../sky/packages/material_design_icons
|
|
||||||
sky:
|
|
||||||
path: ../../sky/packages/sky
|
|
@ -1,4 +0,0 @@
|
|||||||
assets:
|
|
||||||
- assets/game_thumbnail.png
|
|
||||||
- assets/sector_thumbnail.png
|
|
||||||
- assets/stocks_thumbnail.png
|
|
@ -15,7 +15,6 @@ class FitnessItemList extends StatelessComponent {
|
|||||||
|
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return new Material(
|
return new Material(
|
||||||
type: MaterialType.canvas,
|
|
||||||
child: new ScrollableList<FitnessItem>(
|
child: new ScrollableList<FitnessItem>(
|
||||||
padding: const EdgeDims.all(4.0),
|
padding: const EdgeDims.all(4.0),
|
||||||
items: items,
|
items: items,
|
||||||
@ -172,10 +171,9 @@ class FeedFragmentState extends State<FeedFragment> {
|
|||||||
Widget buildBody() {
|
Widget buildBody() {
|
||||||
TextStyle style = Theme.of(context).text.title;
|
TextStyle style = Theme.of(context).text.title;
|
||||||
if (config.userData == null)
|
if (config.userData == null)
|
||||||
return new Material(type: MaterialType.canvas);
|
return new Material();
|
||||||
if (config.userData.items.length == 0)
|
if (config.userData.items.length == 0)
|
||||||
return new Material(
|
return new Material(
|
||||||
type: MaterialType.canvas,
|
|
||||||
child: new Row(
|
child: new Row(
|
||||||
[new Text("No data yet.\nAdd some!", style: style)],
|
[new Text("No data yet.\nAdd some!", style: style)],
|
||||||
justifyContent: FlexJustifyContent.center
|
justifyContent: FlexJustifyContent.center
|
||||||
@ -189,7 +187,6 @@ class FeedFragmentState extends State<FeedFragment> {
|
|||||||
);
|
);
|
||||||
case FitnessMode.chart:
|
case FitnessMode.chart:
|
||||||
return new Material(
|
return new Material(
|
||||||
type: MaterialType.canvas,
|
|
||||||
child: new Container(
|
child: new Container(
|
||||||
padding: const EdgeDims.all(20.0),
|
padding: const EdgeDims.all(20.0),
|
||||||
child: buildChart()
|
child: buildChart()
|
||||||
|
@ -5,9 +5,8 @@
|
|||||||
library fitness;
|
library fitness;
|
||||||
|
|
||||||
import 'package:playfair/playfair.dart' as playfair;
|
import 'package:playfair/playfair.dart' as playfair;
|
||||||
import 'package:sky/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:sky/painting.dart';
|
import 'package:flutter/painting.dart';
|
||||||
import 'package:sky/widgets.dart';
|
|
||||||
|
|
||||||
import 'user_data.dart';
|
import 'user_data.dart';
|
||||||
import 'date_utils.dart';
|
import 'date_utils.dart';
|
||||||
@ -126,7 +125,7 @@ class FitnessAppState extends State<FitnessApp> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Widget build(BuildContext) {
|
Widget build(BuildContext) {
|
||||||
return new App(
|
return new MaterialApp(
|
||||||
theme: new ThemeData(
|
theme: new ThemeData(
|
||||||
brightness: ThemeBrightness.light,
|
brightness: ThemeBrightness.light,
|
||||||
primarySwatch: Colors.indigo,
|
primarySwatch: Colors.indigo,
|
||||||
|
@ -86,7 +86,6 @@ class MealFragmentState extends State<MealFragment> {
|
|||||||
Widget buildBody() {
|
Widget buildBody() {
|
||||||
Meal meal = new Meal(when: new DateTime.now());
|
Meal meal = new Meal(when: new DateTime.now());
|
||||||
return new Material(
|
return new Material(
|
||||||
type: MaterialType.canvas,
|
|
||||||
child: new ScrollableViewport(
|
child: new ScrollableViewport(
|
||||||
child: new Container(
|
child: new Container(
|
||||||
padding: const EdgeDims.all(20.0),
|
padding: const EdgeDims.all(20.0),
|
||||||
|
@ -173,7 +173,6 @@ class MeasurementFragmentState extends State<MeasurementFragment> {
|
|||||||
Measurement measurement = new Measurement(when: _when);
|
Measurement measurement = new Measurement(when: _when);
|
||||||
// TODO(jackson): Revisit the layout of this pane to be more maintainable
|
// TODO(jackson): Revisit the layout of this pane to be more maintainable
|
||||||
return new Material(
|
return new Material(
|
||||||
type: MaterialType.canvas,
|
|
||||||
child: new Container(
|
child: new Container(
|
||||||
padding: const EdgeDims.all(20.0),
|
padding: const EdgeDims.all(20.0),
|
||||||
child: new Column([
|
child: new Column([
|
||||||
|
@ -93,7 +93,6 @@ class SettingsFragmentState extends State<SettingsFragment> {
|
|||||||
|
|
||||||
Widget buildSettingsPane(BuildContext context) {
|
Widget buildSettingsPane(BuildContext context) {
|
||||||
return new Material(
|
return new Material(
|
||||||
type: MaterialType.canvas,
|
|
||||||
child: new ScrollableViewport(
|
child: new ScrollableViewport(
|
||||||
child: new Container(
|
child: new Container(
|
||||||
padding: const EdgeDims.symmetric(vertical: 20.0),
|
padding: const EdgeDims.symmetric(vertical: 20.0),
|
||||||
|
@ -9,7 +9,7 @@ import 'dart:async';
|
|||||||
import 'package:path/path.dart' as path;
|
import 'package:path/path.dart' as path;
|
||||||
|
|
||||||
import 'main.dart';
|
import 'main.dart';
|
||||||
import 'package:sky/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
|
|
||||||
String cachedDataFilePath = null;
|
String cachedDataFilePath = null;
|
||||||
|
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
name: fitness
|
name: fitness
|
||||||
dependencies:
|
dependencies:
|
||||||
sky: any
|
flutter: ">=0.0.3 <0.1.0"
|
||||||
sky_tools: any
|
playfair: ^0.0.10
|
||||||
playfair: ^0.0.9
|
|
||||||
path: ^1.3.6
|
path: ^1.3.6
|
||||||
|
sky_tools: any
|
||||||
dependency_overrides:
|
dependency_overrides:
|
||||||
material_design_icons:
|
material_design_icons:
|
||||||
path: ../../sky/packages/material_design_icons
|
path: ../../sky/packages/material_design_icons
|
||||||
sky:
|
flutter:
|
||||||
path: ../../sky/packages/sky
|
path: ../../sky/packages/sky
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import 'package:sky/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:sky/rendering.dart';
|
import 'package:flutter/rendering.dart';
|
||||||
import 'package:sky/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:sky/widgets.dart';
|
import 'package:flutter/widgets.dart';
|
||||||
import 'package:skysprites/skysprites.dart';
|
import 'package:flutter_sprites/flutter_sprites.dart';
|
||||||
|
|
||||||
AssetBundle _initBundle() {
|
AssetBundle _initBundle() {
|
||||||
if (rootBundle != null)
|
if (rootBundle != null)
|
||||||
@ -53,7 +53,7 @@ class TestAppState extends State<TestApp> {
|
|||||||
];
|
];
|
||||||
|
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return new App(
|
return new MaterialApp(
|
||||||
title: 'EffectLine Demo',
|
title: 'EffectLine Demo',
|
||||||
theme: _theme,
|
theme: _theme,
|
||||||
routes: {
|
routes: {
|
||||||
|
@ -49,7 +49,7 @@ class ExplosionBig extends Explosion {
|
|||||||
|
|
||||||
// Add ring
|
// Add ring
|
||||||
Sprite sprtRing = new Sprite(sheet["explosion_ring.png"]);
|
Sprite sprtRing = new Sprite(sheet["explosion_ring.png"]);
|
||||||
sprtRing.transferMode = sky.TransferMode.plus;
|
sprtRing.transferMode = ui.TransferMode.plus;
|
||||||
addChild(sprtRing);
|
addChild(sprtRing);
|
||||||
|
|
||||||
Action scale = new ActionTween( (a) => sprtRing.scale = a, 0.2, 1.0, 0.75);
|
Action scale = new ActionTween( (a) => sprtRing.scale = a, 0.2, 1.0, 0.75);
|
||||||
@ -63,7 +63,7 @@ class ExplosionBig extends Explosion {
|
|||||||
Sprite sprtFlare = new Sprite(sheet["explosion_flare.png"]);
|
Sprite sprtFlare = new Sprite(sheet["explosion_flare.png"]);
|
||||||
sprtFlare.pivot = new Point(0.3, 1.0);
|
sprtFlare.pivot = new Point(0.3, 1.0);
|
||||||
sprtFlare.scaleX = 0.3;
|
sprtFlare.scaleX = 0.3;
|
||||||
sprtFlare.transferMode = sky.TransferMode.plus;
|
sprtFlare.transferMode = ui.TransferMode.plus;
|
||||||
sprtFlare.rotation = randomDouble() * 360.0;
|
sprtFlare.rotation = randomDouble() * 360.0;
|
||||||
addChild(sprtFlare);
|
addChild(sprtFlare);
|
||||||
|
|
||||||
@ -86,7 +86,7 @@ class ExplosionMini extends Explosion {
|
|||||||
Sprite star = new Sprite(sheet["star_0.png"]);
|
Sprite star = new Sprite(sheet["star_0.png"]);
|
||||||
star.scale = 0.5;
|
star.scale = 0.5;
|
||||||
star.colorOverlay = new Color(0xff95f4fb);
|
star.colorOverlay = new Color(0xff95f4fb);
|
||||||
star.transferMode = sky.TransferMode.plus;
|
star.transferMode = ui.TransferMode.plus;
|
||||||
addChild(star);
|
addChild(star);
|
||||||
|
|
||||||
double rotationStart = randomDouble() * 90.0;
|
double rotationStart = randomDouble() * 90.0;
|
||||||
|
@ -2,10 +2,10 @@ library game;
|
|||||||
|
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'dart:math' as math;
|
import 'dart:math' as math;
|
||||||
import 'dart:sky' as sky;
|
import 'dart:ui' as ui;
|
||||||
|
|
||||||
import 'package:sky/rendering.dart';
|
import 'package:flutter/rendering.dart';
|
||||||
import 'package:skysprites/skysprites.dart';
|
import 'package:flutter_sprites/flutter_sprites.dart';
|
||||||
import 'package:vector_math/vector_math_64.dart';
|
import 'package:vector_math/vector_math_64.dart';
|
||||||
|
|
||||||
part 'custom_actions.dart';
|
part 'custom_actions.dart';
|
||||||
|
@ -26,7 +26,7 @@ class GameDemoNode extends NodeWithSize {
|
|||||||
addChild(_starField);
|
addChild(_starField);
|
||||||
|
|
||||||
// Add nebula
|
// Add nebula
|
||||||
_nebula = new RepeatedImage(_images["assets/nebula.png"], sky.TransferMode.plus);
|
_nebula = new RepeatedImage(_images["assets/nebula.png"], ui.TransferMode.plus);
|
||||||
addChild(_nebula);
|
addChild(_nebula);
|
||||||
|
|
||||||
// Setup game screen, it will always be anchored to the bottom of the screen
|
// Setup game screen, it will always be anchored to the bottom of the screen
|
||||||
|
@ -16,7 +16,7 @@ abstract class GameObject extends Node {
|
|||||||
Paint _paintDebug = new Paint()
|
Paint _paintDebug = new Paint()
|
||||||
..color=new Color(0xffff0000)
|
..color=new Color(0xffff0000)
|
||||||
..strokeWidth = 1.0
|
..strokeWidth = 1.0
|
||||||
..setStyle(sky.PaintingStyle.stroke);
|
..setStyle(ui.PaintingStyle.stroke);
|
||||||
|
|
||||||
bool collidingWith(GameObject obj) {
|
bool collidingWith(GameObject obj) {
|
||||||
return (GameMath.distanceBetweenPoints(position, obj.position)
|
return (GameMath.distanceBetweenPoints(position, obj.position)
|
||||||
@ -111,7 +111,7 @@ class Ship extends GameObject {
|
|||||||
|
|
||||||
_sprtShield = new Sprite(f.sheet["shield.png"]);
|
_sprtShield = new Sprite(f.sheet["shield.png"]);
|
||||||
_sprtShield.scale = 0.35;
|
_sprtShield.scale = 0.35;
|
||||||
_sprtShield.transferMode = sky.TransferMode.plus;
|
_sprtShield.transferMode = ui.TransferMode.plus;
|
||||||
addChild(_sprtShield);
|
addChild(_sprtShield);
|
||||||
|
|
||||||
radius = 20.0;
|
radius = 20.0;
|
||||||
@ -188,7 +188,7 @@ class Laser extends GameObject {
|
|||||||
Sprite sprt = new Sprite(f.sheet["explosion_particle.png"]);
|
Sprite sprt = new Sprite(f.sheet["explosion_particle.png"]);
|
||||||
sprt.scale = 0.5;
|
sprt.scale = 0.5;
|
||||||
sprt.colorOverlay = laserColor;
|
sprt.colorOverlay = laserColor;
|
||||||
sprt.transferMode = sky.TransferMode.plus;
|
sprt.transferMode = ui.TransferMode.plus;
|
||||||
addChild(sprt);
|
addChild(sprt);
|
||||||
sprites.add(sprt);
|
sprites.add(sprt);
|
||||||
}
|
}
|
||||||
|
@ -4,12 +4,11 @@
|
|||||||
|
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
|
||||||
import 'package:sky/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:sky/painting.dart';
|
import 'package:flutter/painting.dart';
|
||||||
import 'package:sky/rendering.dart';
|
import 'package:flutter/rendering.dart';
|
||||||
import 'package:sky/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:sky/widgets.dart';
|
import 'package:flutter_sprites/flutter_sprites.dart';
|
||||||
import 'package:skysprites/skysprites.dart';
|
|
||||||
|
|
||||||
import 'game_demo.dart';
|
import 'game_demo.dart';
|
||||||
|
|
||||||
@ -82,7 +81,7 @@ class GameDemoState extends State<GameDemo> {
|
|||||||
int _lastScore = 0;
|
int _lastScore = 0;
|
||||||
|
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return new App(
|
return new MaterialApp(
|
||||||
title: 'Asteroids',
|
title: 'Asteroids',
|
||||||
theme: _theme,
|
theme: _theme,
|
||||||
routes: {
|
routes: {
|
||||||
@ -151,16 +150,18 @@ class TextureButton extends StatefulComponent {
|
|||||||
TextureButtonState createState() => new TextureButtonState();
|
TextureButtonState createState() => new TextureButtonState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class TextureButtonState extends ButtonState<TextureButton> {
|
class TextureButtonState extends State<TextureButton> {
|
||||||
Widget buildContent(BuildContext context) {
|
bool _highlight = false;
|
||||||
return new Listener(
|
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return new GestureDetector(
|
||||||
child: new Container(
|
child: new Container(
|
||||||
width: config.width,
|
width: config.width,
|
||||||
height: config.height,
|
height: config.height,
|
||||||
child: new CustomPaint(
|
child: new CustomPaint(
|
||||||
callback: paintCallback,
|
callback: paintCallback,
|
||||||
token: new _TextureButtonToken(
|
token: new _TextureButtonToken(
|
||||||
highlight,
|
_highlight,
|
||||||
config.texture,
|
config.texture,
|
||||||
config.textureDown,
|
config.textureDown,
|
||||||
config.width,
|
config.width,
|
||||||
@ -168,9 +169,22 @@ class TextureButtonState extends ButtonState<TextureButton> {
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
onPointerUp: (_) {
|
onTapDown: () {
|
||||||
|
setState(() {
|
||||||
|
_highlight = true;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
onTap: () {
|
||||||
|
setState(() {
|
||||||
|
_highlight = false;
|
||||||
|
});
|
||||||
if (config.onPressed != null)
|
if (config.onPressed != null)
|
||||||
config.onPressed();
|
config.onPressed();
|
||||||
|
},
|
||||||
|
onTapCancel: () {
|
||||||
|
setState(() {
|
||||||
|
_highlight = false;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -180,7 +194,7 @@ class TextureButtonState extends ButtonState<TextureButton> {
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
canvas.save();
|
canvas.save();
|
||||||
if (highlight && config.textureDown != null) {
|
if (_highlight && config.textureDown != null) {
|
||||||
// Draw down state
|
// Draw down state
|
||||||
canvas.scale(size.width / config.textureDown.size.width, size.height / config.textureDown.size.height);
|
canvas.scale(size.width / config.textureDown.size.width, size.height / config.textureDown.size.height);
|
||||||
config.textureDown.drawTexture(canvas, Point.origin, new Paint());
|
config.textureDown.drawTexture(canvas, Point.origin, new Paint());
|
||||||
|
@ -10,7 +10,7 @@ class PowerBar extends NodeWithSize {
|
|||||||
Paint _paintOutline = new Paint()
|
Paint _paintOutline = new Paint()
|
||||||
..color = new Color(0xffffffff)
|
..color = new Color(0xffffffff)
|
||||||
..strokeWidth = 1.0
|
..strokeWidth = 1.0
|
||||||
..setStyle(sky.PaintingStyle.stroke);
|
..setStyle(ui.PaintingStyle.stroke);
|
||||||
|
|
||||||
void paint(PaintingCanvas canvas) {
|
void paint(PaintingCanvas canvas) {
|
||||||
applyTransformForPivot(canvas);
|
applyTransformForPivot(canvas);
|
||||||
|
@ -4,7 +4,7 @@ class RepeatedImage extends Node {
|
|||||||
Sprite _sprt0;
|
Sprite _sprt0;
|
||||||
Sprite _sprt1;
|
Sprite _sprt1;
|
||||||
|
|
||||||
RepeatedImage(sky.Image image, [sky.TransferMode mode = null]) {
|
RepeatedImage(ui.Image image, [ui.TransferMode mode = null]) {
|
||||||
_sprt0 = new Sprite.fromImage(image);
|
_sprt0 = new Sprite.fromImage(image);
|
||||||
_sprt0.size = new Size(1024.0, 1024.0);
|
_sprt0.size = new Size(1024.0, 1024.0);
|
||||||
_sprt0.pivot = Point.origin;
|
_sprt0.pivot = Point.origin;
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
part of game;
|
part of game;
|
||||||
|
|
||||||
class StarField extends NodeWithSize {
|
class StarField extends NodeWithSize {
|
||||||
sky.Image _image;
|
ui.Image _image;
|
||||||
SpriteSheet _spriteSheet;
|
SpriteSheet _spriteSheet;
|
||||||
int _numStars;
|
int _numStars;
|
||||||
bool _autoScroll;
|
bool _autoScroll;
|
||||||
@ -15,9 +15,9 @@ class StarField extends NodeWithSize {
|
|||||||
Size _paddedSize = Size.zero;
|
Size _paddedSize = Size.zero;
|
||||||
|
|
||||||
Paint _paint = new Paint()
|
Paint _paint = new Paint()
|
||||||
..filterQuality = sky.FilterQuality.low
|
..filterQuality = ui.FilterQuality.low
|
||||||
..isAntiAlias = false
|
..isAntiAlias = false
|
||||||
..transferMode = sky.TransferMode.plus;
|
..transferMode = ui.TransferMode.plus;
|
||||||
|
|
||||||
StarField(this._spriteSheet, this._numStars, [this._autoScroll = false]) : super(Size.zero) {
|
StarField(this._spriteSheet, this._numStars, [this._autoScroll = false]) : super(Size.zero) {
|
||||||
_image = _spriteSheet.image;
|
_image = _spriteSheet.image;
|
||||||
@ -48,9 +48,9 @@ class StarField extends NodeWithSize {
|
|||||||
|
|
||||||
void paint(PaintingCanvas canvas) {
|
void paint(PaintingCanvas canvas) {
|
||||||
// Create a transform for each star
|
// Create a transform for each star
|
||||||
List<sky.RSTransform> transforms = [];
|
List<ui.RSTransform> transforms = [];
|
||||||
for (int i = 0; i < _numStars; i++) {
|
for (int i = 0; i < _numStars; i++) {
|
||||||
sky.RSTransform transform = new sky.RSTransform(
|
ui.RSTransform transform = new ui.RSTransform(
|
||||||
_starScales[i],
|
_starScales[i],
|
||||||
0.0,
|
0.0,
|
||||||
_starPositions[i].x - _padding,
|
_starPositions[i].x - _padding,
|
||||||
@ -60,7 +60,7 @@ class StarField extends NodeWithSize {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Draw the stars
|
// Draw the stars
|
||||||
canvas.drawAtlas(_image, transforms, _rects, _colors, sky.TransferMode.modulate, null, _paint);
|
canvas.drawAtlas(_image, transforms, _rects, _colors, ui.TransferMode.modulate, null, _paint);
|
||||||
}
|
}
|
||||||
|
|
||||||
void move(double dx, double dy) {
|
void move(double dx, double dy) {
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
name: asteroids
|
name: asteroids
|
||||||
dependencies:
|
dependencies:
|
||||||
sky: any
|
flutter: ">=0.0.3 <0.1.0"
|
||||||
sky_tools: any
|
sky_tools: any
|
||||||
skysprites: any
|
flutter_sprites: any
|
||||||
box2d: any
|
box2d: any
|
||||||
dependency_overrides:
|
dependency_overrides:
|
||||||
material_design_icons:
|
material_design_icons:
|
||||||
path: ../../sky/packages/material_design_icons
|
path: ../../sky/packages/material_design_icons
|
||||||
sky:
|
flutter:
|
||||||
path: ../../sky/packages/sky
|
path: ../../sky/packages/sky
|
||||||
skysprites:
|
flutter_sprites:
|
||||||
path: ../../skysprites
|
path: ../../skysprites
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
import 'dart:sky';
|
import 'dart:ui';
|
||||||
|
|
||||||
import 'package:sky/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:sky/rendering.dart';
|
import 'package:flutter/rendering.dart';
|
||||||
import 'package:sky/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:sky/widgets.dart';
|
import 'package:flutter/widgets.dart';
|
||||||
import 'package:skysprites/skysprites.dart';
|
import 'package:flutter_sprites/flutter_sprites.dart';
|
||||||
|
|
||||||
AssetBundle _initBundle() {
|
AssetBundle _initBundle() {
|
||||||
if (rootBundle != null)
|
if (rootBundle != null)
|
||||||
@ -32,7 +32,7 @@ main() async {
|
|||||||
runApp(_app);
|
runApp(_app);
|
||||||
}
|
}
|
||||||
|
|
||||||
class TestBedApp extends App {
|
class TestBedApp extends MaterialApp {
|
||||||
|
|
||||||
Widget build() {
|
Widget build() {
|
||||||
ThemeData theme = new ThemeData(
|
ThemeData theme = new ThemeData(
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
import 'dart:sky';
|
import 'dart:ui';
|
||||||
|
|
||||||
import 'package:sky/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:sky/rendering.dart';
|
import 'package:flutter/rendering.dart';
|
||||||
import 'package:sky/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:sky/widgets.dart';
|
import 'package:flutter/widgets.dart';
|
||||||
import 'package:skysprites/skysprites.dart';
|
import 'package:flutter_sprites/flutter_sprites.dart';
|
||||||
|
|
||||||
AssetBundle _initBundle() {
|
AssetBundle _initBundle() {
|
||||||
if (rootBundle != null)
|
if (rootBundle != null)
|
||||||
@ -32,7 +32,7 @@ main() async {
|
|||||||
String json = await _bundle.loadString('assets/sprites.json');
|
String json = await _bundle.loadString('assets/sprites.json');
|
||||||
_spriteSheet = new SpriteSheet(_images['assets/sprites.png'], json);
|
_spriteSheet = new SpriteSheet(_images['assets/sprites.png'], json);
|
||||||
|
|
||||||
runApp(new App(
|
runApp(new MaterialApp(
|
||||||
title: 'Test drawAtlas',
|
title: 'Test drawAtlas',
|
||||||
theme: _theme,
|
theme: _theme,
|
||||||
routes: {
|
routes: {
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
import 'dart:sky' as sky;
|
import 'dart:ui' as ui;
|
||||||
import 'dart:math' as math;
|
import 'dart:math' as math;
|
||||||
|
|
||||||
import 'package:sky/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:sky/rendering.dart';
|
import 'package:flutter/rendering.dart';
|
||||||
import 'package:sky/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:sky/widgets.dart';
|
import 'package:flutter/widgets.dart';
|
||||||
import 'package:skysprites/skysprites.dart';
|
import 'package:flutter_sprites/flutter_sprites.dart';
|
||||||
|
|
||||||
AssetBundle _initBundle() {
|
AssetBundle _initBundle() {
|
||||||
if (rootBundle != null)
|
if (rootBundle != null)
|
||||||
@ -33,11 +33,11 @@ main() async {
|
|||||||
String json = await _bundle.loadString('assets/sprites.json');
|
String json = await _bundle.loadString('assets/sprites.json');
|
||||||
_spriteSheet = new SpriteSheet(_images['assets/sprites.png'], json);
|
_spriteSheet = new SpriteSheet(_images['assets/sprites.png'], json);
|
||||||
|
|
||||||
runApp(new App(
|
runApp(new MaterialApp(
|
||||||
title: 'Test Sprite Performance',
|
title: 'Test Sprite Performance',
|
||||||
theme: _theme,
|
theme: _theme,
|
||||||
routes: {
|
routes: {
|
||||||
'/': (NavigatorState navigator, RouteState route) {
|
'/': (RouteArguments args) {
|
||||||
return new SpriteWidget(new TestPerformance());
|
return new SpriteWidget(new TestPerformance());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -202,7 +202,7 @@ class TestPerformanceAtlas extends PerformanceTest {
|
|||||||
double rotation = 0.0;
|
double rotation = 0.0;
|
||||||
List<Rect> rects = [];
|
List<Rect> rects = [];
|
||||||
Paint cachedPaint = new Paint()
|
Paint cachedPaint = new Paint()
|
||||||
..filterQuality = sky.FilterQuality.low
|
..filterQuality = ui.FilterQuality.low
|
||||||
..isAntiAlias = false;
|
..isAntiAlias = false;
|
||||||
|
|
||||||
TestPerformanceAtlas() {
|
TestPerformanceAtlas() {
|
||||||
@ -216,7 +216,7 @@ class TestPerformanceAtlas extends PerformanceTest {
|
|||||||
|
|
||||||
void paint(PaintingCanvas canvas) {
|
void paint(PaintingCanvas canvas) {
|
||||||
// Setup transforms
|
// Setup transforms
|
||||||
List<sky.RSTransform> transforms = [];
|
List<ui.RSTransform> transforms = [];
|
||||||
|
|
||||||
for (int x = 0; x < grid; x++) {
|
for (int x = 0; x < grid; x++) {
|
||||||
for (int y = 0; y < grid; y++) {
|
for (int y = 0; y < grid; y++) {
|
||||||
@ -238,12 +238,12 @@ class TestPerformanceAtlas extends PerformanceTest {
|
|||||||
rotation += 1.0;
|
rotation += 1.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
sky.RSTransform createTransform(double x, double y, double ax, double ay, double rot, double scale) {
|
ui.RSTransform createTransform(double x, double y, double ax, double ay, double rot, double scale) {
|
||||||
double scos = math.cos(convertDegrees2Radians(rot)) * scale;
|
double scos = math.cos(convertDegrees2Radians(rot)) * scale;
|
||||||
double ssin = math.sin(convertDegrees2Radians(rot)) * scale;
|
double ssin = math.sin(convertDegrees2Radians(rot)) * scale;
|
||||||
double tx = x + -scos * ax + ssin * ay;
|
double tx = x + -scos * ax + ssin * ay;
|
||||||
double ty = y + -ssin * ax - scos * ay;
|
double ty = y + -ssin * ax - scos * ay;
|
||||||
return new sky.RSTransform(scos, ssin, tx, ty);
|
return new ui.RSTransform(scos, ssin, tx, ty);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -255,7 +255,7 @@ class TestPerformanceAtlas2 extends PerformanceTest {
|
|||||||
double rotation = 0.0;
|
double rotation = 0.0;
|
||||||
List<Rect> rects = [];
|
List<Rect> rects = [];
|
||||||
Paint cachedPaint = new Paint()
|
Paint cachedPaint = new Paint()
|
||||||
..filterQuality = sky.FilterQuality.low
|
..filterQuality = ui.FilterQuality.low
|
||||||
..isAntiAlias = false;
|
..isAntiAlias = false;
|
||||||
|
|
||||||
TestPerformanceAtlas2() {
|
TestPerformanceAtlas2() {
|
||||||
@ -269,7 +269,7 @@ class TestPerformanceAtlas2 extends PerformanceTest {
|
|||||||
|
|
||||||
void paint(PaintingCanvas canvas) {
|
void paint(PaintingCanvas canvas) {
|
||||||
// Setup transforms
|
// Setup transforms
|
||||||
List<sky.RSTransform> transforms = [];
|
List<ui.RSTransform> transforms = [];
|
||||||
|
|
||||||
for (int x = 12; x < grid - 12; x++) {
|
for (int x = 12; x < grid - 12; x++) {
|
||||||
for (int y = 0; y < grid; y++) {
|
for (int y = 0; y < grid; y++) {
|
||||||
@ -291,11 +291,11 @@ class TestPerformanceAtlas2 extends PerformanceTest {
|
|||||||
rotation += 1.0;
|
rotation += 1.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
sky.RSTransform createTransform(double x, double y, double ax, double ay, double rot, double scale) {
|
ui.RSTransform createTransform(double x, double y, double ax, double ay, double rot, double scale) {
|
||||||
double scos = math.cos(convertDegrees2Radians(rot)) * scale;
|
double scos = math.cos(convertDegrees2Radians(rot)) * scale;
|
||||||
double ssin = math.sin(convertDegrees2Radians(rot)) * scale;
|
double ssin = math.sin(convertDegrees2Radians(rot)) * scale;
|
||||||
double tx = x + -scos * ax + ssin * ay;
|
double tx = x + -scos * ax + ssin * ay;
|
||||||
double ty = y + -ssin * ax - scos * ay;
|
double ty = y + -ssin * ax - scos * ay;
|
||||||
return new sky.RSTransform(scos, ssin, tx, ty);
|
return new ui.RSTransform(scos, ssin, tx, ty);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
import 'dart:sky';
|
import 'dart:ui';
|
||||||
|
|
||||||
import 'package:sky/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:sky/rendering.dart';
|
import 'package:flutter/rendering.dart';
|
||||||
import 'package:sky/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:sky/widgets.dart';
|
import 'package:flutter/widgets.dart';
|
||||||
import 'package:skysprites/skysprites.dart';
|
import 'package:flutter_sprites/flutter_sprites.dart';
|
||||||
|
|
||||||
AssetBundle _initBundle() {
|
AssetBundle _initBundle() {
|
||||||
if (rootBundle != null)
|
if (rootBundle != null)
|
||||||
@ -27,7 +27,7 @@ main() async {
|
|||||||
String json = await _bundle.loadString('assets/sprites.json');
|
String json = await _bundle.loadString('assets/sprites.json');
|
||||||
_spriteSheet = new SpriteSheet(_images['assets/sprites.png'], json);
|
_spriteSheet = new SpriteSheet(_images['assets/sprites.png'], json);
|
||||||
|
|
||||||
runApp(new App(
|
runApp(new MaterialApp(
|
||||||
title: 'Test Physics',
|
title: 'Test Physics',
|
||||||
theme: new ThemeData(
|
theme: new ThemeData(
|
||||||
brightness: ThemeBrightness.light,
|
brightness: ThemeBrightness.light,
|
||||||
@ -45,24 +45,11 @@ main() async {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class TestBed extends NodeWithSize {
|
class TestBed extends NodeWithSize {
|
||||||
Sprite _ship;
|
|
||||||
Sprite _obstacle;
|
Sprite _obstacle;
|
||||||
|
PhysicsNode _physicsNode;
|
||||||
|
|
||||||
TestBed() : super(new Size(1024.0, 1024.0)) {
|
TestBed() : super(new Size(1024.0, 1024.0)) {
|
||||||
PhysicsNode physicsNode = new PhysicsNode(new Offset(0.0, 100.0));
|
_physicsNode = new PhysicsNode(new Offset(0.0, 100.0));
|
||||||
|
|
||||||
_ship = new Sprite(_spriteSheet["ship.png"]);
|
|
||||||
_ship.position = new Point(512.0, 512.0);
|
|
||||||
_ship.size = new Size(64.0, 64.0);
|
|
||||||
_ship.physicsBody = new PhysicsBody(
|
|
||||||
new PhysicsShapeGroup([
|
|
||||||
new PhysicsShapeCircle(Point.origin, 32.0),
|
|
||||||
new PhysicsShapePolygon([new Point(0.0, 0.0), new Point(50.0, 0.0), new Point(50.0, 50.0), new Point(0.0, 50.0)])
|
|
||||||
]),
|
|
||||||
friction: 0.5,
|
|
||||||
tag: "ship"
|
|
||||||
);
|
|
||||||
physicsNode.addChild(_ship);
|
|
||||||
|
|
||||||
_obstacle = new Sprite(_spriteSheet["ship.png"]);
|
_obstacle = new Sprite(_spriteSheet["ship.png"]);
|
||||||
_obstacle.position = new Point(532.0, 800.0);
|
_obstacle.position = new Point(532.0, 800.0);
|
||||||
@ -73,23 +60,51 @@ class TestBed extends NodeWithSize {
|
|||||||
friction: 0.5,
|
friction: 0.5,
|
||||||
tag: "obstacle"
|
tag: "obstacle"
|
||||||
);
|
);
|
||||||
physicsNode.addChild(_obstacle);
|
_physicsNode.addChild(_obstacle);
|
||||||
physicsNode.addContactCallback(myCallback, "obstacle", "ship", PhysicsContactType.begin);
|
_physicsNode.addContactCallback(myCallback, "obstacle", "ship", PhysicsContactType.begin);
|
||||||
|
|
||||||
addChild(physicsNode);
|
addChild(_physicsNode);
|
||||||
|
|
||||||
userInteractionEnabled = true;
|
userInteractionEnabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void myCallback(PhysicsContactType type, PhysicsContact contact) {
|
void myCallback(PhysicsContactType type, PhysicsContact contact) {
|
||||||
print("CONTACT type: $type");
|
print("CONTACT type: $type");
|
||||||
contact.nodeB.removeFromParent();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool handleEvent(SpriteBoxEvent event) {
|
bool handleEvent(SpriteBoxEvent event) {
|
||||||
if (event.type == "pointerdown") {
|
if (event.type == "pointerdown") {
|
||||||
Point pos = convertPointToNodeSpace(event.boxPosition);
|
Point pos = convertPointToNodeSpace(event.boxPosition);
|
||||||
_ship.position = pos;
|
|
||||||
|
Sprite shipA;
|
||||||
|
shipA = new Sprite(_spriteSheet["ship.png"]);
|
||||||
|
shipA.opacity = 0.3;
|
||||||
|
shipA.position = new Point(pos.x - 40.0, pos.y);
|
||||||
|
shipA.size = new Size(64.0, 64.0);
|
||||||
|
shipA.physicsBody = new PhysicsBody(new PhysicsShapeCircle(Point.origin, 32.0),
|
||||||
|
friction: 0.5,
|
||||||
|
restitution: 0.5,
|
||||||
|
tag: "ship"
|
||||||
|
);
|
||||||
|
_physicsNode.addChild(shipA);
|
||||||
|
shipA.physicsBody.applyLinearImpulse(
|
||||||
|
new Offset(randomSignedDouble() * 5000.0, randomSignedDouble() * 5000.0),
|
||||||
|
shipA.position
|
||||||
|
);
|
||||||
|
|
||||||
|
Sprite shipB;
|
||||||
|
shipB = new Sprite(_spriteSheet["ship.png"]);
|
||||||
|
shipB.opacity = 0.3;
|
||||||
|
shipB.position = new Point(pos.x + 40.0, pos.y);
|
||||||
|
shipB.size = new Size(64.0, 64.0);
|
||||||
|
shipB.physicsBody = new PhysicsBody(new PhysicsShapePolygon([new Point(-25.0, -25.0), new Point(25.0, -25.0), new Point(25.0, 25.0), new Point(-25.0, 25.0)]),
|
||||||
|
friction: 0.5,
|
||||||
|
restitution: 0.5,
|
||||||
|
tag: "ship"
|
||||||
|
);
|
||||||
|
_physicsNode.addChild(shipB);
|
||||||
|
|
||||||
|
new PhysicsJointRevolute(shipA.physicsBody, shipB.physicsBody, pos);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,6 @@
|
|||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
import 'package:sky/widgets.dart';
|
import 'package:flutter/widgets.dart';
|
||||||
|
|
||||||
void main() => runApp(new Center(child: new Text('Hello, world!')));
|
void main() => runApp(new Center(child: new Text('Hello, world!')));
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
name: hello_world
|
name: hello_world
|
||||||
dependencies:
|
dependencies:
|
||||||
sky: any
|
flutter: ">=0.0.3 <0.1.0"
|
||||||
sky_tools: any
|
sky_tools: any
|
||||||
dependency_overrides:
|
dependency_overrides:
|
||||||
material_design_icons:
|
material_design_icons:
|
||||||
path: ../../sky/packages/material_design_icons
|
path: ../../sky/packages/material_design_icons
|
||||||
sky:
|
flutter:
|
||||||
path: ../../sky/packages/sky
|
path: ../../sky/packages/sky
|
||||||
|
@ -1,14 +1,13 @@
|
|||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
import 'dart:sky' as sky;
|
|
||||||
import 'dart:math';
|
import 'dart:math';
|
||||||
|
|
||||||
import 'package:sky/material.dart';
|
import 'package:flutter/gestures.dart';
|
||||||
import 'package:sky/painting.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:sky/rendering.dart';
|
import 'package:flutter/painting.dart';
|
||||||
import 'package:sky/services.dart';
|
import 'package:flutter/rendering.dart';
|
||||||
import 'package:sky/widgets.dart';
|
import 'package:flutter/services.dart';
|
||||||
|
|
||||||
// Classic minesweeper-inspired game. The mouse controls are standard
|
// Classic minesweeper-inspired game. The mouse controls are standard
|
||||||
// except for left + right combo which is not implemented. For touch,
|
// except for left + right combo which is not implemented. For touch,
|
||||||
@ -86,7 +85,7 @@ class MineDiggerState extends State<MineDigger> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
PointerEventListener _pointerDownHandlerFor(int posX, int posY) {
|
PointerEventListener _pointerDownHandlerFor(int posX, int posY) {
|
||||||
return (sky.PointerEvent event) {
|
return (PointerInputEvent event) {
|
||||||
if (event.buttons == 1) {
|
if (event.buttons == 1) {
|
||||||
probe(posX, posY);
|
probe(posX, posY);
|
||||||
} else if (event.buttons == 2) {
|
} else if (event.buttons == 2) {
|
||||||
@ -191,7 +190,7 @@ class MineDiggerState extends State<MineDigger> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void handleToolbarPointerDown(sky.PointerEvent event) {
|
void handleToolbarPointerDown(PointerInputEvent event) {
|
||||||
setState(() {
|
setState(() {
|
||||||
resetGame();
|
resetGame();
|
||||||
});
|
});
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
name: mine_digger
|
name: mine_digger
|
||||||
dependencies:
|
dependencies:
|
||||||
sky: any
|
flutter: ">=0.0.3 <0.1.0"
|
||||||
sky_tools: any
|
sky_tools: any
|
||||||
dependency_overrides:
|
dependency_overrides:
|
||||||
material_design_icons:
|
material_design_icons:
|
||||||
path: ../../sky/packages/material_design_icons
|
path: ../../sky/packages/material_design_icons
|
||||||
sky:
|
flutter:
|
||||||
path: ../../sky/packages/sky
|
path: ../../sky/packages/sky
|
||||||
|
@ -2,20 +2,20 @@
|
|||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
import 'dart:sky' as sky;
|
import 'dart:ui' as ui;
|
||||||
import 'dart:typed_data';
|
import 'dart:typed_data';
|
||||||
|
|
||||||
void drawText(sky.Canvas canvas, String lh) {
|
void drawText(ui.Canvas canvas, String lh) {
|
||||||
sky.Paint paint = new sky.Paint();
|
ui.Paint paint = new ui.Paint();
|
||||||
|
|
||||||
// offset down
|
// offset down
|
||||||
canvas.translate(0.0, 100.0);
|
canvas.translate(0.0, 100.0);
|
||||||
|
|
||||||
// set up the text
|
// set up the text
|
||||||
sky.Document document = new sky.Document();
|
ui.Document document = new ui.Document();
|
||||||
sky.Text arabic = document.createText("مرحبا");
|
ui.Text arabic = document.createText("مرحبا");
|
||||||
sky.Text english = document.createText(" Hello");
|
ui.Text english = document.createText(" Hello");
|
||||||
sky.Element block = document.createElement('div');
|
ui.Element block = document.createElement('div');
|
||||||
block.style['display'] = 'paragraph';
|
block.style['display'] = 'paragraph';
|
||||||
block.style['font-family'] = 'monospace';
|
block.style['font-family'] = 'monospace';
|
||||||
block.style['font-size'] = '50px';
|
block.style['font-size'] = '50px';
|
||||||
@ -23,21 +23,21 @@ void drawText(sky.Canvas canvas, String lh) {
|
|||||||
block.style['color'] = '#0000A0';
|
block.style['color'] = '#0000A0';
|
||||||
block.appendChild(arabic);
|
block.appendChild(arabic);
|
||||||
block.appendChild(english);
|
block.appendChild(english);
|
||||||
sky.LayoutRoot layoutRoot = new sky.LayoutRoot();
|
ui.LayoutRoot layoutRoot = new ui.LayoutRoot();
|
||||||
layoutRoot.rootElement = block;
|
layoutRoot.rootElement = block;
|
||||||
layoutRoot.maxWidth = sky.view.width - 20.0; // you need to set a width for this to paint
|
layoutRoot.maxWidth = ui.view.width - 20.0; // you need to set a width for this to paint
|
||||||
layoutRoot.layout();
|
layoutRoot.layout();
|
||||||
|
|
||||||
// draw a line at the text's baseline
|
// draw a line at the text's baseline
|
||||||
sky.Path path = new sky.Path();
|
ui.Path path = new ui.Path();
|
||||||
path.moveTo(0.0, 0.0);
|
path.moveTo(0.0, 0.0);
|
||||||
path.lineTo(block.maxContentWidth, 0.0);
|
path.lineTo(block.maxContentWidth, 0.0);
|
||||||
path.moveTo(0.0, block.alphabeticBaseline);
|
path.moveTo(0.0, block.alphabeticBaseline);
|
||||||
path.lineTo(block.maxContentWidth, block.alphabeticBaseline);
|
path.lineTo(block.maxContentWidth, block.alphabeticBaseline);
|
||||||
path.moveTo(0.0, block.height);
|
path.moveTo(0.0, block.height);
|
||||||
path.lineTo(block.maxContentWidth, block.height);
|
path.lineTo(block.maxContentWidth, block.height);
|
||||||
paint.color = const sky.Color(0xFFFF9000);
|
paint.color = const ui.Color(0xFFFF9000);
|
||||||
paint.setStyle(sky.PaintingStyle.stroke);
|
paint.setStyle(ui.PaintingStyle.stroke);
|
||||||
paint.strokeWidth = 3.0;
|
paint.strokeWidth = 3.0;
|
||||||
canvas.drawPath(path, paint);
|
canvas.drawPath(path, paint);
|
||||||
|
|
||||||
@ -45,14 +45,14 @@ void drawText(sky.Canvas canvas, String lh) {
|
|||||||
layoutRoot.paint(canvas);
|
layoutRoot.paint(canvas);
|
||||||
}
|
}
|
||||||
|
|
||||||
sky.Picture paint(sky.Rect paintBounds) {
|
ui.Picture paint(ui.Rect paintBounds) {
|
||||||
sky.PictureRecorder recorder = new sky.PictureRecorder();
|
ui.PictureRecorder recorder = new ui.PictureRecorder();
|
||||||
sky.Canvas canvas = new sky.Canvas(recorder, paintBounds);
|
ui.Canvas canvas = new ui.Canvas(recorder, paintBounds);
|
||||||
|
|
||||||
sky.Paint paint = new sky.Paint();
|
ui.Paint paint = new ui.Paint();
|
||||||
paint.color = const sky.Color(0xFFFFFFFF);
|
paint.color = const ui.Color(0xFFFFFFFF);
|
||||||
paint.setStyle(sky.PaintingStyle.fill);
|
paint.setStyle(ui.PaintingStyle.fill);
|
||||||
canvas.drawRect(new sky.Rect.fromLTRB(0.0, 0.0, sky.view.width, sky.view.height), paint);
|
canvas.drawRect(new ui.Rect.fromLTRB(0.0, 0.0, ui.view.width, ui.view.height), paint);
|
||||||
|
|
||||||
canvas.translate(10.0, 0.0);
|
canvas.translate(10.0, 0.0);
|
||||||
drawText(canvas, '1.0');
|
drawText(canvas, '1.0');
|
||||||
@ -61,29 +61,29 @@ sky.Picture paint(sky.Rect paintBounds) {
|
|||||||
return recorder.endRecording();
|
return recorder.endRecording();
|
||||||
}
|
}
|
||||||
|
|
||||||
sky.Scene composite(sky.Picture picture, sky.Rect paintBounds) {
|
ui.Scene composite(ui.Picture picture, ui.Rect paintBounds) {
|
||||||
final double devicePixelRatio = sky.view.devicePixelRatio;
|
final double devicePixelRatio = ui.view.devicePixelRatio;
|
||||||
sky.Rect sceneBounds = new sky.Rect.fromLTWH(0.0, 0.0, sky.view.width * devicePixelRatio, sky.view.height * devicePixelRatio);
|
ui.Rect sceneBounds = new ui.Rect.fromLTWH(0.0, 0.0, ui.view.width * devicePixelRatio, ui.view.height * devicePixelRatio);
|
||||||
Float64List deviceTransform = new Float64List(16)
|
Float64List deviceTransform = new Float64List(16)
|
||||||
..[0] = devicePixelRatio
|
..[0] = devicePixelRatio
|
||||||
..[5] = devicePixelRatio
|
..[5] = devicePixelRatio
|
||||||
..[10] = 1.0
|
..[10] = 1.0
|
||||||
..[15] = 1.0;
|
..[15] = 1.0;
|
||||||
sky.SceneBuilder sceneBuilder = new sky.SceneBuilder(sceneBounds)
|
ui.SceneBuilder sceneBuilder = new ui.SceneBuilder(sceneBounds)
|
||||||
..pushTransform(deviceTransform)
|
..pushTransform(deviceTransform)
|
||||||
..addPicture(sky.Offset.zero, picture, paintBounds)
|
..addPicture(ui.Offset.zero, picture, paintBounds)
|
||||||
..pop();
|
..pop();
|
||||||
return sceneBuilder.build();
|
return sceneBuilder.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
void beginFrame(double timeStamp) {
|
void beginFrame(double timeStamp) {
|
||||||
sky.Rect paintBounds = new sky.Rect.fromLTWH(0.0, 0.0, sky.view.width, sky.view.height);
|
ui.Rect paintBounds = new ui.Rect.fromLTWH(0.0, 0.0, ui.view.width, ui.view.height);
|
||||||
sky.Picture picture = paint(paintBounds);
|
ui.Picture picture = paint(paintBounds);
|
||||||
sky.Scene scene = composite(picture, paintBounds);
|
ui.Scene scene = composite(picture, paintBounds);
|
||||||
sky.view.scene = scene;
|
ui.view.scene = scene;
|
||||||
}
|
}
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
sky.view.setFrameCallback(beginFrame);
|
ui.view.setFrameCallback(beginFrame);
|
||||||
sky.view.scheduleFrame();
|
ui.view.scheduleFrame();
|
||||||
}
|
}
|
||||||
|
@ -2,56 +2,56 @@
|
|||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
import 'dart:sky' as sky;
|
import 'dart:ui' as ui;
|
||||||
import 'dart:typed_data';
|
import 'dart:typed_data';
|
||||||
|
|
||||||
sky.Color color;
|
ui.Color color;
|
||||||
|
|
||||||
sky.Picture paint(sky.Rect paintBounds) {
|
ui.Picture paint(ui.Rect paintBounds) {
|
||||||
sky.PictureRecorder recorder = new sky.PictureRecorder();
|
ui.PictureRecorder recorder = new ui.PictureRecorder();
|
||||||
sky.Canvas canvas = new sky.Canvas(recorder, paintBounds);
|
ui.Canvas canvas = new ui.Canvas(recorder, paintBounds);
|
||||||
sky.Size size = paintBounds.size;
|
ui.Size size = paintBounds.size;
|
||||||
|
|
||||||
double radius = size.shortestSide * 0.45;
|
double radius = size.shortestSide * 0.45;
|
||||||
sky.Paint paint = new sky.Paint()
|
ui.Paint paint = new ui.Paint()
|
||||||
..color = color;
|
..color = color;
|
||||||
canvas.drawCircle(size.center(sky.Point.origin), radius, paint);
|
canvas.drawCircle(size.center(ui.Point.origin), radius, paint);
|
||||||
|
|
||||||
return recorder.endRecording();
|
return recorder.endRecording();
|
||||||
}
|
}
|
||||||
|
|
||||||
sky.Scene composite(sky.Picture picture, sky.Rect paintBounds) {
|
ui.Scene composite(ui.Picture picture, ui.Rect paintBounds) {
|
||||||
final double devicePixelRatio = sky.view.devicePixelRatio;
|
final double devicePixelRatio = ui.view.devicePixelRatio;
|
||||||
sky.Rect sceneBounds = new sky.Rect.fromLTWH(0.0, 0.0, sky.view.width * devicePixelRatio, sky.view.height * devicePixelRatio);
|
ui.Rect sceneBounds = new ui.Rect.fromLTWH(0.0, 0.0, ui.view.width * devicePixelRatio, ui.view.height * devicePixelRatio);
|
||||||
Float64List deviceTransform = new Float64List(16)
|
Float64List deviceTransform = new Float64List(16)
|
||||||
..[0] = devicePixelRatio
|
..[0] = devicePixelRatio
|
||||||
..[5] = devicePixelRatio
|
..[5] = devicePixelRatio
|
||||||
..[10] = 1.0
|
..[10] = 1.0
|
||||||
..[15] = 1.0;
|
..[15] = 1.0;
|
||||||
sky.SceneBuilder sceneBuilder = new sky.SceneBuilder(sceneBounds)
|
ui.SceneBuilder sceneBuilder = new ui.SceneBuilder(sceneBounds)
|
||||||
..pushTransform(deviceTransform)
|
..pushTransform(deviceTransform)
|
||||||
..addPicture(sky.Offset.zero, picture, paintBounds)
|
..addPicture(ui.Offset.zero, picture, paintBounds)
|
||||||
..pop();
|
..pop();
|
||||||
return sceneBuilder.build();
|
return sceneBuilder.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
void beginFrame(double timeStamp) {
|
void beginFrame(double timeStamp) {
|
||||||
sky.Rect paintBounds = new sky.Rect.fromLTWH(0.0, 0.0, sky.view.width, sky.view.height);
|
ui.Rect paintBounds = new ui.Rect.fromLTWH(0.0, 0.0, ui.view.width, ui.view.height);
|
||||||
sky.Picture picture = paint(paintBounds);
|
ui.Picture picture = paint(paintBounds);
|
||||||
sky.Scene scene = composite(picture, paintBounds);
|
ui.Scene scene = composite(picture, paintBounds);
|
||||||
sky.view.scene = scene;
|
ui.view.scene = scene;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool handleEvent(sky.Event event) {
|
bool handleEvent(ui.Event event) {
|
||||||
if (event.type == 'pointerdown') {
|
if (event.type == 'pointerdown') {
|
||||||
color = new sky.Color.fromARGB(255, 0, 0, 255);
|
color = new ui.Color.fromARGB(255, 0, 0, 255);
|
||||||
sky.view.scheduleFrame();
|
ui.view.scheduleFrame();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event.type == 'pointerup') {
|
if (event.type == 'pointerup') {
|
||||||
color = new sky.Color.fromARGB(255, 0, 255, 0);
|
color = new ui.Color.fromARGB(255, 0, 255, 0);
|
||||||
sky.view.scheduleFrame();
|
ui.view.scheduleFrame();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -65,8 +65,8 @@ bool handleEvent(sky.Event event) {
|
|||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
print('Hello, world');
|
print('Hello, world');
|
||||||
color = new sky.Color.fromARGB(255, 0, 255, 0);
|
color = new ui.Color.fromARGB(255, 0, 255, 0);
|
||||||
sky.view.setFrameCallback(beginFrame);
|
ui.view.setFrameCallback(beginFrame);
|
||||||
sky.view.setEventCallback(handleEvent);
|
ui.view.setEventCallback(handleEvent);
|
||||||
sky.view.scheduleFrame();
|
ui.view.scheduleFrame();
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
import 'dart:math' as math;
|
import 'dart:math' as math;
|
||||||
import 'dart:sky' as sky;
|
import 'dart:ui' as ui;
|
||||||
import 'dart:typed_data';
|
import 'dart:typed_data';
|
||||||
|
|
||||||
const kMaxIterations = 100;
|
const kMaxIterations = 100;
|
||||||
@ -14,9 +14,9 @@ void report(String s) {
|
|||||||
// print("$s\n");
|
// print("$s\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
sky.LayoutRoot layoutRoot = new sky.LayoutRoot();
|
ui.LayoutRoot layoutRoot = new ui.LayoutRoot();
|
||||||
sky.Document document = new sky.Document();
|
ui.Document document = new ui.Document();
|
||||||
sky.Element root;
|
ui.Element root;
|
||||||
math.Random random = new math.Random();
|
math.Random random = new math.Random();
|
||||||
|
|
||||||
bool pickThis(double odds) {
|
bool pickThis(double odds) {
|
||||||
@ -29,19 +29,19 @@ String generateCharacter(int min, int max) {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
String colorToCSSString(sky.Color color) {
|
String colorToCSSString(ui.Color color) {
|
||||||
return 'rgba(${color.red}, ${color.green}, ${color.blue}, ${color.alpha / 255.0})';
|
return 'rgba(${color.red}, ${color.green}, ${color.blue}, ${color.alpha / 255.0})';
|
||||||
}
|
}
|
||||||
|
|
||||||
void mutate(sky.Canvas canvas) {
|
void mutate(ui.Canvas canvas) {
|
||||||
// mutate the DOM randomly
|
// mutate the DOM randomly
|
||||||
int iterationsLeft = kMaxIterations;
|
int iterationsLeft = kMaxIterations;
|
||||||
sky.Node node = root;
|
ui.Node node = root;
|
||||||
sky.Node other = null;
|
ui.Node other = null;
|
||||||
while (node != null && iterationsLeft > 0) {
|
while (node != null && iterationsLeft > 0) {
|
||||||
iterationsLeft -= 1;
|
iterationsLeft -= 1;
|
||||||
if (node is sky.Element && pickThis(0.4)) {
|
if (node is ui.Element && pickThis(0.4)) {
|
||||||
node = (node as sky.Element).firstChild;
|
node = (node as ui.Element).firstChild;
|
||||||
} else if (node.nextSibling != null && pickThis(0.5)) {
|
} else if (node.nextSibling != null && pickThis(0.5)) {
|
||||||
node = node.nextSibling;
|
node = node.nextSibling;
|
||||||
} else if (other == null && node != root && pickThis(0.1)) {
|
} else if (other == null && node != root && pickThis(0.1)) {
|
||||||
@ -57,7 +57,7 @@ void mutate(sky.Canvas canvas) {
|
|||||||
} else if (node != root && pickThis(0.001)) {
|
} else if (node != root && pickThis(0.001)) {
|
||||||
report("remove()");
|
report("remove()");
|
||||||
node.remove();
|
node.remove();
|
||||||
} else if (node is sky.Element) {
|
} else if (node is ui.Element) {
|
||||||
if (pickThis(0.1)) {
|
if (pickThis(0.1)) {
|
||||||
report("appending a new text node (ASCII)");
|
report("appending a new text node (ASCII)");
|
||||||
node.appendChild(document.createText(generateCharacter(0x20, 0x7F)));
|
node.appendChild(document.createText(generateCharacter(0x20, 0x7F)));
|
||||||
@ -80,7 +80,7 @@ void mutate(sky.Canvas canvas) {
|
|||||||
break;
|
break;
|
||||||
} else if (pickThis(0.1)) {
|
} else if (pickThis(0.1)) {
|
||||||
report("styling: color");
|
report("styling: color");
|
||||||
node.style['color'] = colorToCSSString(new sky.Color(random.nextInt(0xFFFFFFFF) | 0xC0808080));
|
node.style['color'] = colorToCSSString(new ui.Color(random.nextInt(0xFFFFFFFF) | 0xC0808080));
|
||||||
break;
|
break;
|
||||||
} else if (pickThis(0.1)) {
|
} else if (pickThis(0.1)) {
|
||||||
report("styling: font-size");
|
report("styling: font-size");
|
||||||
@ -148,12 +148,12 @@ void mutate(sky.Canvas canvas) {
|
|||||||
break;
|
break;
|
||||||
} else if (pickThis(0.1)) {
|
} else if (pickThis(0.1)) {
|
||||||
report("styling: text-decoration-color");
|
report("styling: text-decoration-color");
|
||||||
node.style['text-decoration-color'] = colorToCSSString(new sky.Color(random.nextInt(0xFFFFFFFF)));
|
node.style['text-decoration-color'] = colorToCSSString(new ui.Color(random.nextInt(0xFFFFFFFF)));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
assert(node is sky.Text);
|
assert(node is ui.Text);
|
||||||
final sky.Text text = node;
|
final ui.Text text = node;
|
||||||
if (pickThis(0.1)) {
|
if (pickThis(0.1)) {
|
||||||
report("appending a new text node (ASCII)");
|
report("appending a new text node (ASCII)");
|
||||||
text.appendData(generateCharacter(0x20, 0x7F));
|
text.appendData(generateCharacter(0x20, 0x7F));
|
||||||
@ -182,8 +182,8 @@ void mutate(sky.Canvas canvas) {
|
|||||||
node = root;
|
node = root;
|
||||||
int count = 1;
|
int count = 1;
|
||||||
while (node != null) {
|
while (node != null) {
|
||||||
if (node is sky.Element && node.firstChild != null) {
|
if (node is ui.Element && node.firstChild != null) {
|
||||||
node = (node as sky.Element).firstChild;
|
node = (node as ui.Element).firstChild;
|
||||||
count += 1;
|
count += 1;
|
||||||
} else {
|
} else {
|
||||||
while (node != null && node.nextSibling == null)
|
while (node != null && node.nextSibling == null)
|
||||||
@ -202,40 +202,40 @@ void mutate(sky.Canvas canvas) {
|
|||||||
|
|
||||||
// draw the result
|
// draw the result
|
||||||
report("recording...");
|
report("recording...");
|
||||||
layoutRoot.maxWidth = sky.view.width;
|
layoutRoot.maxWidth = ui.view.width;
|
||||||
layoutRoot.layout();
|
layoutRoot.layout();
|
||||||
layoutRoot.paint(canvas);
|
layoutRoot.paint(canvas);
|
||||||
report("painting...");
|
report("painting...");
|
||||||
}
|
}
|
||||||
|
|
||||||
sky.Picture paint(sky.Rect paintBounds) {
|
ui.Picture paint(ui.Rect paintBounds) {
|
||||||
sky.PictureRecorder recorder = new sky.PictureRecorder();
|
ui.PictureRecorder recorder = new ui.PictureRecorder();
|
||||||
sky.Canvas canvas = new sky.Canvas(recorder, paintBounds);
|
ui.Canvas canvas = new ui.Canvas(recorder, paintBounds);
|
||||||
mutate(canvas);
|
mutate(canvas);
|
||||||
return recorder.endRecording();
|
return recorder.endRecording();
|
||||||
}
|
}
|
||||||
|
|
||||||
sky.Scene composite(sky.Picture picture, sky.Rect paintBounds) {
|
ui.Scene composite(ui.Picture picture, ui.Rect paintBounds) {
|
||||||
final double devicePixelRatio = sky.view.devicePixelRatio;
|
final double devicePixelRatio = ui.view.devicePixelRatio;
|
||||||
sky.Rect sceneBounds = new sky.Rect.fromLTWH(0.0, 0.0, sky.view.width * devicePixelRatio, sky.view.height * devicePixelRatio);
|
ui.Rect sceneBounds = new ui.Rect.fromLTWH(0.0, 0.0, ui.view.width * devicePixelRatio, ui.view.height * devicePixelRatio);
|
||||||
Float64List deviceTransform = new Float64List(16)
|
Float64List deviceTransform = new Float64List(16)
|
||||||
..[0] = devicePixelRatio
|
..[0] = devicePixelRatio
|
||||||
..[5] = devicePixelRatio
|
..[5] = devicePixelRatio
|
||||||
..[10] = 1.0
|
..[10] = 1.0
|
||||||
..[15] = 1.0;
|
..[15] = 1.0;
|
||||||
sky.SceneBuilder sceneBuilder = new sky.SceneBuilder(sceneBounds)
|
ui.SceneBuilder sceneBuilder = new ui.SceneBuilder(sceneBounds)
|
||||||
..pushTransform(deviceTransform)
|
..pushTransform(deviceTransform)
|
||||||
..addPicture(sky.Offset.zero, picture, paintBounds)
|
..addPicture(ui.Offset.zero, picture, paintBounds)
|
||||||
..pop();
|
..pop();
|
||||||
return sceneBuilder.build();
|
return sceneBuilder.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
void beginFrame(double timeStamp) {
|
void beginFrame(double timeStamp) {
|
||||||
sky.Rect paintBounds = new sky.Rect.fromLTWH(0.0, 0.0, sky.view.width, sky.view.height);
|
ui.Rect paintBounds = new ui.Rect.fromLTWH(0.0, 0.0, ui.view.width, ui.view.height);
|
||||||
sky.Picture picture = paint(paintBounds);
|
ui.Picture picture = paint(paintBounds);
|
||||||
sky.Scene scene = composite(picture, paintBounds);
|
ui.Scene scene = composite(picture, paintBounds);
|
||||||
sky.view.scene = scene;
|
ui.view.scene = scene;
|
||||||
sky.view.scheduleFrame();
|
ui.view.scheduleFrame();
|
||||||
}
|
}
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
@ -243,6 +243,6 @@ void main() {
|
|||||||
root.style['display'] = 'paragraph';
|
root.style['display'] = 'paragraph';
|
||||||
root.style['color'] = '#FFFFFF';
|
root.style['color'] = '#FFFFFF';
|
||||||
layoutRoot.rootElement = root;
|
layoutRoot.rootElement = root;
|
||||||
sky.view.setFrameCallback(beginFrame);
|
ui.view.setFrameCallback(beginFrame);
|
||||||
sky.view.scheduleFrame();
|
ui.view.scheduleFrame();
|
||||||
}
|
}
|
||||||
|
@ -2,34 +2,34 @@
|
|||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
import 'dart:sky' as sky;
|
import 'dart:ui' as ui;
|
||||||
import 'dart:math' as math;
|
import 'dart:math' as math;
|
||||||
import 'dart:typed_data';
|
import 'dart:typed_data';
|
||||||
|
|
||||||
sky.Picture paint(sky.Rect paintBounds) {
|
ui.Picture paint(ui.Rect paintBounds) {
|
||||||
sky.PictureRecorder recorder = new sky.PictureRecorder();
|
ui.PictureRecorder recorder = new ui.PictureRecorder();
|
||||||
sky.Canvas canvas = new sky.Canvas(recorder, paintBounds);
|
ui.Canvas canvas = new ui.Canvas(recorder, paintBounds);
|
||||||
sky.Size size = paintBounds.size;
|
ui.Size size = paintBounds.size;
|
||||||
|
|
||||||
sky.Paint paint = new sky.Paint();
|
ui.Paint paint = new ui.Paint();
|
||||||
sky.Point mid = size.center(sky.Point.origin);
|
ui.Point mid = size.center(ui.Point.origin);
|
||||||
double radius = size.shortestSide / 2.0;
|
double radius = size.shortestSide / 2.0;
|
||||||
canvas.drawPaint(new sky.Paint()..color = const sky.Color(0xFFFFFFFF));
|
canvas.drawPaint(new ui.Paint()..color = const ui.Color(0xFFFFFFFF));
|
||||||
|
|
||||||
canvas.save();
|
canvas.save();
|
||||||
canvas.translate(-mid.x/2.0, sky.view.height*2.0);
|
canvas.translate(-mid.x/2.0, ui.view.height*2.0);
|
||||||
canvas.clipRect(
|
canvas.clipRect(
|
||||||
new sky.Rect.fromLTRB(0.0, -sky.view.height, sky.view.width, radius));
|
new ui.Rect.fromLTRB(0.0, -ui.view.height, ui.view.width, radius));
|
||||||
|
|
||||||
canvas.translate(mid.x, mid.y);
|
canvas.translate(mid.x, mid.y);
|
||||||
paint.color = const sky.Color.fromARGB(128, 255, 0, 255);
|
paint.color = const ui.Color.fromARGB(128, 255, 0, 255);
|
||||||
canvas.rotate(math.PI/4.0);
|
canvas.rotate(math.PI/4.0);
|
||||||
|
|
||||||
sky.Gradient yellowBlue = new sky.Gradient.linear(
|
ui.Gradient yellowBlue = new ui.Gradient.linear(
|
||||||
[new sky.Point(-radius, -radius), new sky.Point(0.0, 0.0)],
|
[new ui.Point(-radius, -radius), new ui.Point(0.0, 0.0)],
|
||||||
[const sky.Color(0xFFFFFF00), const sky.Color(0xFF0000FF)]);
|
[const ui.Color(0xFFFFFF00), const ui.Color(0xFF0000FF)]);
|
||||||
canvas.drawRect(new sky.Rect.fromLTRB(-radius, -radius, radius, radius),
|
canvas.drawRect(new ui.Rect.fromLTRB(-radius, -radius, radius, radius),
|
||||||
new sky.Paint()..setShader(yellowBlue));
|
new ui.Paint()..setShader(yellowBlue));
|
||||||
|
|
||||||
// Scale x and y by 0.5.
|
// Scale x and y by 0.5.
|
||||||
var scaleMatrix = new Float64List.fromList([
|
var scaleMatrix = new Float64List.fromList([
|
||||||
@ -39,70 +39,70 @@ sky.Picture paint(sky.Rect paintBounds) {
|
|||||||
0.0, 0.0, 0.0, 1.0,
|
0.0, 0.0, 0.0, 1.0,
|
||||||
]);
|
]);
|
||||||
canvas.concat(scaleMatrix);
|
canvas.concat(scaleMatrix);
|
||||||
paint.color = const sky.Color.fromARGB(128, 0, 255, 0);
|
paint.color = const ui.Color.fromARGB(128, 0, 255, 0);
|
||||||
canvas.drawCircle(sky.Point.origin, radius, paint);
|
canvas.drawCircle(ui.Point.origin, radius, paint);
|
||||||
|
|
||||||
canvas.restore();
|
canvas.restore();
|
||||||
|
|
||||||
canvas.translate(0.0, 50.0);
|
canvas.translate(0.0, 50.0);
|
||||||
var builder = new sky.LayerDrawLooperBuilder()
|
var builder = new ui.LayerDrawLooperBuilder()
|
||||||
..addLayerOnTop(
|
..addLayerOnTop(
|
||||||
new sky.DrawLooperLayerInfo()
|
new ui.DrawLooperLayerInfo()
|
||||||
..setOffset(const sky.Offset(150.0, 0.0))
|
..setOffset(const ui.Offset(150.0, 0.0))
|
||||||
..setColorMode(sky.TransferMode.src)
|
..setColorMode(ui.TransferMode.src)
|
||||||
..setPaintBits(sky.PaintBits.all),
|
..setPaintBits(ui.PaintBits.all),
|
||||||
new sky.Paint()
|
new ui.Paint()
|
||||||
..color = const sky.Color.fromARGB(128, 255, 255, 0)
|
..color = const ui.Color.fromARGB(128, 255, 255, 0)
|
||||||
..colorFilter = new sky.ColorFilter.mode(
|
..colorFilter = new ui.ColorFilter.mode(
|
||||||
const sky.Color.fromARGB(128, 0, 0, 255), sky.TransferMode.srcIn)
|
const ui.Color.fromARGB(128, 0, 0, 255), ui.TransferMode.srcIn)
|
||||||
..maskFilter = new sky.MaskFilter.blur(
|
..maskFilter = new ui.MaskFilter.blur(
|
||||||
sky.BlurStyle.normal, 3.0, highQuality: true))
|
ui.BlurStyle.normal, 3.0, highQuality: true))
|
||||||
..addLayerOnTop(
|
..addLayerOnTop(
|
||||||
new sky.DrawLooperLayerInfo()
|
new ui.DrawLooperLayerInfo()
|
||||||
..setOffset(const sky.Offset(75.0, 75.0))
|
..setOffset(const ui.Offset(75.0, 75.0))
|
||||||
..setColorMode(sky.TransferMode.src)
|
..setColorMode(ui.TransferMode.src)
|
||||||
..setPaintBits(sky.PaintBits.shader),
|
..setPaintBits(ui.PaintBits.shader),
|
||||||
new sky.Paint()
|
new ui.Paint()
|
||||||
..shader = new sky.Gradient.radial(
|
..shader = new ui.Gradient.radial(
|
||||||
new sky.Point(0.0, 0.0), radius/3.0,
|
new ui.Point(0.0, 0.0), radius/3.0,
|
||||||
[const sky.Color(0xFFFFFF00), const sky.Color(0xFFFF0000)],
|
[const ui.Color(0xFFFFFF00), const ui.Color(0xFFFF0000)],
|
||||||
null, sky.TileMode.mirror)
|
null, ui.TileMode.mirror)
|
||||||
// Since we're don't set sky.PaintBits.maskFilter, this has no effect.
|
// Since we're don't set ui.PaintBits.maskFilter, this has no effect.
|
||||||
..maskFilter = new sky.MaskFilter.blur(
|
..maskFilter = new ui.MaskFilter.blur(
|
||||||
sky.BlurStyle.normal, 50.0, highQuality: true))
|
ui.BlurStyle.normal, 50.0, highQuality: true))
|
||||||
..addLayerOnTop(
|
..addLayerOnTop(
|
||||||
new sky.DrawLooperLayerInfo()..setOffset(const sky.Offset(225.0, 75.0)),
|
new ui.DrawLooperLayerInfo()..setOffset(const ui.Offset(225.0, 75.0)),
|
||||||
// Since this layer uses a DST color mode, this has no effect.
|
// Since this layer uses a DST color mode, this has no effect.
|
||||||
new sky.Paint()..color = const sky.Color.fromARGB(128, 255, 0, 0));
|
new ui.Paint()..color = const ui.Color.fromARGB(128, 255, 0, 0));
|
||||||
paint.drawLooper = builder.build();
|
paint.drawLooper = builder.build();
|
||||||
canvas.drawCircle(sky.Point.origin, radius, paint);
|
canvas.drawCircle(ui.Point.origin, radius, paint);
|
||||||
|
|
||||||
return recorder.endRecording();
|
return recorder.endRecording();
|
||||||
}
|
}
|
||||||
|
|
||||||
sky.Scene composite(sky.Picture picture, sky.Rect paintBounds) {
|
ui.Scene composite(ui.Picture picture, ui.Rect paintBounds) {
|
||||||
final double devicePixelRatio = sky.view.devicePixelRatio;
|
final double devicePixelRatio = ui.view.devicePixelRatio;
|
||||||
sky.Rect sceneBounds = new sky.Rect.fromLTWH(0.0, 0.0, sky.view.width * devicePixelRatio, sky.view.height * devicePixelRatio);
|
ui.Rect sceneBounds = new ui.Rect.fromLTWH(0.0, 0.0, ui.view.width * devicePixelRatio, ui.view.height * devicePixelRatio);
|
||||||
Float32List deviceTransform = new Float32List(16)
|
Float64List deviceTransform = new Float64List(16)
|
||||||
..[0] = devicePixelRatio
|
..[0] = devicePixelRatio
|
||||||
..[5] = devicePixelRatio
|
..[5] = devicePixelRatio
|
||||||
..[10] = 1.0
|
..[10] = 1.0
|
||||||
..[15] = 1.0;
|
..[15] = 1.0;
|
||||||
sky.SceneBuilder sceneBuilder = new sky.SceneBuilder(sceneBounds)
|
ui.SceneBuilder sceneBuilder = new ui.SceneBuilder(sceneBounds)
|
||||||
..pushTransform(deviceTransform)
|
..pushTransform(deviceTransform)
|
||||||
..addPicture(sky.Offset.zero, picture, paintBounds)
|
..addPicture(ui.Offset.zero, picture, paintBounds)
|
||||||
..pop();
|
..pop();
|
||||||
return sceneBuilder.build();
|
return sceneBuilder.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
void beginFrame(double timeStamp) {
|
void beginFrame(double timeStamp) {
|
||||||
sky.Rect paintBounds = new sky.Rect.fromLTWH(0.0, 0.0, sky.view.width, sky.view.height);
|
ui.Rect paintBounds = new ui.Rect.fromLTWH(0.0, 0.0, ui.view.width, ui.view.height);
|
||||||
sky.Picture picture = paint(paintBounds);
|
ui.Picture picture = paint(paintBounds);
|
||||||
sky.Scene scene = composite(picture, paintBounds);
|
ui.Scene scene = composite(picture, paintBounds);
|
||||||
sky.view.scene = scene;
|
ui.view.scene = scene;
|
||||||
}
|
}
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
sky.view.setFrameCallback(beginFrame);
|
ui.view.setFrameCallback(beginFrame);
|
||||||
sky.view.scheduleFrame();
|
ui.view.scheduleFrame();
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
name: raw
|
name: sky_raw_examples
|
||||||
dependencies:
|
dependencies:
|
||||||
sky: any
|
flutter: ">=0.0.3 <0.1.0"
|
||||||
sky_tools: any
|
sky_tools: any
|
||||||
dependency_overrides:
|
dependency_overrides:
|
||||||
material_design_icons:
|
material_design_icons:
|
||||||
path: ../../sky/packages/material_design_icons
|
path: ../../sky/packages/material_design_icons
|
||||||
sky:
|
flutter:
|
||||||
path: ../../sky/packages/sky
|
path: ../../sky/packages/sky
|
||||||
|
@ -2,63 +2,63 @@
|
|||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
import 'dart:sky' as sky;
|
import 'dart:ui' as ui;
|
||||||
import 'dart:typed_data';
|
import 'dart:typed_data';
|
||||||
|
|
||||||
sky.Picture paint(sky.Rect paintBounds) {
|
ui.Picture paint(ui.Rect paintBounds) {
|
||||||
sky.PictureRecorder recorder = new sky.PictureRecorder();
|
ui.PictureRecorder recorder = new ui.PictureRecorder();
|
||||||
sky.Canvas canvas = new sky.Canvas(recorder, paintBounds);
|
ui.Canvas canvas = new ui.Canvas(recorder, paintBounds);
|
||||||
|
|
||||||
double size = 100.0;
|
double size = 100.0;
|
||||||
canvas.translate(size + 10.0, size + 10.0);
|
canvas.translate(size + 10.0, size + 10.0);
|
||||||
|
|
||||||
sky.Paint paint = new sky.Paint();
|
ui.Paint paint = new ui.Paint();
|
||||||
paint.color = const sky.Color.fromARGB(255, 0, 255, 0);
|
paint.color = const ui.Color.fromARGB(255, 0, 255, 0);
|
||||||
var builder = new sky.LayerDrawLooperBuilder()
|
var builder = new ui.LayerDrawLooperBuilder()
|
||||||
// Shadow layer.
|
// Shadow layer.
|
||||||
..addLayerOnTop(
|
..addLayerOnTop(
|
||||||
new sky.DrawLooperLayerInfo()
|
new ui.DrawLooperLayerInfo()
|
||||||
..setPaintBits(sky.PaintBits.all)
|
..setPaintBits(ui.PaintBits.all)
|
||||||
..setOffset(const sky.Offset(5.0, 5.0))
|
..setOffset(const ui.Offset(5.0, 5.0))
|
||||||
..setColorMode(sky.TransferMode.src),
|
..setColorMode(ui.TransferMode.src),
|
||||||
new sky.Paint()
|
new ui.Paint()
|
||||||
..color = const sky.Color.fromARGB(128, 55, 55, 55)
|
..color = const ui.Color.fromARGB(128, 55, 55, 55)
|
||||||
..maskFilter = new sky.MaskFilter.blur(sky.BlurStyle.normal, 5.0)
|
..maskFilter = new ui.MaskFilter.blur(ui.BlurStyle.normal, 5.0)
|
||||||
)
|
)
|
||||||
// Main layer.
|
// Main layer.
|
||||||
..addLayerOnTop(new sky.DrawLooperLayerInfo(), new sky.Paint());
|
..addLayerOnTop(new ui.DrawLooperLayerInfo(), new ui.Paint());
|
||||||
paint.drawLooper = builder.build();
|
paint.drawLooper = builder.build();
|
||||||
|
|
||||||
canvas.drawPaint(
|
canvas.drawPaint(
|
||||||
new sky.Paint()..color = const sky.Color.fromARGB(255, 255, 255, 255));
|
new ui.Paint()..color = const ui.Color.fromARGB(255, 255, 255, 255));
|
||||||
canvas.drawRect(new sky.Rect.fromLTRB(-size, -size, size, size), paint);
|
canvas.drawRect(new ui.Rect.fromLTRB(-size, -size, size, size), paint);
|
||||||
|
|
||||||
return recorder.endRecording();
|
return recorder.endRecording();
|
||||||
}
|
}
|
||||||
|
|
||||||
sky.Scene composite(sky.Picture picture, sky.Rect paintBounds) {
|
ui.Scene composite(ui.Picture picture, ui.Rect paintBounds) {
|
||||||
final double devicePixelRatio = sky.view.devicePixelRatio;
|
final double devicePixelRatio = ui.view.devicePixelRatio;
|
||||||
sky.Rect sceneBounds = new sky.Rect.fromLTWH(0.0, 0.0, sky.view.width * devicePixelRatio, sky.view.height * devicePixelRatio);
|
ui.Rect sceneBounds = new ui.Rect.fromLTWH(0.0, 0.0, ui.view.width * devicePixelRatio, ui.view.height * devicePixelRatio);
|
||||||
Float64List deviceTransform = new Float64List(16)
|
Float64List deviceTransform = new Float64List(16)
|
||||||
..[0] = devicePixelRatio
|
..[0] = devicePixelRatio
|
||||||
..[5] = devicePixelRatio
|
..[5] = devicePixelRatio
|
||||||
..[10] = 1.0
|
..[10] = 1.0
|
||||||
..[15] = 1.0;
|
..[15] = 1.0;
|
||||||
sky.SceneBuilder sceneBuilder = new sky.SceneBuilder(sceneBounds)
|
ui.SceneBuilder sceneBuilder = new ui.SceneBuilder(sceneBounds)
|
||||||
..pushTransform(deviceTransform)
|
..pushTransform(deviceTransform)
|
||||||
..addPicture(sky.Offset.zero, picture, paintBounds)
|
..addPicture(ui.Offset.zero, picture, paintBounds)
|
||||||
..pop();
|
..pop();
|
||||||
return sceneBuilder.build();
|
return sceneBuilder.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
void beginFrame(double timeStamp) {
|
void beginFrame(double timeStamp) {
|
||||||
sky.Rect paintBounds = new sky.Rect.fromLTWH(0.0, 0.0, sky.view.width, sky.view.height);
|
ui.Rect paintBounds = new ui.Rect.fromLTWH(0.0, 0.0, ui.view.width, ui.view.height);
|
||||||
sky.Picture picture = paint(paintBounds);
|
ui.Picture picture = paint(paintBounds);
|
||||||
sky.Scene scene = composite(picture, paintBounds);
|
ui.Scene scene = composite(picture, paintBounds);
|
||||||
sky.view.scene = scene;
|
ui.view.scene = scene;
|
||||||
}
|
}
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
sky.view.setFrameCallback(beginFrame);
|
ui.view.setFrameCallback(beginFrame);
|
||||||
sky.view.scheduleFrame();
|
ui.view.scheduleFrame();
|
||||||
}
|
}
|
||||||
|
@ -3,20 +3,20 @@
|
|||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
import 'dart:math' as math;
|
import 'dart:math' as math;
|
||||||
import 'dart:sky' as sky;
|
import 'dart:ui' as ui;
|
||||||
import 'dart:typed_data';
|
import 'dart:typed_data';
|
||||||
|
|
||||||
double timeBase = null;
|
double timeBase = null;
|
||||||
sky.LayoutRoot layoutRoot = new sky.LayoutRoot();
|
ui.LayoutRoot layoutRoot = new ui.LayoutRoot();
|
||||||
|
|
||||||
sky.Picture paint(sky.Rect paintBounds, double delta) {
|
ui.Picture paint(ui.Rect paintBounds, double delta) {
|
||||||
sky.PictureRecorder recorder = new sky.PictureRecorder();
|
ui.PictureRecorder recorder = new ui.PictureRecorder();
|
||||||
sky.Canvas canvas = new sky.Canvas(recorder, paintBounds);
|
ui.Canvas canvas = new ui.Canvas(recorder, paintBounds);
|
||||||
|
|
||||||
canvas.translate(sky.view.width / 2.0, sky.view.height / 2.0);
|
canvas.translate(ui.view.width / 2.0, ui.view.height / 2.0);
|
||||||
canvas.rotate(math.PI * delta / 1800);
|
canvas.rotate(math.PI * delta / 1800);
|
||||||
canvas.drawRect(new sky.Rect.fromLTRB(-100.0, -100.0, 100.0, 100.0),
|
canvas.drawRect(new ui.Rect.fromLTRB(-100.0, -100.0, 100.0, 100.0),
|
||||||
new sky.Paint()..color = const sky.Color.fromARGB(255, 0, 255, 0));
|
new ui.Paint()..color = const ui.Color.fromARGB(255, 0, 255, 0));
|
||||||
|
|
||||||
double sin = math.sin(delta / 200);
|
double sin = math.sin(delta / 200);
|
||||||
layoutRoot.maxWidth = 150.0 + (50 * sin);
|
layoutRoot.maxWidth = 150.0 + (50 * sin);
|
||||||
@ -28,17 +28,17 @@ sky.Picture paint(sky.Rect paintBounds, double delta) {
|
|||||||
return recorder.endRecording();
|
return recorder.endRecording();
|
||||||
}
|
}
|
||||||
|
|
||||||
sky.Scene composite(sky.Picture picture, sky.Rect paintBounds) {
|
ui.Scene composite(ui.Picture picture, ui.Rect paintBounds) {
|
||||||
final double devicePixelRatio = sky.view.devicePixelRatio;
|
final double devicePixelRatio = ui.view.devicePixelRatio;
|
||||||
sky.Rect sceneBounds = new sky.Rect.fromLTWH(0.0, 0.0, sky.view.width * devicePixelRatio, sky.view.height * devicePixelRatio);
|
ui.Rect sceneBounds = new ui.Rect.fromLTWH(0.0, 0.0, ui.view.width * devicePixelRatio, ui.view.height * devicePixelRatio);
|
||||||
Float64List deviceTransform = new Float64List(16)
|
Float64List deviceTransform = new Float64List(16)
|
||||||
..[0] = devicePixelRatio
|
..[0] = devicePixelRatio
|
||||||
..[5] = devicePixelRatio
|
..[5] = devicePixelRatio
|
||||||
..[10] = 1.0
|
..[10] = 1.0
|
||||||
..[15] = 1.0;
|
..[15] = 1.0;
|
||||||
sky.SceneBuilder sceneBuilder = new sky.SceneBuilder(sceneBounds)
|
ui.SceneBuilder sceneBuilder = new ui.SceneBuilder(sceneBounds)
|
||||||
..pushTransform(deviceTransform)
|
..pushTransform(deviceTransform)
|
||||||
..addPicture(sky.Offset.zero, picture, paintBounds)
|
..addPicture(ui.Offset.zero, picture, paintBounds)
|
||||||
..pop();
|
..pop();
|
||||||
return sceneBuilder.build();
|
return sceneBuilder.build();
|
||||||
}
|
}
|
||||||
@ -47,15 +47,15 @@ void beginFrame(double timeStamp) {
|
|||||||
if (timeBase == null)
|
if (timeBase == null)
|
||||||
timeBase = timeStamp;
|
timeBase = timeStamp;
|
||||||
double delta = timeStamp - timeBase;
|
double delta = timeStamp - timeBase;
|
||||||
sky.Rect paintBounds = new sky.Rect.fromLTWH(0.0, 0.0, sky.view.width, sky.view.height);
|
ui.Rect paintBounds = new ui.Rect.fromLTWH(0.0, 0.0, ui.view.width, ui.view.height);
|
||||||
sky.Picture picture = paint(paintBounds, delta);
|
ui.Picture picture = paint(paintBounds, delta);
|
||||||
sky.Scene scene = composite(picture, paintBounds);
|
ui.Scene scene = composite(picture, paintBounds);
|
||||||
sky.view.scene = scene;
|
ui.view.scene = scene;
|
||||||
sky.view.scheduleFrame();
|
ui.view.scheduleFrame();
|
||||||
}
|
}
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
var document = new sky.Document();
|
var document = new ui.Document();
|
||||||
var arabic = document.createText("هذا هو قليلا طويلة من النص الذي يجب التفاف .");
|
var arabic = document.createText("هذا هو قليلا طويلة من النص الذي يجب التفاف .");
|
||||||
var more = document.createText(" و أكثر قليلا لجعله أطول. ");
|
var more = document.createText(" و أكثر قليلا لجعله أطول. ");
|
||||||
var block = document.createElement('p');
|
var block = document.createElement('p');
|
||||||
@ -68,6 +68,6 @@ void main() {
|
|||||||
|
|
||||||
layoutRoot.rootElement = block;
|
layoutRoot.rootElement = block;
|
||||||
|
|
||||||
sky.view.setFrameCallback(beginFrame);
|
ui.view.setFrameCallback(beginFrame);
|
||||||
sky.view.scheduleFrame();
|
ui.view.scheduleFrame();
|
||||||
}
|
}
|
||||||
|
@ -3,29 +3,29 @@
|
|||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
import 'dart:math' as math;
|
import 'dart:math' as math;
|
||||||
import 'dart:sky' as sky;
|
import 'dart:ui' as ui;
|
||||||
import 'dart:typed_data';
|
import 'dart:typed_data';
|
||||||
|
|
||||||
import 'package:sky/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
|
|
||||||
double timeBase = null;
|
double timeBase = null;
|
||||||
|
|
||||||
sky.Image image = null;
|
ui.Image image = null;
|
||||||
String url1 = "https://raw.githubusercontent.com/dart-lang/logos/master/logos_and_wordmarks/dart-logo.png";
|
String url1 = "https://raw.githubusercontent.com/dart-lang/logos/master/logos_and_wordmarks/dart-logo.png";
|
||||||
String url2 = "http://i2.kym-cdn.com/photos/images/facebook/000/581/296/c09.jpg";
|
String url2 = "http://i2.kym-cdn.com/photos/images/facebook/000/581/296/c09.jpg";
|
||||||
|
|
||||||
sky.Picture paint(sky.Rect paintBounds, double delta) {
|
ui.Picture paint(ui.Rect paintBounds, double delta) {
|
||||||
sky.PictureRecorder recorder = new sky.PictureRecorder();
|
ui.PictureRecorder recorder = new ui.PictureRecorder();
|
||||||
sky.Canvas canvas = new sky.Canvas(recorder, paintBounds);
|
ui.Canvas canvas = new ui.Canvas(recorder, paintBounds);
|
||||||
|
|
||||||
canvas.translate(paintBounds.width / 2.0, paintBounds.height / 2.0);
|
canvas.translate(paintBounds.width / 2.0, paintBounds.height / 2.0);
|
||||||
canvas.rotate(math.PI * delta / 1800);
|
canvas.rotate(math.PI * delta / 1800);
|
||||||
canvas.scale(0.2, 0.2);
|
canvas.scale(0.2, 0.2);
|
||||||
sky.Paint paint = new sky.Paint()..color = const sky.Color.fromARGB(255, 0, 255, 0);
|
ui.Paint paint = new ui.Paint()..color = const ui.Color.fromARGB(255, 0, 255, 0);
|
||||||
|
|
||||||
// Draw image
|
// Draw image
|
||||||
if (image != null)
|
if (image != null)
|
||||||
canvas.drawImage(image, new sky.Point(-image.width / 2.0, -image.height / 2.0), paint);
|
canvas.drawImage(image, new ui.Point(-image.width / 2.0, -image.height / 2.0), paint);
|
||||||
|
|
||||||
// Draw cut out of image
|
// Draw cut out of image
|
||||||
canvas.rotate(math.PI * delta / 1800);
|
canvas.rotate(math.PI * delta / 1800);
|
||||||
@ -33,25 +33,25 @@ sky.Picture paint(sky.Rect paintBounds, double delta) {
|
|||||||
var w = image.width.toDouble();
|
var w = image.width.toDouble();
|
||||||
var h = image.width.toDouble();
|
var h = image.width.toDouble();
|
||||||
canvas.drawImageRect(image,
|
canvas.drawImageRect(image,
|
||||||
new sky.Rect.fromLTRB(w * 0.25, h * 0.25, w * 0.75, h * 0.75),
|
new ui.Rect.fromLTRB(w * 0.25, h * 0.25, w * 0.75, h * 0.75),
|
||||||
new sky.Rect.fromLTRB(-w / 4.0, -h / 4.0, w / 4.0, h / 4.0),
|
new ui.Rect.fromLTRB(-w / 4.0, -h / 4.0, w / 4.0, h / 4.0),
|
||||||
paint);
|
paint);
|
||||||
}
|
}
|
||||||
|
|
||||||
return recorder.endRecording();
|
return recorder.endRecording();
|
||||||
}
|
}
|
||||||
|
|
||||||
sky.Scene composite(sky.Picture picture, sky.Rect paintBounds) {
|
ui.Scene composite(ui.Picture picture, ui.Rect paintBounds) {
|
||||||
final double devicePixelRatio = sky.view.devicePixelRatio;
|
final double devicePixelRatio = ui.view.devicePixelRatio;
|
||||||
sky.Rect sceneBounds = new sky.Rect.fromLTWH(0.0, 0.0, sky.view.width * devicePixelRatio, sky.view.height * devicePixelRatio);
|
ui.Rect sceneBounds = new ui.Rect.fromLTWH(0.0, 0.0, ui.view.width * devicePixelRatio, ui.view.height * devicePixelRatio);
|
||||||
Float64List deviceTransform = new Float64List(16)
|
Float64List deviceTransform = new Float64List(16)
|
||||||
..[0] = devicePixelRatio
|
..[0] = devicePixelRatio
|
||||||
..[5] = devicePixelRatio
|
..[5] = devicePixelRatio
|
||||||
..[10] = 1.0
|
..[10] = 1.0
|
||||||
..[15] = 1.0;
|
..[15] = 1.0;
|
||||||
sky.SceneBuilder sceneBuilder = new sky.SceneBuilder(sceneBounds)
|
ui.SceneBuilder sceneBuilder = new ui.SceneBuilder(sceneBounds)
|
||||||
..pushTransform(deviceTransform)
|
..pushTransform(deviceTransform)
|
||||||
..addPicture(sky.Offset.zero, picture, paintBounds)
|
..addPicture(ui.Offset.zero, picture, paintBounds)
|
||||||
..pop();
|
..pop();
|
||||||
return sceneBuilder.build();
|
return sceneBuilder.build();
|
||||||
}
|
}
|
||||||
@ -60,11 +60,11 @@ void beginFrame(double timeStamp) {
|
|||||||
if (timeBase == null)
|
if (timeBase == null)
|
||||||
timeBase = timeStamp;
|
timeBase = timeStamp;
|
||||||
double delta = timeStamp - timeBase;
|
double delta = timeStamp - timeBase;
|
||||||
sky.Rect paintBounds = new sky.Rect.fromLTWH(0.0, 0.0, sky.view.width, sky.view.height);
|
ui.Rect paintBounds = new ui.Rect.fromLTWH(0.0, 0.0, ui.view.width, ui.view.height);
|
||||||
sky.Picture picture = paint(paintBounds, delta);
|
ui.Picture picture = paint(paintBounds, delta);
|
||||||
sky.Scene scene = composite(picture, paintBounds);
|
ui.Scene scene = composite(picture, paintBounds);
|
||||||
sky.view.scene = scene;
|
ui.view.scene = scene;
|
||||||
sky.view.scheduleFrame();
|
ui.view.scheduleFrame();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -72,13 +72,13 @@ void handleImageLoad(result) {
|
|||||||
if (result != image) {
|
if (result != image) {
|
||||||
print("${result.width}x${result.width} image loaded!");
|
print("${result.width}x${result.width} image loaded!");
|
||||||
image = result;
|
image = result;
|
||||||
sky.view.scheduleFrame();
|
ui.view.scheduleFrame();
|
||||||
} else {
|
} else {
|
||||||
print("Existing image was loaded again");
|
print("Existing image was loaded again");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool handleEvent(sky.Event event) {
|
bool handleEvent(ui.Event event) {
|
||||||
if (event.type == "pointerdown") {
|
if (event.type == "pointerdown") {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -93,6 +93,6 @@ bool handleEvent(sky.Event event) {
|
|||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
imageCache.load(url1).first.then(handleImageLoad);
|
imageCache.load(url1).first.then(handleImageLoad);
|
||||||
sky.view.setEventCallback(handleEvent);
|
ui.view.setEventCallback(handleEvent);
|
||||||
sky.view.setFrameCallback(beginFrame);
|
ui.view.setFrameCallback(beginFrame);
|
||||||
}
|
}
|
||||||
|
@ -3,46 +3,46 @@
|
|||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
import 'dart:math' as math;
|
import 'dart:math' as math;
|
||||||
import 'dart:sky' as sky;
|
import 'dart:ui' as ui;
|
||||||
import 'dart:typed_data';
|
import 'dart:typed_data';
|
||||||
|
|
||||||
double timeBase = null;
|
double timeBase = null;
|
||||||
|
|
||||||
void beginFrame(double timeStamp) {
|
void beginFrame(double timeStamp) {
|
||||||
sky.tracing.begin('beginFrame');
|
ui.tracing.begin('beginFrame');
|
||||||
if (timeBase == null)
|
if (timeBase == null)
|
||||||
timeBase = timeStamp;
|
timeBase = timeStamp;
|
||||||
double delta = timeStamp - timeBase;
|
double delta = timeStamp - timeBase;
|
||||||
|
|
||||||
// paint
|
// paint
|
||||||
sky.Rect paintBounds = new sky.Rect.fromLTWH(0.0, 0.0, sky.view.width, sky.view.height);
|
ui.Rect paintBounds = new ui.Rect.fromLTWH(0.0, 0.0, ui.view.width, ui.view.height);
|
||||||
sky.PictureRecorder recorder = new sky.PictureRecorder();
|
ui.PictureRecorder recorder = new ui.PictureRecorder();
|
||||||
sky.Canvas canvas = new sky.Canvas(recorder, paintBounds);
|
ui.Canvas canvas = new ui.Canvas(recorder, paintBounds);
|
||||||
canvas.translate(paintBounds.width / 2.0, paintBounds.height / 2.0);
|
canvas.translate(paintBounds.width / 2.0, paintBounds.height / 2.0);
|
||||||
canvas.rotate(math.PI * delta / 1800);
|
canvas.rotate(math.PI * delta / 1800);
|
||||||
canvas.drawRect(new sky.Rect.fromLTRB(-100.0, -100.0, 100.0, 100.0),
|
canvas.drawRect(new ui.Rect.fromLTRB(-100.0, -100.0, 100.0, 100.0),
|
||||||
new sky.Paint()..color = const sky.Color.fromARGB(255, 0, 255, 0));
|
new ui.Paint()..color = const ui.Color.fromARGB(255, 0, 255, 0));
|
||||||
sky.Picture picture = recorder.endRecording();
|
ui.Picture picture = recorder.endRecording();
|
||||||
|
|
||||||
// composite
|
// composite
|
||||||
final double devicePixelRatio = sky.view.devicePixelRatio;
|
final double devicePixelRatio = ui.view.devicePixelRatio;
|
||||||
sky.Rect sceneBounds = new sky.Rect.fromLTWH(0.0, 0.0, sky.view.width * devicePixelRatio, sky.view.height * devicePixelRatio);
|
ui.Rect sceneBounds = new ui.Rect.fromLTWH(0.0, 0.0, ui.view.width * devicePixelRatio, ui.view.height * devicePixelRatio);
|
||||||
Float64List deviceTransform = new Float64List(16)
|
Float64List deviceTransform = new Float64List(16)
|
||||||
..[0] = devicePixelRatio
|
..[0] = devicePixelRatio
|
||||||
..[5] = devicePixelRatio
|
..[5] = devicePixelRatio
|
||||||
..[10] = 1.0
|
..[10] = 1.0
|
||||||
..[15] = 1.0;
|
..[15] = 1.0;
|
||||||
sky.SceneBuilder sceneBuilder = new sky.SceneBuilder(sceneBounds)
|
ui.SceneBuilder sceneBuilder = new ui.SceneBuilder(sceneBounds)
|
||||||
..pushTransform(deviceTransform)
|
..pushTransform(deviceTransform)
|
||||||
..addPicture(sky.Offset.zero, picture, paintBounds)
|
..addPicture(ui.Offset.zero, picture, paintBounds)
|
||||||
..pop();
|
..pop();
|
||||||
sky.view.scene = sceneBuilder.build();
|
ui.view.scene = sceneBuilder.build();
|
||||||
|
|
||||||
sky.tracing.end('beginFrame');
|
ui.tracing.end('beginFrame');
|
||||||
sky.view.scheduleFrame();
|
ui.view.scheduleFrame();
|
||||||
}
|
}
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
sky.view.setFrameCallback(beginFrame);
|
ui.view.setFrameCallback(beginFrame);
|
||||||
sky.view.scheduleFrame();
|
ui.view.scheduleFrame();
|
||||||
}
|
}
|
||||||
|
@ -1,17 +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("//sky/build/skyx.gni")
|
|
||||||
|
|
||||||
skyx("interactive_flex") {
|
|
||||||
main_dart = "interactive_flex.dart"
|
|
||||||
}
|
|
||||||
|
|
||||||
group("rendering") {
|
|
||||||
testonly = true
|
|
||||||
|
|
||||||
deps = [
|
|
||||||
":interactive_flex",
|
|
||||||
]
|
|
||||||
}
|
|
@ -2,7 +2,7 @@
|
|||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
import 'package:sky/rendering.dart';
|
import 'package:flutter/rendering.dart';
|
||||||
|
|
||||||
import 'solid_color_box.dart';
|
import 'solid_color_box.dart';
|
||||||
|
|
||||||
|
@ -2,9 +2,9 @@
|
|||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
import 'dart:sky' as sky;
|
import 'dart:ui' as ui;
|
||||||
|
|
||||||
import 'package:sky/rendering.dart';
|
import 'package:flutter/rendering.dart';
|
||||||
|
|
||||||
RenderBox getBox(double lh) {
|
RenderBox getBox(double lh) {
|
||||||
RenderParagraph paragraph = new RenderParagraph(
|
RenderParagraph paragraph = new RenderParagraph(
|
||||||
@ -50,7 +50,7 @@ RenderBox getBox(double lh) {
|
|||||||
path.lineTo(w, h);
|
path.lineTo(w, h);
|
||||||
Paint paint = new Paint();
|
Paint paint = new Paint();
|
||||||
paint.color = const Color(0xFFFF9000);
|
paint.color = const Color(0xFFFF9000);
|
||||||
paint.setStyle(sky.PaintingStyle.stroke);
|
paint.setStyle(ui.PaintingStyle.stroke);
|
||||||
paint.strokeWidth = 3.0;
|
paint.strokeWidth = 3.0;
|
||||||
canvas.drawPath(path, paint);
|
canvas.drawPath(path, paint);
|
||||||
}
|
}
|
||||||
|
@ -2,9 +2,9 @@
|
|||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
import 'dart:sky' as sky;
|
import 'dart:ui' as ui;
|
||||||
|
|
||||||
import 'package:sky/rendering.dart';
|
import 'package:flutter/rendering.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
var root = new RenderFlex(
|
var root = new RenderFlex(
|
||||||
@ -15,7 +15,7 @@ void main() {
|
|||||||
additionalConstraints: new BoxConstraints.tightFor(height: 100.0),
|
additionalConstraints: new BoxConstraints.tightFor(height: 100.0),
|
||||||
child: new RenderDecoratedBox(
|
child: new RenderDecoratedBox(
|
||||||
decoration: new BoxDecoration(
|
decoration: new BoxDecoration(
|
||||||
backgroundColor: new sky.Color(0xFFFFFF00)
|
backgroundColor: new ui.Color(0xFFFFFF00)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@ -27,12 +27,12 @@ void main() {
|
|||||||
child: new RenderDecoratedBox(
|
child: new RenderDecoratedBox(
|
||||||
decoration: new BoxDecoration(
|
decoration: new BoxDecoration(
|
||||||
border: new Border(
|
border: new Border(
|
||||||
top: new BorderSide(color: new sky.Color(0xFFF00000), width: 5.0),
|
top: new BorderSide(color: new ui.Color(0xFFF00000), width: 5.0),
|
||||||
right: new BorderSide(color: new sky.Color(0xFFFF9000), width: 10.0),
|
right: new BorderSide(color: new ui.Color(0xFFFF9000), width: 10.0),
|
||||||
bottom: new BorderSide(color: new sky.Color(0xFFFFF000), width: 15.0),
|
bottom: new BorderSide(color: new ui.Color(0xFFFFF000), width: 15.0),
|
||||||
left: new BorderSide(color: new sky.Color(0xFF00FF00), width: 20.0)
|
left: new BorderSide(color: new ui.Color(0xFF00FF00), width: 20.0)
|
||||||
),
|
),
|
||||||
backgroundColor: new sky.Color(0xFFDDDDDD)
|
backgroundColor: new ui.Color(0xFFDDDDDD)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@ -43,7 +43,7 @@ void main() {
|
|||||||
additionalConstraints: new BoxConstraints.tightFor(height: 100.0),
|
additionalConstraints: new BoxConstraints.tightFor(height: 100.0),
|
||||||
child: new RenderDecoratedBox(
|
child: new RenderDecoratedBox(
|
||||||
decoration: new BoxDecoration(
|
decoration: new BoxDecoration(
|
||||||
backgroundColor: new sky.Color(0xFFFFFF00)
|
backgroundColor: new ui.Color(0xFFFFFF00)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@ -54,7 +54,7 @@ void main() {
|
|||||||
additionalConstraints: new BoxConstraints.tightFor(height: 100.0),
|
additionalConstraints: new BoxConstraints.tightFor(height: 100.0),
|
||||||
child: new RenderDecoratedBox(
|
child: new RenderDecoratedBox(
|
||||||
decoration: new BoxDecoration(
|
decoration: new BoxDecoration(
|
||||||
backgroundColor: new sky.Color(0xFFFFFF00)
|
backgroundColor: new ui.Color(0xFFFFFF00)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@ -65,7 +65,7 @@ void main() {
|
|||||||
additionalConstraints: new BoxConstraints.tightFor(height: 100.0),
|
additionalConstraints: new BoxConstraints.tightFor(height: 100.0),
|
||||||
child: new RenderDecoratedBox(
|
child: new RenderDecoratedBox(
|
||||||
decoration: new BoxDecoration(
|
decoration: new BoxDecoration(
|
||||||
backgroundColor: new sky.Color(0xFFFFFF00)
|
backgroundColor: new ui.Color(0xFFFFFF00)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
@ -2,33 +2,33 @@
|
|||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
import 'dart:sky' as sky;
|
import 'dart:ui' as ui;
|
||||||
|
|
||||||
import 'package:sky/rendering.dart';
|
import 'package:flutter/rendering.dart';
|
||||||
import 'solid_color_box.dart';
|
import 'solid_color_box.dart';
|
||||||
|
|
||||||
RenderBox buildFlexExample() {
|
RenderBox buildFlexExample() {
|
||||||
RenderFlex flexRoot = new RenderFlex(direction: FlexDirection.vertical);
|
RenderFlex flexRoot = new RenderFlex(direction: FlexDirection.vertical);
|
||||||
|
|
||||||
RenderDecoratedBox root = new RenderDecoratedBox(
|
RenderDecoratedBox root = new RenderDecoratedBox(
|
||||||
decoration: new BoxDecoration(backgroundColor: const sky.Color(0xFF000000)),
|
decoration: new BoxDecoration(backgroundColor: const ui.Color(0xFF000000)),
|
||||||
child: flexRoot
|
child: flexRoot
|
||||||
);
|
);
|
||||||
|
|
||||||
void addFlexChildSolidColor(RenderFlex parent, sky.Color backgroundColor, { int flex: 0 }) {
|
void addFlexChildSolidColor(RenderFlex parent, ui.Color backgroundColor, { int flex: 0 }) {
|
||||||
RenderSolidColorBox child = new RenderSolidColorBox(backgroundColor);
|
RenderSolidColorBox child = new RenderSolidColorBox(backgroundColor);
|
||||||
parent.add(child);
|
parent.add(child);
|
||||||
child.parentData.flex = flex;
|
child.parentData.flex = flex;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Yellow bar at top
|
// Yellow bar at top
|
||||||
addFlexChildSolidColor(flexRoot, const sky.Color(0xFFFFFF00), flex: 1);
|
addFlexChildSolidColor(flexRoot, const ui.Color(0xFFFFFF00), flex: 1);
|
||||||
|
|
||||||
// Turquoise box
|
// Turquoise box
|
||||||
flexRoot.add(new RenderSolidColorBox(const sky.Color(0x7700FFFF), desiredSize: new sky.Size(100.0, 100.0)));
|
flexRoot.add(new RenderSolidColorBox(const ui.Color(0x7700FFFF), desiredSize: new ui.Size(100.0, 100.0)));
|
||||||
|
|
||||||
var renderDecoratedBlock = new RenderDecoratedBox(
|
var renderDecoratedBlock = new RenderDecoratedBox(
|
||||||
decoration: new BoxDecoration(backgroundColor: const sky.Color(0xFFFFFFFF))
|
decoration: new BoxDecoration(backgroundColor: const ui.Color(0xFFFFFFFF))
|
||||||
);
|
);
|
||||||
|
|
||||||
flexRoot.add(new RenderPadding(padding: const EdgeDims.all(10.0), child: renderDecoratedBlock));
|
flexRoot.add(new RenderPadding(padding: const EdgeDims.all(10.0), child: renderDecoratedBlock));
|
||||||
@ -36,11 +36,11 @@ RenderBox buildFlexExample() {
|
|||||||
var row = new RenderFlex(direction: FlexDirection.horizontal);
|
var row = new RenderFlex(direction: FlexDirection.horizontal);
|
||||||
|
|
||||||
// Purple and blue cells
|
// Purple and blue cells
|
||||||
addFlexChildSolidColor(row, const sky.Color(0x77FF00FF), flex: 1);
|
addFlexChildSolidColor(row, const ui.Color(0x77FF00FF), flex: 1);
|
||||||
addFlexChildSolidColor(row, const sky.Color(0xFF0000FF), flex: 2);
|
addFlexChildSolidColor(row, const ui.Color(0xFF0000FF), flex: 2);
|
||||||
|
|
||||||
var decoratedRow = new RenderDecoratedBox(
|
var decoratedRow = new RenderDecoratedBox(
|
||||||
decoration: new BoxDecoration(backgroundColor: const sky.Color(0xFF333333)),
|
decoration: new BoxDecoration(backgroundColor: const ui.Color(0xFF333333)),
|
||||||
child: row
|
child: row
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -2,11 +2,11 @@
|
|||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
import 'dart:sky' as sky;
|
import 'dart:ui' as ui;
|
||||||
import 'dart:math' as math;
|
import 'dart:math' as math;
|
||||||
|
|
||||||
import 'package:sky/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:sky/rendering.dart';
|
import 'package:flutter/rendering.dart';
|
||||||
|
|
||||||
import 'solid_color_box.dart';
|
import 'solid_color_box.dart';
|
||||||
|
|
||||||
@ -19,7 +19,7 @@ class Touch {
|
|||||||
class RenderImageGrow extends RenderImage {
|
class RenderImageGrow extends RenderImage {
|
||||||
final Size _startingSize;
|
final Size _startingSize;
|
||||||
|
|
||||||
RenderImageGrow(sky.Image image, Size size)
|
RenderImageGrow(ui.Image image, Size size)
|
||||||
: _startingSize = size, super(image: image, width: size.width, height: size.height);
|
: _startingSize = size, super(image: image, width: size.width, height: size.height);
|
||||||
|
|
||||||
double _growth = 0.0;
|
double _growth = 0.0;
|
||||||
@ -35,7 +35,7 @@ RenderImageGrow image;
|
|||||||
|
|
||||||
Map<int, Touch> touches = new Map();
|
Map<int, Touch> touches = new Map();
|
||||||
void handleEvent(event) {
|
void handleEvent(event) {
|
||||||
if (event is sky.PointerEvent) {
|
if (event is ui.PointerEvent) {
|
||||||
if (event.type == 'pointermove')
|
if (event.type == 'pointermove')
|
||||||
image.growth = math.max(0.0, image.growth + event.x - touches[event.pointer].x);
|
image.growth = math.max(0.0, image.growth + event.x - touches[event.pointer].x);
|
||||||
touches[event.pointer] = new Touch(event.x, event.y);
|
touches[event.pointer] = new Touch(event.x, event.y);
|
||||||
@ -59,7 +59,7 @@ void main() {
|
|||||||
|
|
||||||
// Resizeable image
|
// Resizeable image
|
||||||
image = new RenderImageGrow(null, new Size(100.0, null));
|
image = new RenderImageGrow(null, new Size(100.0, null));
|
||||||
imageCache.load("https://www.dartlang.org/logos/dart-logo.png").first.then((sky.Image dartLogo) {
|
imageCache.load("https://www.dartlang.org/logos/dart-logo.png").first.then((ui.Image dartLogo) {
|
||||||
image.image = dartLogo;
|
image.image = dartLogo;
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -99,5 +99,5 @@ Pancetta meatball tongue tenderloin rump tail jowl boudin.""";
|
|||||||
|
|
||||||
updateTaskDescription('Interactive Flex', topColor);
|
updateTaskDescription('Interactive Flex', topColor);
|
||||||
new FlutterBinding(root: root);
|
new FlutterBinding(root: root);
|
||||||
sky.view.setEventCallback(handleEvent);
|
ui.view.setEventCallback(handleEvent);
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
import 'package:sky/rendering.dart';
|
import 'package:flutter/rendering.dart';
|
||||||
|
|
||||||
import 'solid_color_box.dart';
|
import 'solid_color_box.dart';
|
||||||
|
|
||||||
|
527
examples/rendering/lib/sector_layout.dart
Normal file
@ -0,0 +1,527 @@
|
|||||||
|
// 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 'package:flutter/rendering.dart';
|
||||||
|
import 'package:flutter/gestures.dart';
|
||||||
|
|
||||||
|
const double kTwoPi = 2 * math.PI;
|
||||||
|
|
||||||
|
class SectorConstraints extends Constraints {
|
||||||
|
const SectorConstraints({
|
||||||
|
this.minDeltaRadius: 0.0,
|
||||||
|
this.maxDeltaRadius: double.INFINITY,
|
||||||
|
this.minDeltaTheta: 0.0,
|
||||||
|
this.maxDeltaTheta: kTwoPi
|
||||||
|
});
|
||||||
|
|
||||||
|
const SectorConstraints.tight({ double deltaRadius: 0.0, double deltaTheta: 0.0 })
|
||||||
|
: minDeltaRadius = deltaRadius,
|
||||||
|
maxDeltaRadius = deltaRadius,
|
||||||
|
minDeltaTheta = deltaTheta,
|
||||||
|
maxDeltaTheta = deltaTheta;
|
||||||
|
|
||||||
|
final double minDeltaRadius;
|
||||||
|
final double maxDeltaRadius;
|
||||||
|
final double minDeltaTheta;
|
||||||
|
final double maxDeltaTheta;
|
||||||
|
|
||||||
|
double constrainDeltaRadius(double deltaRadius) {
|
||||||
|
return clamp(min: minDeltaRadius, max: maxDeltaRadius, value: deltaRadius);
|
||||||
|
}
|
||||||
|
|
||||||
|
double constrainDeltaTheta(double deltaTheta) {
|
||||||
|
return clamp(min: minDeltaTheta, max: maxDeltaTheta, value: deltaTheta);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool get isTight => minDeltaTheta >= maxDeltaTheta && minDeltaTheta >= maxDeltaTheta;
|
||||||
|
}
|
||||||
|
|
||||||
|
class SectorDimensions {
|
||||||
|
const SectorDimensions({ this.deltaRadius: 0.0, this.deltaTheta: 0.0 });
|
||||||
|
|
||||||
|
factory SectorDimensions.withConstraints(
|
||||||
|
SectorConstraints constraints,
|
||||||
|
{ double deltaRadius: 0.0, double deltaTheta: 0.0 }
|
||||||
|
) {
|
||||||
|
return new SectorDimensions(
|
||||||
|
deltaRadius: constraints.constrainDeltaRadius(deltaRadius),
|
||||||
|
deltaTheta: constraints.constrainDeltaTheta(deltaTheta)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
final double deltaRadius;
|
||||||
|
final double deltaTheta;
|
||||||
|
}
|
||||||
|
|
||||||
|
class SectorParentData extends ParentData {
|
||||||
|
double radius = 0.0;
|
||||||
|
double theta = 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract class RenderSector extends RenderObject {
|
||||||
|
|
||||||
|
void setupParentData(RenderObject child) {
|
||||||
|
if (child.parentData is! SectorParentData)
|
||||||
|
child.parentData = new SectorParentData();
|
||||||
|
}
|
||||||
|
|
||||||
|
// RenderSectors always use SectorParentData subclasses, as they need to be
|
||||||
|
// able to read their position information for painting and hit testing.
|
||||||
|
SectorParentData get parentData => super.parentData;
|
||||||
|
|
||||||
|
SectorDimensions getIntrinsicDimensions(SectorConstraints constraints, double radius) {
|
||||||
|
return new SectorDimensions.withConstraints(constraints);
|
||||||
|
}
|
||||||
|
|
||||||
|
SectorConstraints get constraints => super.constraints;
|
||||||
|
bool debugDoesMeetConstraints() {
|
||||||
|
assert(constraints != null);
|
||||||
|
assert(deltaRadius != null);
|
||||||
|
assert(deltaRadius < double.INFINITY);
|
||||||
|
assert(deltaTheta != null);
|
||||||
|
assert(deltaTheta < double.INFINITY);
|
||||||
|
return constraints.minDeltaRadius <= deltaRadius &&
|
||||||
|
deltaRadius <= math.max(constraints.minDeltaRadius, constraints.maxDeltaRadius) &&
|
||||||
|
constraints.minDeltaTheta <= deltaTheta &&
|
||||||
|
deltaTheta <= math.max(constraints.minDeltaTheta, constraints.maxDeltaTheta);
|
||||||
|
}
|
||||||
|
void performResize() {
|
||||||
|
// default behaviour for subclasses that have sizedByParent = true
|
||||||
|
deltaRadius = constraints.constrainDeltaRadius(0.0);
|
||||||
|
deltaTheta = constraints.constrainDeltaTheta(0.0);
|
||||||
|
}
|
||||||
|
void performLayout() {
|
||||||
|
// descendants have to either override performLayout() to set both
|
||||||
|
// the dimensions and lay out children, or, set sizedByParent to
|
||||||
|
// true so that performResize()'s logic above does its thing.
|
||||||
|
assert(sizedByParent);
|
||||||
|
}
|
||||||
|
|
||||||
|
Rect get paintBounds => new Rect.fromLTWH(0.0, 0.0, 2.0 * deltaRadius, 2.0 * deltaRadius);
|
||||||
|
|
||||||
|
bool hitTest(HitTestResult result, { double radius, double theta }) {
|
||||||
|
if (radius < parentData.radius || radius >= parentData.radius + deltaRadius ||
|
||||||
|
theta < parentData.theta || theta >= parentData.theta + deltaTheta)
|
||||||
|
return false;
|
||||||
|
hitTestChildren(result, radius: radius, theta: theta);
|
||||||
|
result.add(new HitTestEntry(this));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
void hitTestChildren(HitTestResult result, { double radius, double theta }) { }
|
||||||
|
|
||||||
|
double deltaRadius;
|
||||||
|
double deltaTheta;
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract class RenderDecoratedSector extends RenderSector {
|
||||||
|
|
||||||
|
RenderDecoratedSector(BoxDecoration decoration) : _decoration = decoration;
|
||||||
|
|
||||||
|
BoxDecoration _decoration;
|
||||||
|
BoxDecoration get decoration => _decoration;
|
||||||
|
void set decoration (BoxDecoration value) {
|
||||||
|
if (value == _decoration)
|
||||||
|
return;
|
||||||
|
_decoration = value;
|
||||||
|
markNeedsPaint();
|
||||||
|
}
|
||||||
|
|
||||||
|
// offset must point to the center of the circle
|
||||||
|
void paint(PaintingContext context, Offset offset) {
|
||||||
|
assert(deltaRadius != null);
|
||||||
|
assert(deltaTheta != null);
|
||||||
|
assert(parentData is SectorParentData);
|
||||||
|
|
||||||
|
if (_decoration == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (_decoration.backgroundColor != null) {
|
||||||
|
final PaintingCanvas canvas = context.canvas;
|
||||||
|
Paint paint = new Paint()..color = _decoration.backgroundColor;
|
||||||
|
Path path = new Path();
|
||||||
|
double outerRadius = (parentData.radius + deltaRadius);
|
||||||
|
Rect outerBounds = new Rect.fromLTRB(offset.dx-outerRadius, offset.dy-outerRadius, offset.dx+outerRadius, offset.dy+outerRadius);
|
||||||
|
path.arcTo(outerBounds, parentData.theta, deltaTheta, true);
|
||||||
|
double innerRadius = parentData.radius;
|
||||||
|
Rect innerBounds = new Rect.fromLTRB(offset.dx-innerRadius, offset.dy-innerRadius, offset.dx+innerRadius, offset.dy+innerRadius);
|
||||||
|
path.arcTo(innerBounds, parentData.theta + deltaTheta, -deltaTheta, false);
|
||||||
|
path.close();
|
||||||
|
canvas.drawPath(path, paint);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
class SectorChildListParentData extends SectorParentData with ContainerParentDataMixin<RenderSector> { }
|
||||||
|
|
||||||
|
class RenderSectorWithChildren extends RenderDecoratedSector with ContainerRenderObjectMixin<RenderSector, SectorChildListParentData> {
|
||||||
|
RenderSectorWithChildren(BoxDecoration decoration) : super(decoration);
|
||||||
|
|
||||||
|
void hitTestChildren(HitTestResult result, { double radius, double theta }) {
|
||||||
|
RenderSector child = lastChild;
|
||||||
|
while (child != null) {
|
||||||
|
if (child.hitTest(result, radius: radius, theta: theta))
|
||||||
|
return;
|
||||||
|
final SectorChildListParentData childParentData = child.parentData;
|
||||||
|
child = childParentData.previousSibling;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void visitChildren(RenderObjectVisitor visitor) {
|
||||||
|
RenderSector child = lastChild;
|
||||||
|
while (child != null) {
|
||||||
|
visitor(child);
|
||||||
|
final SectorChildListParentData childParentData = child.parentData;
|
||||||
|
child = childParentData.previousSibling;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class RenderSectorRing extends RenderSectorWithChildren {
|
||||||
|
// lays out RenderSector children in a ring
|
||||||
|
|
||||||
|
RenderSectorRing({
|
||||||
|
BoxDecoration decoration,
|
||||||
|
double deltaRadius: double.INFINITY,
|
||||||
|
double padding: 0.0
|
||||||
|
}) : _padding = padding, _desiredDeltaRadius = deltaRadius, super(decoration);
|
||||||
|
|
||||||
|
double _desiredDeltaRadius;
|
||||||
|
double get desiredDeltaRadius => _desiredDeltaRadius;
|
||||||
|
void set desiredDeltaRadius(double value) {
|
||||||
|
assert(value != null);
|
||||||
|
if (_desiredDeltaRadius != value) {
|
||||||
|
_desiredDeltaRadius = value;
|
||||||
|
markNeedsLayout();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
double _padding;
|
||||||
|
double get padding => _padding;
|
||||||
|
void set padding(double value) {
|
||||||
|
// TODO(ianh): avoid code duplication
|
||||||
|
assert(value != null);
|
||||||
|
if (_padding != value) {
|
||||||
|
_padding = value;
|
||||||
|
markNeedsLayout();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void setupParentData(RenderObject child) {
|
||||||
|
// TODO(ianh): avoid code duplication
|
||||||
|
if (child.parentData is! SectorChildListParentData)
|
||||||
|
child.parentData = new SectorChildListParentData();
|
||||||
|
}
|
||||||
|
|
||||||
|
SectorDimensions getIntrinsicDimensions(SectorConstraints constraints, double radius) {
|
||||||
|
double outerDeltaRadius = constraints.constrainDeltaRadius(desiredDeltaRadius);
|
||||||
|
double innerDeltaRadius = outerDeltaRadius - padding * 2.0;
|
||||||
|
double childRadius = radius + padding;
|
||||||
|
double paddingTheta = math.atan(padding / (radius + outerDeltaRadius));
|
||||||
|
double innerTheta = paddingTheta; // increments with each child
|
||||||
|
double remainingDeltaTheta = constraints.maxDeltaTheta - (innerTheta + paddingTheta);
|
||||||
|
RenderSector child = firstChild;
|
||||||
|
while (child != null) {
|
||||||
|
SectorConstraints innerConstraints = new SectorConstraints(
|
||||||
|
maxDeltaRadius: innerDeltaRadius,
|
||||||
|
maxDeltaTheta: remainingDeltaTheta
|
||||||
|
);
|
||||||
|
SectorDimensions childDimensions = child.getIntrinsicDimensions(innerConstraints, childRadius);
|
||||||
|
innerTheta += childDimensions.deltaTheta;
|
||||||
|
remainingDeltaTheta -= childDimensions.deltaTheta;
|
||||||
|
final SectorChildListParentData childParentData = child.parentData;
|
||||||
|
child = childParentData.nextSibling;
|
||||||
|
if (child != null) {
|
||||||
|
innerTheta += paddingTheta;
|
||||||
|
remainingDeltaTheta -= paddingTheta;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new SectorDimensions.withConstraints(constraints,
|
||||||
|
deltaRadius: outerDeltaRadius,
|
||||||
|
deltaTheta: innerTheta);
|
||||||
|
}
|
||||||
|
|
||||||
|
void performLayout() {
|
||||||
|
assert(this.parentData is SectorParentData);
|
||||||
|
deltaRadius = constraints.constrainDeltaRadius(desiredDeltaRadius);
|
||||||
|
assert(deltaRadius < double.INFINITY);
|
||||||
|
double innerDeltaRadius = deltaRadius - padding * 2.0;
|
||||||
|
double childRadius = this.parentData.radius + padding;
|
||||||
|
double paddingTheta = math.atan(padding / (this.parentData.radius + deltaRadius));
|
||||||
|
double innerTheta = paddingTheta; // increments with each child
|
||||||
|
double remainingDeltaTheta = constraints.maxDeltaTheta - (innerTheta + paddingTheta);
|
||||||
|
RenderSector child = firstChild;
|
||||||
|
while (child != null) {
|
||||||
|
SectorConstraints innerConstraints = new SectorConstraints(
|
||||||
|
maxDeltaRadius: innerDeltaRadius,
|
||||||
|
maxDeltaTheta: remainingDeltaTheta
|
||||||
|
);
|
||||||
|
assert(child.parentData is SectorParentData);
|
||||||
|
child.parentData.theta = innerTheta;
|
||||||
|
child.parentData.radius = childRadius;
|
||||||
|
child.layout(innerConstraints, parentUsesSize: true);
|
||||||
|
innerTheta += child.deltaTheta;
|
||||||
|
remainingDeltaTheta -= child.deltaTheta;
|
||||||
|
final SectorChildListParentData childParentData = child.parentData;
|
||||||
|
child = childParentData.nextSibling;
|
||||||
|
if (child != null) {
|
||||||
|
innerTheta += paddingTheta;
|
||||||
|
remainingDeltaTheta -= paddingTheta;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
deltaTheta = innerTheta;
|
||||||
|
}
|
||||||
|
|
||||||
|
// offset must point to the center of our circle
|
||||||
|
// each sector then knows how to paint itself at its location
|
||||||
|
void paint(PaintingContext context, Offset offset) {
|
||||||
|
// TODO(ianh): avoid code duplication
|
||||||
|
super.paint(context, offset);
|
||||||
|
RenderSector child = firstChild;
|
||||||
|
while (child != null) {
|
||||||
|
context.paintChild(child, offset.toPoint());
|
||||||
|
final SectorChildListParentData childParentData = child.parentData;
|
||||||
|
child = childParentData.nextSibling;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
class RenderSectorSlice extends RenderSectorWithChildren {
|
||||||
|
// lays out RenderSector children in a stack
|
||||||
|
|
||||||
|
RenderSectorSlice({
|
||||||
|
BoxDecoration decoration,
|
||||||
|
double deltaTheta: kTwoPi,
|
||||||
|
double padding: 0.0
|
||||||
|
}) : _padding = padding, _desiredDeltaTheta = deltaTheta, super(decoration);
|
||||||
|
|
||||||
|
double _desiredDeltaTheta;
|
||||||
|
double get desiredDeltaTheta => _desiredDeltaTheta;
|
||||||
|
void set desiredDeltaTheta(double value) {
|
||||||
|
assert(value != null);
|
||||||
|
if (_desiredDeltaTheta != value) {
|
||||||
|
_desiredDeltaTheta = value;
|
||||||
|
markNeedsLayout();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
double _padding;
|
||||||
|
double get padding => _padding;
|
||||||
|
void set padding(double value) {
|
||||||
|
// TODO(ianh): avoid code duplication
|
||||||
|
assert(value != null);
|
||||||
|
if (_padding != value) {
|
||||||
|
_padding = value;
|
||||||
|
markNeedsLayout();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void setupParentData(RenderObject child) {
|
||||||
|
// TODO(ianh): avoid code duplication
|
||||||
|
if (child.parentData is! SectorChildListParentData)
|
||||||
|
child.parentData = new SectorChildListParentData();
|
||||||
|
}
|
||||||
|
|
||||||
|
SectorDimensions getIntrinsicDimensions(SectorConstraints constraints, double radius) {
|
||||||
|
assert(this.parentData is SectorParentData);
|
||||||
|
double paddingTheta = math.atan(padding / this.parentData.radius);
|
||||||
|
double outerDeltaTheta = constraints.constrainDeltaTheta(desiredDeltaTheta);
|
||||||
|
double innerDeltaTheta = outerDeltaTheta - paddingTheta * 2.0;
|
||||||
|
double childRadius = this.parentData.radius + padding;
|
||||||
|
double remainingDeltaRadius = constraints.maxDeltaRadius - (padding * 2.0);
|
||||||
|
RenderSector child = firstChild;
|
||||||
|
while (child != null) {
|
||||||
|
SectorConstraints innerConstraints = new SectorConstraints(
|
||||||
|
maxDeltaRadius: remainingDeltaRadius,
|
||||||
|
maxDeltaTheta: innerDeltaTheta
|
||||||
|
);
|
||||||
|
SectorDimensions childDimensions = child.getIntrinsicDimensions(innerConstraints, childRadius);
|
||||||
|
childRadius += childDimensions.deltaRadius;
|
||||||
|
remainingDeltaRadius -= childDimensions.deltaRadius;
|
||||||
|
final SectorChildListParentData childParentData = child.parentData;
|
||||||
|
child = childParentData.nextSibling;
|
||||||
|
childRadius += padding;
|
||||||
|
remainingDeltaRadius -= padding;
|
||||||
|
}
|
||||||
|
return new SectorDimensions.withConstraints(constraints,
|
||||||
|
deltaRadius: childRadius - this.parentData.radius,
|
||||||
|
deltaTheta: outerDeltaTheta);
|
||||||
|
}
|
||||||
|
|
||||||
|
void performLayout() {
|
||||||
|
assert(this.parentData is SectorParentData);
|
||||||
|
deltaTheta = constraints.constrainDeltaTheta(desiredDeltaTheta);
|
||||||
|
assert(deltaTheta <= kTwoPi);
|
||||||
|
double paddingTheta = math.atan(padding / this.parentData.radius);
|
||||||
|
double innerTheta = this.parentData.theta + paddingTheta;
|
||||||
|
double innerDeltaTheta = deltaTheta - paddingTheta * 2.0;
|
||||||
|
double childRadius = this.parentData.radius + padding;
|
||||||
|
double remainingDeltaRadius = constraints.maxDeltaRadius - (padding * 2.0);
|
||||||
|
RenderSector child = firstChild;
|
||||||
|
while (child != null) {
|
||||||
|
SectorConstraints innerConstraints = new SectorConstraints(
|
||||||
|
maxDeltaRadius: remainingDeltaRadius,
|
||||||
|
maxDeltaTheta: innerDeltaTheta
|
||||||
|
);
|
||||||
|
child.parentData.theta = innerTheta;
|
||||||
|
child.parentData.radius = childRadius;
|
||||||
|
child.layout(innerConstraints, parentUsesSize: true);
|
||||||
|
childRadius += child.deltaRadius;
|
||||||
|
remainingDeltaRadius -= child.deltaRadius;
|
||||||
|
final SectorChildListParentData childParentData = child.parentData;
|
||||||
|
child = childParentData.nextSibling;
|
||||||
|
childRadius += padding;
|
||||||
|
remainingDeltaRadius -= padding;
|
||||||
|
}
|
||||||
|
deltaRadius = childRadius - this.parentData.radius;
|
||||||
|
}
|
||||||
|
|
||||||
|
// offset must point to the center of our circle
|
||||||
|
// each sector then knows how to paint itself at its location
|
||||||
|
void paint(PaintingContext context, Offset offset) {
|
||||||
|
// TODO(ianh): avoid code duplication
|
||||||
|
super.paint(context, offset);
|
||||||
|
RenderSector child = firstChild;
|
||||||
|
while (child != null) {
|
||||||
|
assert(child.parentData is SectorChildListParentData);
|
||||||
|
context.paintChild(child, offset.toPoint());
|
||||||
|
final SectorChildListParentData childParentData = child.parentData;
|
||||||
|
child = childParentData.nextSibling;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
class RenderBoxToRenderSectorAdapter extends RenderBox with RenderObjectWithChildMixin<RenderSector> {
|
||||||
|
|
||||||
|
RenderBoxToRenderSectorAdapter({ double innerRadius: 0.0, RenderSector child }) :
|
||||||
|
_innerRadius = innerRadius {
|
||||||
|
this.child = child;
|
||||||
|
}
|
||||||
|
|
||||||
|
double _innerRadius;
|
||||||
|
double get innerRadius => _innerRadius;
|
||||||
|
void set innerRadius(double value) {
|
||||||
|
_innerRadius = value;
|
||||||
|
markNeedsLayout();
|
||||||
|
}
|
||||||
|
|
||||||
|
void setupParentData(RenderObject child) {
|
||||||
|
if (child.parentData is! SectorParentData)
|
||||||
|
child.parentData = new SectorParentData();
|
||||||
|
}
|
||||||
|
|
||||||
|
double getMinIntrinsicWidth(BoxConstraints constraints) {
|
||||||
|
if (child == null)
|
||||||
|
return super.getMinIntrinsicWidth(constraints);
|
||||||
|
return getIntrinsicDimensions(constraints).width;
|
||||||
|
}
|
||||||
|
|
||||||
|
double getMaxIntrinsicWidth(BoxConstraints constraints) {
|
||||||
|
if (child == null)
|
||||||
|
return super.getMaxIntrinsicWidth(constraints);
|
||||||
|
return getIntrinsicDimensions(constraints).width;
|
||||||
|
}
|
||||||
|
|
||||||
|
double getMinIntrinsicHeight(BoxConstraints constraints) {
|
||||||
|
if (child == null)
|
||||||
|
return super.getMinIntrinsicHeight(constraints);
|
||||||
|
return getIntrinsicDimensions(constraints).height;
|
||||||
|
}
|
||||||
|
|
||||||
|
double getMaxIntrinsicHeight(BoxConstraints constraints) {
|
||||||
|
if (child == null)
|
||||||
|
return super.getMaxIntrinsicHeight(constraints);
|
||||||
|
return getIntrinsicDimensions(constraints).height;
|
||||||
|
}
|
||||||
|
|
||||||
|
Size getIntrinsicDimensions(BoxConstraints constraints) {
|
||||||
|
assert(child is RenderSector);
|
||||||
|
assert(child.parentData is SectorParentData);
|
||||||
|
assert(constraints.maxWidth < double.INFINITY || constraints.maxHeight < double.INFINITY);
|
||||||
|
double maxChildDeltaRadius = math.min(constraints.maxWidth, constraints.maxHeight) / 2.0 - innerRadius;
|
||||||
|
SectorDimensions childDimensions = child.getIntrinsicDimensions(new SectorConstraints(maxDeltaRadius: maxChildDeltaRadius), innerRadius);
|
||||||
|
double dimension = (innerRadius + childDimensions.deltaRadius) * 2.0;
|
||||||
|
return constraints.constrain(new Size(dimension, dimension));
|
||||||
|
}
|
||||||
|
|
||||||
|
void performLayout() {
|
||||||
|
if (child == null) {
|
||||||
|
size = constraints.constrain(Size.zero);
|
||||||
|
} else {
|
||||||
|
assert(child is RenderSector);
|
||||||
|
assert(constraints.maxWidth < double.INFINITY || constraints.maxHeight < double.INFINITY);
|
||||||
|
double maxChildDeltaRadius = math.min(constraints.maxWidth, constraints.maxHeight) / 2.0 - innerRadius;
|
||||||
|
assert(child.parentData is SectorParentData);
|
||||||
|
child.parentData.radius = innerRadius;
|
||||||
|
child.parentData.theta = 0.0;
|
||||||
|
child.layout(new SectorConstraints(maxDeltaRadius: maxChildDeltaRadius), parentUsesSize: true);
|
||||||
|
double dimension = (innerRadius + child.deltaRadius) * 2.0;
|
||||||
|
size = constraints.constrain(new Size(dimension, dimension));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void paint(PaintingContext context, Offset offset) {
|
||||||
|
super.paint(context, offset);
|
||||||
|
if (child != null) {
|
||||||
|
Rect bounds = offset & size;
|
||||||
|
// we move the offset to the center of the circle for the RenderSectors
|
||||||
|
context.paintChild(child, bounds.center);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool hitTest(HitTestResult result, { Point position }) {
|
||||||
|
if (child == null)
|
||||||
|
return false;
|
||||||
|
double x = position.x;
|
||||||
|
double y = position.y;
|
||||||
|
// translate to our origin
|
||||||
|
x -= size.width/2.0;
|
||||||
|
y -= size.height/2.0;
|
||||||
|
// convert to radius/theta
|
||||||
|
double radius = math.sqrt(x*x+y*y);
|
||||||
|
double theta = (math.atan2(x, -y) - math.PI/2.0) % kTwoPi;
|
||||||
|
if (radius < innerRadius)
|
||||||
|
return false;
|
||||||
|
if (radius >= innerRadius + child.deltaRadius)
|
||||||
|
return false;
|
||||||
|
if (theta > child.deltaTheta)
|
||||||
|
return false;
|
||||||
|
child.hitTest(result, radius: radius, theta: theta);
|
||||||
|
result.add(new BoxHitTestEntry(this, position));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
class RenderSolidColor extends RenderDecoratedSector {
|
||||||
|
RenderSolidColor(Color backgroundColor, {
|
||||||
|
this.desiredDeltaRadius: double.INFINITY,
|
||||||
|
this.desiredDeltaTheta: kTwoPi
|
||||||
|
}) : this.backgroundColor = backgroundColor,
|
||||||
|
super(new BoxDecoration(backgroundColor: backgroundColor));
|
||||||
|
|
||||||
|
double desiredDeltaRadius;
|
||||||
|
double desiredDeltaTheta;
|
||||||
|
final Color backgroundColor;
|
||||||
|
|
||||||
|
SectorDimensions getIntrinsicDimensions(SectorConstraints constraints, double radius) {
|
||||||
|
return new SectorDimensions.withConstraints(constraints, deltaTheta: desiredDeltaTheta);
|
||||||
|
}
|
||||||
|
|
||||||
|
void performLayout() {
|
||||||
|
deltaRadius = constraints.constrainDeltaRadius(desiredDeltaRadius);
|
||||||
|
deltaTheta = constraints.constrainDeltaTheta(desiredDeltaTheta);
|
||||||
|
}
|
||||||
|
|
||||||
|
void handleEvent(InputEvent event, HitTestEntry entry) {
|
||||||
|
if (event.type == 'pointerdown')
|
||||||
|
decoration = new BoxDecoration(backgroundColor: const Color(0xFFFF0000));
|
||||||
|
else if (event.type == 'pointerup')
|
||||||
|
decoration = new BoxDecoration(backgroundColor: backgroundColor);
|
||||||
|
}
|
||||||
|
}
|
@ -1,9 +1,9 @@
|
|||||||
name: rendering
|
name: flutter_rendering_examples
|
||||||
dependencies:
|
dependencies:
|
||||||
sky: any
|
flutter: ">=0.0.3 <0.1.0"
|
||||||
sky_tools: any
|
sky_tools: any
|
||||||
dependency_overrides:
|
dependency_overrides:
|
||||||
material_design_icons:
|
material_design_icons:
|
||||||
path: ../../sky/packages/material_design_icons
|
path: ../../sky/packages/material_design_icons
|
||||||
sky:
|
flutter:
|
||||||
path: ../../sky/packages/sky
|
path: ../../sky/packages/sky
|
||||||
|
@ -4,8 +4,8 @@
|
|||||||
|
|
||||||
import 'dart:math' as math;
|
import 'dart:math' as math;
|
||||||
|
|
||||||
import 'package:sky/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:sky/rendering.dart';
|
import 'package:flutter/rendering.dart';
|
||||||
|
|
||||||
import 'solid_color_box.dart';
|
import 'solid_color_box.dart';
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
import 'package:sky/rendering.dart';
|
import 'package:flutter/rendering.dart';
|
||||||
|
|
||||||
import 'solid_color_box.dart';
|
import 'solid_color_box.dart';
|
||||||
|
|
||||||
|
@ -2,539 +2,9 @@
|
|||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
import 'dart:math' as math;
|
import 'dart:async';
|
||||||
import 'dart:sky' as sky;
|
import 'package:flutter/rendering.dart';
|
||||||
|
import 'lib/sector_layout.dart';
|
||||||
import 'package:sky/rendering.dart';
|
|
||||||
|
|
||||||
const double kTwoPi = 2 * math.PI;
|
|
||||||
|
|
||||||
class SectorConstraints extends Constraints {
|
|
||||||
const SectorConstraints({
|
|
||||||
this.minDeltaRadius: 0.0,
|
|
||||||
this.maxDeltaRadius: double.INFINITY,
|
|
||||||
this.minDeltaTheta: 0.0,
|
|
||||||
this.maxDeltaTheta: kTwoPi
|
|
||||||
});
|
|
||||||
|
|
||||||
const SectorConstraints.tight({ double deltaRadius: 0.0, double deltaTheta: 0.0 })
|
|
||||||
: minDeltaRadius = deltaRadius,
|
|
||||||
maxDeltaRadius = deltaRadius,
|
|
||||||
minDeltaTheta = deltaTheta,
|
|
||||||
maxDeltaTheta = deltaTheta;
|
|
||||||
|
|
||||||
final double minDeltaRadius;
|
|
||||||
final double maxDeltaRadius;
|
|
||||||
final double minDeltaTheta;
|
|
||||||
final double maxDeltaTheta;
|
|
||||||
|
|
||||||
double constrainDeltaRadius(double deltaRadius) {
|
|
||||||
return clamp(min: minDeltaRadius, max: maxDeltaRadius, value: deltaRadius);
|
|
||||||
}
|
|
||||||
|
|
||||||
double constrainDeltaTheta(double deltaTheta) {
|
|
||||||
return clamp(min: minDeltaTheta, max: maxDeltaTheta, value: deltaTheta);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool get isTight => minDeltaTheta >= maxDeltaTheta && minDeltaTheta >= maxDeltaTheta;
|
|
||||||
}
|
|
||||||
|
|
||||||
class SectorDimensions {
|
|
||||||
const SectorDimensions({ this.deltaRadius: 0.0, this.deltaTheta: 0.0 });
|
|
||||||
|
|
||||||
factory SectorDimensions.withConstraints(
|
|
||||||
SectorConstraints constraints,
|
|
||||||
{ double deltaRadius: 0.0, double deltaTheta: 0.0 }
|
|
||||||
) {
|
|
||||||
return new SectorDimensions(
|
|
||||||
deltaRadius: constraints.constrainDeltaRadius(deltaRadius),
|
|
||||||
deltaTheta: constraints.constrainDeltaTheta(deltaTheta)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
final double deltaRadius;
|
|
||||||
final double deltaTheta;
|
|
||||||
}
|
|
||||||
|
|
||||||
class SectorParentData extends ParentData {
|
|
||||||
double radius = 0.0;
|
|
||||||
double theta = 0.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract class RenderSector extends RenderObject {
|
|
||||||
|
|
||||||
void setupParentData(RenderObject child) {
|
|
||||||
if (child.parentData is! SectorParentData)
|
|
||||||
child.parentData = new SectorParentData();
|
|
||||||
}
|
|
||||||
|
|
||||||
SectorDimensions getIntrinsicDimensions(SectorConstraints constraints, double radius) {
|
|
||||||
return new SectorDimensions.withConstraints(constraints);
|
|
||||||
}
|
|
||||||
|
|
||||||
SectorConstraints get constraints => super.constraints;
|
|
||||||
bool debugDoesMeetConstraints() {
|
|
||||||
assert(constraints != null);
|
|
||||||
assert(deltaRadius != null);
|
|
||||||
assert(deltaRadius < double.INFINITY);
|
|
||||||
assert(deltaTheta != null);
|
|
||||||
assert(deltaTheta < double.INFINITY);
|
|
||||||
return constraints.minDeltaRadius <= deltaRadius &&
|
|
||||||
deltaRadius <= math.max(constraints.minDeltaRadius, constraints.maxDeltaRadius) &&
|
|
||||||
constraints.minDeltaTheta <= deltaTheta &&
|
|
||||||
deltaTheta <= math.max(constraints.minDeltaTheta, constraints.maxDeltaTheta);
|
|
||||||
}
|
|
||||||
void performResize() {
|
|
||||||
// default behaviour for subclasses that have sizedByParent = true
|
|
||||||
deltaRadius = constraints.constrainDeltaRadius(0.0);
|
|
||||||
deltaTheta = constraints.constrainDeltaTheta(0.0);
|
|
||||||
}
|
|
||||||
void performLayout() {
|
|
||||||
// descendants have to either override performLayout() to set both
|
|
||||||
// the dimensions and lay out children, or, set sizedByParent to
|
|
||||||
// true so that performResize()'s logic above does its thing.
|
|
||||||
assert(sizedByParent);
|
|
||||||
}
|
|
||||||
|
|
||||||
Rect get paintBounds => new Rect.fromLTWH(0.0, 0.0, 2.0 * deltaRadius, 2.0 * deltaRadius);
|
|
||||||
|
|
||||||
bool hitTest(HitTestResult result, { double radius, double theta }) {
|
|
||||||
assert(parentData is SectorParentData);
|
|
||||||
if (radius < parentData.radius || radius >= parentData.radius + deltaRadius ||
|
|
||||||
theta < parentData.theta || theta >= parentData.theta + deltaTheta)
|
|
||||||
return false;
|
|
||||||
hitTestChildren(result, radius: radius, theta: theta);
|
|
||||||
result.add(new HitTestEntry(this));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
void hitTestChildren(HitTestResult result, { double radius, double theta }) { }
|
|
||||||
|
|
||||||
double deltaRadius;
|
|
||||||
double deltaTheta;
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract class RenderDecoratedSector extends RenderSector {
|
|
||||||
|
|
||||||
RenderDecoratedSector(BoxDecoration decoration) : _decoration = decoration;
|
|
||||||
|
|
||||||
BoxDecoration _decoration;
|
|
||||||
BoxDecoration get decoration => _decoration;
|
|
||||||
void set decoration (BoxDecoration value) {
|
|
||||||
if (value == _decoration)
|
|
||||||
return;
|
|
||||||
_decoration = value;
|
|
||||||
markNeedsPaint();
|
|
||||||
}
|
|
||||||
|
|
||||||
// offset must point to the center of the circle
|
|
||||||
void paint(PaintingContext context, Offset offset) {
|
|
||||||
assert(deltaRadius != null);
|
|
||||||
assert(deltaTheta != null);
|
|
||||||
assert(parentData is SectorParentData);
|
|
||||||
|
|
||||||
if (_decoration == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (_decoration.backgroundColor != null) {
|
|
||||||
final PaintingCanvas canvas = context.canvas;
|
|
||||||
Paint paint = new Paint()..color = _decoration.backgroundColor;
|
|
||||||
Path path = new Path();
|
|
||||||
double outerRadius = (parentData.radius + deltaRadius);
|
|
||||||
Rect outerBounds = new Rect.fromLTRB(offset.dx-outerRadius, offset.dy-outerRadius, offset.dx+outerRadius, offset.dy+outerRadius);
|
|
||||||
path.arcTo(outerBounds, parentData.theta, deltaTheta, true);
|
|
||||||
double innerRadius = parentData.radius;
|
|
||||||
Rect innerBounds = new Rect.fromLTRB(offset.dx-innerRadius, offset.dy-innerRadius, offset.dx+innerRadius, offset.dy+innerRadius);
|
|
||||||
path.arcTo(innerBounds, parentData.theta + deltaTheta, -deltaTheta, false);
|
|
||||||
path.close();
|
|
||||||
canvas.drawPath(path, paint);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
class SectorChildListParentData extends SectorParentData with ContainerParentDataMixin<RenderSector> { }
|
|
||||||
|
|
||||||
class RenderSectorWithChildren extends RenderDecoratedSector with ContainerRenderObjectMixin<RenderSector, SectorChildListParentData> {
|
|
||||||
RenderSectorWithChildren(BoxDecoration decoration) : super(decoration);
|
|
||||||
|
|
||||||
void hitTestChildren(HitTestResult result, { double radius, double theta }) {
|
|
||||||
RenderSector child = lastChild;
|
|
||||||
while (child != null) {
|
|
||||||
assert(child.parentData is SectorChildListParentData);
|
|
||||||
if (child.hitTest(result, radius: radius, theta: theta))
|
|
||||||
return;
|
|
||||||
child = child.parentData.previousSibling;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void visitChildren(RenderObjectVisitor visitor) {
|
|
||||||
RenderSector child = lastChild;
|
|
||||||
while (child != null) {
|
|
||||||
visitor(child);
|
|
||||||
child = child.parentData.previousSibling;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class RenderSectorRing extends RenderSectorWithChildren {
|
|
||||||
// lays out RenderSector children in a ring
|
|
||||||
|
|
||||||
RenderSectorRing({
|
|
||||||
BoxDecoration decoration,
|
|
||||||
double deltaRadius: double.INFINITY,
|
|
||||||
double padding: 0.0
|
|
||||||
}) : super(decoration), _padding = padding, _desiredDeltaRadius = deltaRadius;
|
|
||||||
|
|
||||||
double _desiredDeltaRadius;
|
|
||||||
double get desiredDeltaRadius => _desiredDeltaRadius;
|
|
||||||
void set desiredDeltaRadius(double value) {
|
|
||||||
assert(value != null);
|
|
||||||
if (_desiredDeltaRadius != value) {
|
|
||||||
_desiredDeltaRadius = value;
|
|
||||||
markNeedsLayout();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
double _padding;
|
|
||||||
double get padding => _padding;
|
|
||||||
void set padding(double value) {
|
|
||||||
// TODO(ianh): avoid code duplication
|
|
||||||
assert(value != null);
|
|
||||||
if (_padding != value) {
|
|
||||||
_padding = value;
|
|
||||||
markNeedsLayout();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void setupParentData(RenderObject child) {
|
|
||||||
// TODO(ianh): avoid code duplication
|
|
||||||
if (child.parentData is! SectorChildListParentData)
|
|
||||||
child.parentData = new SectorChildListParentData();
|
|
||||||
}
|
|
||||||
|
|
||||||
SectorDimensions getIntrinsicDimensions(SectorConstraints constraints, double radius) {
|
|
||||||
double outerDeltaRadius = constraints.constrainDeltaRadius(desiredDeltaRadius);
|
|
||||||
double innerDeltaRadius = outerDeltaRadius - padding * 2.0;
|
|
||||||
double childRadius = radius + padding;
|
|
||||||
double paddingTheta = math.atan(padding / (radius + outerDeltaRadius));
|
|
||||||
double innerTheta = paddingTheta; // increments with each child
|
|
||||||
double remainingDeltaTheta = constraints.maxDeltaTheta - (innerTheta + paddingTheta);
|
|
||||||
RenderSector child = firstChild;
|
|
||||||
while (child != null) {
|
|
||||||
SectorConstraints innerConstraints = new SectorConstraints(
|
|
||||||
maxDeltaRadius: innerDeltaRadius,
|
|
||||||
maxDeltaTheta: remainingDeltaTheta
|
|
||||||
);
|
|
||||||
SectorDimensions childDimensions = child.getIntrinsicDimensions(innerConstraints, childRadius);
|
|
||||||
innerTheta += childDimensions.deltaTheta;
|
|
||||||
remainingDeltaTheta -= childDimensions.deltaTheta;
|
|
||||||
assert(child.parentData is SectorChildListParentData);
|
|
||||||
child = child.parentData.nextSibling;
|
|
||||||
if (child != null) {
|
|
||||||
innerTheta += paddingTheta;
|
|
||||||
remainingDeltaTheta -= paddingTheta;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return new SectorDimensions.withConstraints(constraints,
|
|
||||||
deltaRadius: outerDeltaRadius,
|
|
||||||
deltaTheta: innerTheta);
|
|
||||||
}
|
|
||||||
|
|
||||||
void performLayout() {
|
|
||||||
assert(this.parentData is SectorParentData);
|
|
||||||
deltaRadius = constraints.constrainDeltaRadius(desiredDeltaRadius);
|
|
||||||
assert(deltaRadius < double.INFINITY);
|
|
||||||
double innerDeltaRadius = deltaRadius - padding * 2.0;
|
|
||||||
double childRadius = this.parentData.radius + padding;
|
|
||||||
double paddingTheta = math.atan(padding / (this.parentData.radius + deltaRadius));
|
|
||||||
double innerTheta = paddingTheta; // increments with each child
|
|
||||||
double remainingDeltaTheta = constraints.maxDeltaTheta - (innerTheta + paddingTheta);
|
|
||||||
RenderSector child = firstChild;
|
|
||||||
while (child != null) {
|
|
||||||
SectorConstraints innerConstraints = new SectorConstraints(
|
|
||||||
maxDeltaRadius: innerDeltaRadius,
|
|
||||||
maxDeltaTheta: remainingDeltaTheta
|
|
||||||
);
|
|
||||||
assert(child.parentData is SectorParentData);
|
|
||||||
child.parentData.theta = innerTheta;
|
|
||||||
child.parentData.radius = childRadius;
|
|
||||||
child.layout(innerConstraints, parentUsesSize: true);
|
|
||||||
innerTheta += child.deltaTheta;
|
|
||||||
remainingDeltaTheta -= child.deltaTheta;
|
|
||||||
assert(child.parentData is SectorChildListParentData);
|
|
||||||
child = child.parentData.nextSibling;
|
|
||||||
if (child != null) {
|
|
||||||
innerTheta += paddingTheta;
|
|
||||||
remainingDeltaTheta -= paddingTheta;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
deltaTheta = innerTheta;
|
|
||||||
}
|
|
||||||
|
|
||||||
// offset must point to the center of our circle
|
|
||||||
// each sector then knows how to paint itself at its location
|
|
||||||
void paint(PaintingContext context, Offset offset) {
|
|
||||||
// TODO(ianh): avoid code duplication
|
|
||||||
super.paint(context, offset);
|
|
||||||
RenderSector child = firstChild;
|
|
||||||
while (child != null) {
|
|
||||||
assert(child.parentData is SectorChildListParentData);
|
|
||||||
context.paintChild(child, offset.toPoint());
|
|
||||||
child = child.parentData.nextSibling;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
class RenderSectorSlice extends RenderSectorWithChildren {
|
|
||||||
// lays out RenderSector children in a stack
|
|
||||||
|
|
||||||
RenderSectorSlice({
|
|
||||||
BoxDecoration decoration,
|
|
||||||
double deltaTheta: kTwoPi,
|
|
||||||
double padding: 0.0
|
|
||||||
}) : super(decoration), _padding = padding, _desiredDeltaTheta = deltaTheta;
|
|
||||||
|
|
||||||
double _desiredDeltaTheta;
|
|
||||||
double get desiredDeltaTheta => _desiredDeltaTheta;
|
|
||||||
void set desiredDeltaTheta(double value) {
|
|
||||||
assert(value != null);
|
|
||||||
if (_desiredDeltaTheta != value) {
|
|
||||||
_desiredDeltaTheta = value;
|
|
||||||
markNeedsLayout();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
double _padding;
|
|
||||||
double get padding => _padding;
|
|
||||||
void set padding(double value) {
|
|
||||||
// TODO(ianh): avoid code duplication
|
|
||||||
assert(value != null);
|
|
||||||
if (_padding != value) {
|
|
||||||
_padding = value;
|
|
||||||
markNeedsLayout();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void setupParentData(RenderObject child) {
|
|
||||||
// TODO(ianh): avoid code duplication
|
|
||||||
if (child.parentData is! SectorChildListParentData)
|
|
||||||
child.parentData = new SectorChildListParentData();
|
|
||||||
}
|
|
||||||
|
|
||||||
SectorDimensions getIntrinsicDimensions(SectorConstraints constraints, double radius) {
|
|
||||||
assert(this.parentData is SectorParentData);
|
|
||||||
double paddingTheta = math.atan(padding / this.parentData.radius);
|
|
||||||
double outerDeltaTheta = constraints.constrainDeltaTheta(desiredDeltaTheta);
|
|
||||||
double innerDeltaTheta = outerDeltaTheta - paddingTheta * 2.0;
|
|
||||||
double childRadius = this.parentData.radius + padding;
|
|
||||||
double remainingDeltaRadius = constraints.maxDeltaRadius - (padding * 2.0);
|
|
||||||
RenderSector child = firstChild;
|
|
||||||
while (child != null) {
|
|
||||||
SectorConstraints innerConstraints = new SectorConstraints(
|
|
||||||
maxDeltaRadius: remainingDeltaRadius,
|
|
||||||
maxDeltaTheta: innerDeltaTheta
|
|
||||||
);
|
|
||||||
SectorDimensions childDimensions = child.getIntrinsicDimensions(innerConstraints, childRadius);
|
|
||||||
childRadius += childDimensions.deltaRadius;
|
|
||||||
remainingDeltaRadius -= childDimensions.deltaRadius;
|
|
||||||
assert(child.parentData is SectorChildListParentData);
|
|
||||||
child = child.parentData.nextSibling;
|
|
||||||
childRadius += padding;
|
|
||||||
remainingDeltaRadius -= padding;
|
|
||||||
}
|
|
||||||
return new SectorDimensions.withConstraints(constraints,
|
|
||||||
deltaRadius: childRadius - this.parentData.radius,
|
|
||||||
deltaTheta: outerDeltaTheta);
|
|
||||||
}
|
|
||||||
|
|
||||||
void performLayout() {
|
|
||||||
assert(this.parentData is SectorParentData);
|
|
||||||
deltaTheta = constraints.constrainDeltaTheta(desiredDeltaTheta);
|
|
||||||
assert(deltaTheta <= kTwoPi);
|
|
||||||
double paddingTheta = math.atan(padding / this.parentData.radius);
|
|
||||||
double innerTheta = this.parentData.theta + paddingTheta;
|
|
||||||
double innerDeltaTheta = deltaTheta - paddingTheta * 2.0;
|
|
||||||
double childRadius = this.parentData.radius + padding;
|
|
||||||
double remainingDeltaRadius = constraints.maxDeltaRadius - (padding * 2.0);
|
|
||||||
RenderSector child = firstChild;
|
|
||||||
while (child != null) {
|
|
||||||
SectorConstraints innerConstraints = new SectorConstraints(
|
|
||||||
maxDeltaRadius: remainingDeltaRadius,
|
|
||||||
maxDeltaTheta: innerDeltaTheta
|
|
||||||
);
|
|
||||||
child.parentData.theta = innerTheta;
|
|
||||||
child.parentData.radius = childRadius;
|
|
||||||
child.layout(innerConstraints, parentUsesSize: true);
|
|
||||||
childRadius += child.deltaRadius;
|
|
||||||
remainingDeltaRadius -= child.deltaRadius;
|
|
||||||
assert(child.parentData is SectorChildListParentData);
|
|
||||||
child = child.parentData.nextSibling;
|
|
||||||
childRadius += padding;
|
|
||||||
remainingDeltaRadius -= padding;
|
|
||||||
}
|
|
||||||
deltaRadius = childRadius - this.parentData.radius;
|
|
||||||
}
|
|
||||||
|
|
||||||
// offset must point to the center of our circle
|
|
||||||
// each sector then knows how to paint itself at its location
|
|
||||||
void paint(PaintingContext context, Offset offset) {
|
|
||||||
// TODO(ianh): avoid code duplication
|
|
||||||
super.paint(context, offset);
|
|
||||||
RenderSector child = firstChild;
|
|
||||||
while (child != null) {
|
|
||||||
assert(child.parentData is SectorChildListParentData);
|
|
||||||
context.paintChild(child, offset.toPoint());
|
|
||||||
child = child.parentData.nextSibling;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
class RenderBoxToRenderSectorAdapter extends RenderBox {
|
|
||||||
|
|
||||||
RenderBoxToRenderSectorAdapter({ double innerRadius: 0.0, RenderSector child }) :
|
|
||||||
_innerRadius = innerRadius {
|
|
||||||
_child = child;
|
|
||||||
adoptChild(_child);
|
|
||||||
}
|
|
||||||
|
|
||||||
double _innerRadius;
|
|
||||||
double get innerRadius => _innerRadius;
|
|
||||||
void set innerRadius(double value) {
|
|
||||||
_innerRadius = value;
|
|
||||||
markNeedsLayout();
|
|
||||||
}
|
|
||||||
|
|
||||||
RenderSector _child;
|
|
||||||
RenderSector get child => _child;
|
|
||||||
void set child(RenderSector value) {
|
|
||||||
if (_child != null)
|
|
||||||
dropChild(_child);
|
|
||||||
_child = value;
|
|
||||||
adoptChild(_child);
|
|
||||||
markNeedsLayout();
|
|
||||||
}
|
|
||||||
|
|
||||||
void setupParentData(RenderObject child) {
|
|
||||||
if (child.parentData is! SectorParentData)
|
|
||||||
child.parentData = new SectorParentData();
|
|
||||||
}
|
|
||||||
|
|
||||||
void visitChildren(RenderObjectVisitor visitor) {
|
|
||||||
visitor(_child);
|
|
||||||
}
|
|
||||||
|
|
||||||
double getMinIntrinsicWidth(BoxConstraints constraints) {
|
|
||||||
if (child == null)
|
|
||||||
return super.getMinIntrinsicWidth(constraints);
|
|
||||||
return getIntrinsicDimensions(constraints).width;
|
|
||||||
}
|
|
||||||
|
|
||||||
double getMaxIntrinsicWidth(BoxConstraints constraints) {
|
|
||||||
if (child == null)
|
|
||||||
return super.getMaxIntrinsicWidth(constraints);
|
|
||||||
return getIntrinsicDimensions(constraints).width;
|
|
||||||
}
|
|
||||||
|
|
||||||
double getMinIntrinsicHeight(BoxConstraints constraints) {
|
|
||||||
if (child == null)
|
|
||||||
return super.getMinIntrinsicHeight(constraints);
|
|
||||||
return getIntrinsicDimensions(constraints).height;
|
|
||||||
}
|
|
||||||
|
|
||||||
double getMaxIntrinsicHeight(BoxConstraints constraints) {
|
|
||||||
if (child == null)
|
|
||||||
return super.getMaxIntrinsicHeight(constraints);
|
|
||||||
return getIntrinsicDimensions(constraints).height;
|
|
||||||
}
|
|
||||||
|
|
||||||
Size getIntrinsicDimensions(BoxConstraints constraints) {
|
|
||||||
assert(child is RenderSector);
|
|
||||||
assert(child.parentData is SectorParentData);
|
|
||||||
assert(constraints.maxWidth < double.INFINITY || constraints.maxHeight < double.INFINITY);
|
|
||||||
double maxChildDeltaRadius = math.min(constraints.maxWidth, constraints.maxHeight) / 2.0 - innerRadius;
|
|
||||||
SectorDimensions childDimensions = child.getIntrinsicDimensions(new SectorConstraints(maxDeltaRadius: maxChildDeltaRadius), innerRadius);
|
|
||||||
double dimension = (innerRadius + childDimensions.deltaRadius) * 2.0;
|
|
||||||
return constraints.constrain(new Size(dimension, dimension));
|
|
||||||
}
|
|
||||||
|
|
||||||
void performLayout() {
|
|
||||||
if (child == null) {
|
|
||||||
size = constraints.constrain(Size.zero);
|
|
||||||
} else {
|
|
||||||
assert(child is RenderSector);
|
|
||||||
assert(constraints.maxWidth < double.INFINITY || constraints.maxHeight < double.INFINITY);
|
|
||||||
double maxChildDeltaRadius = math.min(constraints.maxWidth, constraints.maxHeight) / 2.0 - innerRadius;
|
|
||||||
assert(child.parentData is SectorParentData);
|
|
||||||
child.parentData.radius = innerRadius;
|
|
||||||
child.parentData.theta = 0.0;
|
|
||||||
child.layout(new SectorConstraints(maxDeltaRadius: maxChildDeltaRadius), parentUsesSize: true);
|
|
||||||
double dimension = (innerRadius + child.deltaRadius) * 2.0;
|
|
||||||
size = constraints.constrain(new Size(dimension, dimension));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void paint(PaintingContext context, Offset offset) {
|
|
||||||
super.paint(context, offset);
|
|
||||||
if (child != null) {
|
|
||||||
Rect bounds = offset & size;
|
|
||||||
// we move the offset to the center of the circle for the RenderSectors
|
|
||||||
context.paintChild(child, bounds.center);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool hitTest(HitTestResult result, { Point position }) {
|
|
||||||
double x = position.x;
|
|
||||||
double y = position.y;
|
|
||||||
if (child == null)
|
|
||||||
return false;
|
|
||||||
// translate to our origin
|
|
||||||
x -= size.width/2.0;
|
|
||||||
y -= size.height/2.0;
|
|
||||||
// convert to radius/theta
|
|
||||||
double radius = math.sqrt(x*x+y*y);
|
|
||||||
double theta = (math.atan2(x, -y) - math.PI/2.0) % kTwoPi;
|
|
||||||
if (radius < innerRadius)
|
|
||||||
return false;
|
|
||||||
if (radius >= innerRadius + child.deltaRadius)
|
|
||||||
return false;
|
|
||||||
if (theta > child.deltaTheta)
|
|
||||||
return false;
|
|
||||||
child.hitTest(result, radius: radius, theta: theta);
|
|
||||||
result.add(new BoxHitTestEntry(this, position));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
class RenderSolidColor extends RenderDecoratedSector {
|
|
||||||
RenderSolidColor(Color backgroundColor, {
|
|
||||||
this.desiredDeltaRadius: double.INFINITY,
|
|
||||||
this.desiredDeltaTheta: kTwoPi
|
|
||||||
}) : this.backgroundColor = backgroundColor,
|
|
||||||
super(new BoxDecoration(backgroundColor: backgroundColor));
|
|
||||||
|
|
||||||
double desiredDeltaRadius;
|
|
||||||
double desiredDeltaTheta;
|
|
||||||
final Color backgroundColor;
|
|
||||||
|
|
||||||
SectorDimensions getIntrinsicDimensions(SectorConstraints constraints, double radius) {
|
|
||||||
return new SectorDimensions.withConstraints(constraints, deltaTheta: desiredDeltaTheta);
|
|
||||||
}
|
|
||||||
|
|
||||||
void performLayout() {
|
|
||||||
deltaRadius = constraints.constrainDeltaRadius(desiredDeltaRadius);
|
|
||||||
deltaTheta = constraints.constrainDeltaTheta(desiredDeltaTheta);
|
|
||||||
}
|
|
||||||
|
|
||||||
void handleEvent(sky.Event event, HitTestEntry entry) {
|
|
||||||
if (event.type == 'pointerdown')
|
|
||||||
decoration = new BoxDecoration(backgroundColor: const Color(0xFFFF0000));
|
|
||||||
else if (event.type == 'pointerup')
|
|
||||||
decoration = new BoxDecoration(backgroundColor: backgroundColor);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
RenderBox buildSectorExample() {
|
RenderBox buildSectorExample() {
|
||||||
RenderSectorRing rootCircle = new RenderSectorRing(padding: 20.0);
|
RenderSectorRing rootCircle = new RenderSectorRing(padding: 20.0);
|
||||||
|
@ -2,10 +2,10 @@
|
|||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
import 'dart:sky';
|
import 'dart:ui';
|
||||||
|
|
||||||
import 'package:sky/rendering.dart';
|
import 'package:flutter/rendering.dart';
|
||||||
import 'package:sky/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
var coloredBox = new RenderDecoratedBox(
|
var coloredBox = new RenderDecoratedBox(
|
||||||
|
@ -2,10 +2,10 @@
|
|||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
import 'dart:sky';
|
import 'dart:ui';
|
||||||
|
|
||||||
import 'package:cassowary/cassowary.dart' as al;
|
import 'package:cassowary/cassowary.dart' as al;
|
||||||
import 'package:sky/rendering.dart';
|
import 'package:flutter/rendering.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
RenderDecoratedBox c1 = new RenderDecoratedBox(
|
RenderDecoratedBox c1 = new RenderDecoratedBox(
|
||||||
|
@ -2,9 +2,8 @@
|
|||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
import 'dart:sky' as sky;
|
import 'package:flutter/rendering.dart';
|
||||||
|
import 'package:flutter/gestures.dart';
|
||||||
import 'package:sky/rendering.dart';
|
|
||||||
|
|
||||||
class RenderSolidColorBox extends RenderDecoratedBox {
|
class RenderSolidColorBox extends RenderDecoratedBox {
|
||||||
final Size desiredSize;
|
final Size desiredSize;
|
||||||
@ -42,7 +41,7 @@ class RenderSolidColorBox extends RenderDecoratedBox {
|
|||||||
size = constraints.constrain(desiredSize);
|
size = constraints.constrain(desiredSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
void handleEvent(sky.Event event, BoxHitTestEntry entry) {
|
void handleEvent(InputEvent event, BoxHitTestEntry entry) {
|
||||||
if (event.type == 'pointerdown')
|
if (event.type == 'pointerdown')
|
||||||
decoration = new BoxDecoration(backgroundColor: const Color(0xFFFF0000));
|
decoration = new BoxDecoration(backgroundColor: const Color(0xFFFF0000));
|
||||||
else if (event.type == 'pointerup')
|
else if (event.type == 'pointerup')
|
||||||
|
@ -2,10 +2,10 @@
|
|||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
import 'dart:sky' as sky;
|
import 'dart:ui' as ui;
|
||||||
|
|
||||||
import 'package:sky/animation.dart';
|
import 'package:flutter/animation.dart';
|
||||||
import 'package:sky/rendering.dart';
|
import 'package:flutter/rendering.dart';
|
||||||
|
|
||||||
import 'solid_color_box.dart';
|
import 'solid_color_box.dart';
|
||||||
|
|
||||||
@ -15,15 +15,15 @@ RenderTransform transformBox;
|
|||||||
void main() {
|
void main() {
|
||||||
RenderFlex flexRoot = new RenderFlex(direction: FlexDirection.vertical);
|
RenderFlex flexRoot = new RenderFlex(direction: FlexDirection.vertical);
|
||||||
|
|
||||||
void addFlexChildSolidColor(RenderFlex parent, sky.Color backgroundColor, { int flex: 0 }) {
|
void addFlexChildSolidColor(RenderFlex parent, ui.Color backgroundColor, { int flex: 0 }) {
|
||||||
RenderSolidColorBox child = new RenderSolidColorBox(backgroundColor);
|
RenderSolidColorBox child = new RenderSolidColorBox(backgroundColor);
|
||||||
parent.add(child);
|
parent.add(child);
|
||||||
child.parentData.flex = flex;
|
child.parentData.flex = flex;
|
||||||
}
|
}
|
||||||
|
|
||||||
addFlexChildSolidColor(flexRoot, const sky.Color(0xFFFF00FF), flex: 1);
|
addFlexChildSolidColor(flexRoot, const ui.Color(0xFFFF00FF), flex: 1);
|
||||||
addFlexChildSolidColor(flexRoot, const sky.Color(0xFFFFFF00), flex: 2);
|
addFlexChildSolidColor(flexRoot, const ui.Color(0xFFFFFF00), flex: 2);
|
||||||
addFlexChildSolidColor(flexRoot, const sky.Color(0xFF00FFFF), flex: 1);
|
addFlexChildSolidColor(flexRoot, const ui.Color(0xFF00FFFF), flex: 1);
|
||||||
|
|
||||||
transformBox = new RenderTransform(child: flexRoot, transform: new Matrix4.identity());
|
transformBox = new RenderTransform(child: flexRoot, transform: new Matrix4.identity());
|
||||||
|
|
||||||
|
@ -2,10 +2,9 @@
|
|||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
import 'dart:sky' as sky;
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter/rendering.dart';
|
||||||
import 'package:sky/material.dart';
|
import 'package:flutter/gestures.dart';
|
||||||
import 'package:sky/rendering.dart';
|
|
||||||
|
|
||||||
// Material design colors. :p
|
// Material design colors. :p
|
||||||
List<Color> kColors = [
|
List<Color> kColors = [
|
||||||
@ -24,7 +23,7 @@ class Dot {
|
|||||||
|
|
||||||
Dot({ Color color }) : _paint = new Paint()..color = color;
|
Dot({ Color color }) : _paint = new Paint()..color = color;
|
||||||
|
|
||||||
void update(sky.PointerEvent event) {
|
void update(PointerInputEvent event) {
|
||||||
position = new Point(event.x, event.y);
|
position = new Point(event.x, event.y);
|
||||||
radius = 5 + (95 * event.pressure);
|
radius = 5 + (95 * event.pressure);
|
||||||
}
|
}
|
||||||
@ -39,8 +38,8 @@ class RenderTouchDemo extends RenderBox {
|
|||||||
|
|
||||||
RenderTouchDemo();
|
RenderTouchDemo();
|
||||||
|
|
||||||
void handleEvent(sky.Event event, BoxHitTestEntry entry) {
|
void handleEvent(InputEvent event, BoxHitTestEntry entry) {
|
||||||
if (event is sky.PointerEvent) {
|
if (event is PointerInputEvent) {
|
||||||
switch (event.type) {
|
switch (event.type) {
|
||||||
case 'pointerdown':
|
case 'pointerdown':
|
||||||
Color color = kColors[event.pointer.remainder(kColors.length)];
|
Color color = kColors[event.pointer.remainder(kColors.length)];
|
||||||
|
@ -2,16 +2,16 @@
|
|||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
import 'dart:sky' as sky;
|
import 'dart:ui' as ui;
|
||||||
|
|
||||||
import 'package:sky/rendering.dart';
|
import 'package:flutter/rendering.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
RenderDecoratedBox green = new RenderDecoratedBox(
|
RenderDecoratedBox green = new RenderDecoratedBox(
|
||||||
decoration: new BoxDecoration(backgroundColor: const sky.Color(0xFF00FF00))
|
decoration: new BoxDecoration(backgroundColor: const ui.Color(0xFF00FF00))
|
||||||
);
|
);
|
||||||
RenderConstrainedBox box = new RenderConstrainedBox(
|
RenderConstrainedBox box = new RenderConstrainedBox(
|
||||||
additionalConstraints: new BoxConstraints.tight(const sky.Size(200.0, 200.0)),
|
additionalConstraints: new BoxConstraints.tight(const ui.Size(200.0, 200.0)),
|
||||||
child: green
|
child: green
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -6,12 +6,11 @@ library stocks;
|
|||||||
|
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'dart:math' as math;
|
import 'dart:math' as math;
|
||||||
import 'dart:sky' as sky;
|
import 'dart:ui' as ui;
|
||||||
|
|
||||||
import 'package:sky/gestures.dart';
|
import 'package:flutter/gestures.dart';
|
||||||
import 'package:sky/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:sky/painting.dart';
|
import 'package:flutter/painting.dart';
|
||||||
import 'package:sky/widgets.dart';
|
|
||||||
|
|
||||||
import 'stock_data.dart';
|
import 'stock_data.dart';
|
||||||
|
|
||||||
@ -88,7 +87,7 @@ class StocksAppState extends State<StocksApp> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return new App(
|
return new MaterialApp(
|
||||||
title: 'Stocks',
|
title: 'Stocks',
|
||||||
theme: theme,
|
theme: theme,
|
||||||
routes: <String, RouteBuilder>{
|
routes: <String, RouteBuilder>{
|
||||||
|
@ -25,7 +25,7 @@ class StockArrow extends StatelessComponent {
|
|||||||
// TODO(jackson): This should change colors with the theme
|
// TODO(jackson): This should change colors with the theme
|
||||||
Color color = _colorForPercentChange(percentChange);
|
Color color = _colorForPercentChange(percentChange);
|
||||||
const double kSize = 40.0;
|
const double kSize = 40.0;
|
||||||
var arrow = new CustomPaint(callback: (sky.Canvas canvas, Size size) {
|
var arrow = new CustomPaint(callback: (ui.Canvas canvas, Size size) {
|
||||||
Paint paint = new Paint()..color = color;
|
Paint paint = new Paint()..color = color;
|
||||||
paint.strokeWidth = 1.0;
|
paint.strokeWidth = 1.0;
|
||||||
const double padding = 2.0;
|
const double padding = 2.0;
|
||||||
@ -49,11 +49,11 @@ class StockArrow extends StatelessComponent {
|
|||||||
path.lineTo(centerX + w, arrowY + h);
|
path.lineTo(centerX + w, arrowY + h);
|
||||||
path.lineTo(centerX - w, arrowY + h);
|
path.lineTo(centerX - w, arrowY + h);
|
||||||
path.close();
|
path.close();
|
||||||
paint.setStyle(sky.PaintingStyle.fill);
|
paint.setStyle(ui.PaintingStyle.fill);
|
||||||
canvas.drawPath(path, paint);
|
canvas.drawPath(path, paint);
|
||||||
|
|
||||||
// Draw a circle that circumscribes the arrow.
|
// Draw a circle that circumscribes the arrow.
|
||||||
paint.setStyle(sky.PaintingStyle.stroke);
|
paint.setStyle(ui.PaintingStyle.stroke);
|
||||||
canvas.drawCircle(new Point(centerX, centerY), r, paint);
|
canvas.drawCircle(new Point(centerX, centerY), r, paint);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
import 'dart:math' as math;
|
import 'dart:math' as math;
|
||||||
|
|
||||||
import 'package:sky/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
|
|
||||||
final math.Random _rng = new math.Random();
|
final math.Random _rng = new math.Random();
|
||||||
|
|
||||||
@ -57,8 +57,8 @@ const _kChunkCount = 30;
|
|||||||
|
|
||||||
String _urlToFetch(int chunk) {
|
String _urlToFetch(int chunk) {
|
||||||
if (rootBundle == null)
|
if (rootBundle == null)
|
||||||
return '../data/stock_data_${chunk}.json';
|
return '../data/stock_data_$chunk.json';
|
||||||
return 'https://domokit.github.io/examples/stocks/data/stock_data_${chunk}.json';
|
return 'https://domokit.github.io/examples/stocks/data/stock_data_$chunk.json';
|
||||||
}
|
}
|
||||||
|
|
||||||
class StockDataFetcher {
|
class StockDataFetcher {
|
||||||
@ -81,9 +81,7 @@ class StockDataFetcher {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
JsonDecoder decoder = new JsonDecoder();
|
JsonDecoder decoder = new JsonDecoder();
|
||||||
|
|
||||||
callback(new StockData(decoder.convert(json)));
|
callback(new StockData(decoder.convert(json)));
|
||||||
|
|
||||||
if (_nextChunk < _kChunkCount)
|
if (_nextChunk < _kChunkCount)
|
||||||
_fetchNextChunk();
|
_fetchNextChunk();
|
||||||
});
|
});
|
||||||
|
@ -37,8 +37,10 @@ class StockHomeState extends State<StockHome> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void _handleSearchEnd() {
|
void _handleSearchEnd() {
|
||||||
assert(config.navigator.currentRoute is StateRoute);
|
assert(() {
|
||||||
assert((config.navigator.currentRoute as StateRoute).owner == this); // TODO(ianh): remove cast once analyzer is cleverer
|
final StateRoute currentRoute = config.navigator.currentRoute;
|
||||||
|
assert(currentRoute.owner == this);
|
||||||
|
});
|
||||||
config.navigator.pop();
|
config.navigator.pop();
|
||||||
setState(() {
|
setState(() {
|
||||||
_isSearching = false;
|
_isSearching = false;
|
||||||
@ -74,7 +76,7 @@ class StockHomeState extends State<StockHome> {
|
|||||||
void _showDrawer() {
|
void _showDrawer() {
|
||||||
showDrawer(
|
showDrawer(
|
||||||
navigator: config.navigator,
|
navigator: config.navigator,
|
||||||
child: new Block([
|
child: new Block(<Widget>[
|
||||||
new DrawerHeader(child: new Text('Stocks')),
|
new DrawerHeader(child: new Text('Stocks')),
|
||||||
new DrawerItem(
|
new DrawerItem(
|
||||||
icon: 'action/assessment',
|
icon: 'action/assessment',
|
||||||
@ -83,6 +85,29 @@ class StockHomeState extends State<StockHome> {
|
|||||||
),
|
),
|
||||||
new DrawerItem(
|
new DrawerItem(
|
||||||
icon: 'action/account_balance',
|
icon: 'action/account_balance',
|
||||||
|
onPressed: () {
|
||||||
|
showDialog(config.navigator, (NavigatorState navigator) {
|
||||||
|
return new Dialog(
|
||||||
|
title: new Text('Not Implemented'),
|
||||||
|
content: new Text('This feature has not yet been implemented.'),
|
||||||
|
actions: <Widget>[
|
||||||
|
new FlatButton(
|
||||||
|
child: new Text('USE IT'),
|
||||||
|
enabled: false,
|
||||||
|
onPressed: () {
|
||||||
|
navigator.pop(false);
|
||||||
|
}
|
||||||
|
),
|
||||||
|
new FlatButton(
|
||||||
|
child: new Text('OH WELL'),
|
||||||
|
onPressed: () {
|
||||||
|
navigator.pop(false);
|
||||||
|
}
|
||||||
|
),
|
||||||
|
]
|
||||||
|
);
|
||||||
|
});
|
||||||
|
},
|
||||||
child: new Text('Account Balance')
|
child: new Text('Account Balance')
|
||||||
),
|
),
|
||||||
new DrawerItem(
|
new DrawerItem(
|
||||||
@ -94,7 +119,7 @@ class StockHomeState extends State<StockHome> {
|
|||||||
new DrawerItem(
|
new DrawerItem(
|
||||||
icon: 'action/thumb_up',
|
icon: 'action/thumb_up',
|
||||||
onPressed: () => _handleStockModeChange(StockMode.optimistic),
|
onPressed: () => _handleStockModeChange(StockMode.optimistic),
|
||||||
child: new Row([
|
child: new Row(<Widget>[
|
||||||
new Flexible(child: new Text('Optimistic')),
|
new Flexible(child: new Text('Optimistic')),
|
||||||
new Radio(value: StockMode.optimistic, groupValue: config.stockMode, onChanged: _handleStockModeChange)
|
new Radio(value: StockMode.optimistic, groupValue: config.stockMode, onChanged: _handleStockModeChange)
|
||||||
])
|
])
|
||||||
@ -102,7 +127,7 @@ class StockHomeState extends State<StockHome> {
|
|||||||
new DrawerItem(
|
new DrawerItem(
|
||||||
icon: 'action/thumb_down',
|
icon: 'action/thumb_down',
|
||||||
onPressed: () => _handleStockModeChange(StockMode.pessimistic),
|
onPressed: () => _handleStockModeChange(StockMode.pessimistic),
|
||||||
child: new Row([
|
child: new Row(<Widget>[
|
||||||
new Flexible(child: new Text('Pessimistic')),
|
new Flexible(child: new Text('Pessimistic')),
|
||||||
new Radio(value: StockMode.pessimistic, groupValue: config.stockMode, onChanged: _handleStockModeChange)
|
new Radio(value: StockMode.pessimistic, groupValue: config.stockMode, onChanged: _handleStockModeChange)
|
||||||
])
|
])
|
||||||
@ -132,7 +157,7 @@ class StockHomeState extends State<StockHome> {
|
|||||||
onPressed: _showDrawer
|
onPressed: _showDrawer
|
||||||
),
|
),
|
||||||
center: new Text('Stocks'),
|
center: new Text('Stocks'),
|
||||||
right: [
|
right: <Widget>[
|
||||||
new IconButton(
|
new IconButton(
|
||||||
icon: "action/search",
|
icon: "action/search",
|
||||||
onPressed: _handleSearchBegin
|
onPressed: _handleSearchBegin
|
||||||
@ -148,14 +173,14 @@ class StockHomeState extends State<StockHome> {
|
|||||||
int selectedTabIndex = 0;
|
int selectedTabIndex = 0;
|
||||||
|
|
||||||
Iterable<Stock> _getStockList(Iterable<String> symbols) {
|
Iterable<Stock> _getStockList(Iterable<String> symbols) {
|
||||||
return symbols.map((symbol) => config.stocks[symbol]);
|
return symbols.map((String symbol) => config.stocks[symbol]);
|
||||||
}
|
}
|
||||||
|
|
||||||
Iterable<Stock> _filterBySearchQuery(Iterable<Stock> stocks) {
|
Iterable<Stock> _filterBySearchQuery(Iterable<Stock> stocks) {
|
||||||
if (_searchQuery == null)
|
if (_searchQuery == null)
|
||||||
return stocks;
|
return stocks;
|
||||||
RegExp regexp = new RegExp(_searchQuery, caseSensitive: false);
|
RegExp regexp = new RegExp(_searchQuery, caseSensitive: false);
|
||||||
return stocks.where((stock) => stock.symbol.contains(regexp));
|
return stocks.where((Stock stock) => stock.symbol.contains(regexp));
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget buildStockList(BuildContext context, Iterable<Stock> stocks) {
|
Widget buildStockList(BuildContext context, Iterable<Stock> stocks) {
|
||||||
@ -188,7 +213,7 @@ class StockHomeState extends State<StockHome> {
|
|||||||
)
|
)
|
||||||
],
|
],
|
||||||
selectedIndex: selectedTabIndex,
|
selectedIndex: selectedTabIndex,
|
||||||
onChanged: (tabIndex) {
|
onChanged: (int tabIndex) {
|
||||||
setState(() { selectedTabIndex = tabIndex; } );
|
setState(() { selectedTabIndex = tabIndex; } );
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@ -201,7 +226,7 @@ class StockHomeState extends State<StockHome> {
|
|||||||
return new ToolBar(
|
return new ToolBar(
|
||||||
left: new IconButton(
|
left: new IconButton(
|
||||||
icon: "navigation/arrow_back",
|
icon: "navigation/arrow_back",
|
||||||
color: Theme.of(context).accentColor,
|
colorFilter: new ui.ColorFilter.mode(Theme.of(context).accentColor, ui.TransferMode.srcATop),
|
||||||
onPressed: _handleSearchEnd
|
onPressed: _handleSearchEnd
|
||||||
),
|
),
|
||||||
center: new Input(
|
center: new Input(
|
||||||
@ -222,7 +247,7 @@ class StockHomeState extends State<StockHome> {
|
|||||||
navigator: config.navigator,
|
navigator: config.navigator,
|
||||||
placeholderKey: _snackBarPlaceholderKey,
|
placeholderKey: _snackBarPlaceholderKey,
|
||||||
content: new Text("Stock purchased!"),
|
content: new Text("Stock purchased!"),
|
||||||
actions: [
|
actions: <SnackBarAction>[
|
||||||
new SnackBarAction(label: "UNDO", onPressed: _handleUndo)
|
new SnackBarAction(label: "UNDO", onPressed: _handleUndo)
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
@ -13,7 +13,6 @@ class StockList extends StatelessComponent {
|
|||||||
|
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return new Material(
|
return new Material(
|
||||||
type: MaterialType.canvas,
|
|
||||||
child: new ScrollableList<Stock>(
|
child: new ScrollableList<Stock>(
|
||||||
items: stocks,
|
items: stocks,
|
||||||
itemExtent: StockRow.kHeight,
|
itemExtent: StockRow.kHeight,
|
||||||
|
@ -12,14 +12,14 @@ Future showStockMenu(NavigatorState navigator, { bool autorefresh, ValueChanged
|
|||||||
switch (await showMenu(
|
switch (await showMenu(
|
||||||
navigator: navigator,
|
navigator: navigator,
|
||||||
position: new MenuPosition(
|
position: new MenuPosition(
|
||||||
right: sky.view.paddingRight + _kMenuMargin,
|
right: ui.view.paddingRight + _kMenuMargin,
|
||||||
top: sky.view.paddingTop + _kMenuMargin
|
top: ui.view.paddingTop + _kMenuMargin
|
||||||
),
|
),
|
||||||
builder: (NavigatorState navigator) {
|
builder: (NavigatorState navigator) {
|
||||||
return <PopupMenuItem>[
|
return <PopupMenuItem>[
|
||||||
new PopupMenuItem(
|
new PopupMenuItem(
|
||||||
value: _MenuItems.autorefresh,
|
value: _MenuItems.autorefresh,
|
||||||
child: new Row([
|
child: new Row(<Widget>[
|
||||||
new Flexible(child: new Text('Autorefresh')),
|
new Flexible(child: new Text('Autorefresh')),
|
||||||
new Checkbox(
|
new Checkbox(
|
||||||
value: autorefresh,
|
value: autorefresh,
|
||||||
@ -59,7 +59,20 @@ Future showStockMenu(NavigatorState navigator, { bool autorefresh, ValueChanged
|
|||||||
return new Dialog(
|
return new Dialog(
|
||||||
title: new Text('Not Implemented'),
|
title: new Text('Not Implemented'),
|
||||||
content: new Text('This feature has not yet been implemented.'),
|
content: new Text('This feature has not yet been implemented.'),
|
||||||
actions: [
|
actions: <Widget>[
|
||||||
|
new FlatButton(
|
||||||
|
child: new Row(<Widget>[
|
||||||
|
new Icon(
|
||||||
|
type: 'device/dvr',
|
||||||
|
size: 18
|
||||||
|
),
|
||||||
|
new Container(
|
||||||
|
width: 8.0
|
||||||
|
),
|
||||||
|
new Text('DUMP APP TO CONSOLE'),
|
||||||
|
]),
|
||||||
|
onPressed: () { debugDumpApp(); }
|
||||||
|
),
|
||||||
new FlatButton(
|
new FlatButton(
|
||||||
child: new Text('OH WELL'),
|
child: new Text('OH WELL'),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
|
@ -10,9 +10,15 @@ class StockRowPartGlobalKey extends GlobalKey {
|
|||||||
const StockRowPartGlobalKey(this.stock, this.part) : super.constructor();
|
const StockRowPartGlobalKey(this.stock, this.part) : super.constructor();
|
||||||
final Stock stock;
|
final Stock stock;
|
||||||
final StockRowPartKind part;
|
final StockRowPartKind part;
|
||||||
String toString() => '[StockRowPartGlobalKey ${stock.symbol}:${part.toString().split(".")[1]})]';
|
bool operator ==(dynamic other) {
|
||||||
bool operator==(other) => other is StockRowPartGlobalKey && identical(other.stock, stock) && identical(other.part, part);
|
if (other is! StockRowPartGlobalKey)
|
||||||
|
return false;
|
||||||
|
final StockRowPartGlobalKey typedOther = other;
|
||||||
|
return stock == typedOther.stock &&
|
||||||
|
part == typedOther.part;
|
||||||
|
}
|
||||||
int get hashCode => 37 * (37 * (373) + identityHashCode(stock)) + identityHashCode(part);
|
int get hashCode => 37 * (37 * (373) + identityHashCode(stock)) + identityHashCode(part);
|
||||||
|
String toString() => '[StockRowPartGlobalKey ${stock.symbol}:${part.toString().split(".")[1]})]';
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef void StockRowActionCallback(Stock stock, GlobalKey row, GlobalKey arrowKey, GlobalKey symbolKey, GlobalKey priceKey);
|
typedef void StockRowActionCallback(Stock stock, GlobalKey row, GlobalKey arrowKey, GlobalKey symbolKey, GlobalKey priceKey);
|
||||||
@ -65,14 +71,14 @@ class StockRow extends StatelessComponent {
|
|||||||
bottom: new BorderSide(color: Theme.of(context).dividerColor)
|
bottom: new BorderSide(color: Theme.of(context).dividerColor)
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
child: new Row([
|
child: new Row(<Widget>[
|
||||||
new Container(
|
new Container(
|
||||||
key: arrowKey,
|
key: arrowKey,
|
||||||
child: new StockArrow(percentChange: stock.percentChange),
|
child: new StockArrow(percentChange: stock.percentChange),
|
||||||
margin: const EdgeDims.only(right: 5.0)
|
margin: const EdgeDims.only(right: 5.0)
|
||||||
),
|
),
|
||||||
new Flexible(
|
new Flexible(
|
||||||
child: new Row([
|
child: new Row(<Widget>[
|
||||||
new Flexible(
|
new Flexible(
|
||||||
flex: 2,
|
flex: 2,
|
||||||
child: new Text(
|
child: new Text(
|
||||||
|
@ -42,7 +42,7 @@ class StockSettingsState extends State<StockSettings> {
|
|||||||
onDismiss: () {
|
onDismiss: () {
|
||||||
navigator.pop(false);
|
navigator.pop(false);
|
||||||
},
|
},
|
||||||
actions: [
|
actions: <Widget>[
|
||||||
new FlatButton(
|
new FlatButton(
|
||||||
child: new Text('NO THANKS'),
|
child: new Text('NO THANKS'),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
@ -84,26 +84,25 @@ class StockSettingsState extends State<StockSettings> {
|
|||||||
// TODO(ianh): Once we have the gesture API hooked up, fix https://github.com/domokit/mojo/issues/281
|
// TODO(ianh): Once we have the gesture API hooked up, fix https://github.com/domokit/mojo/issues/281
|
||||||
// (whereby tapping the widgets below causes both the widget and the menu item to fire their callbacks)
|
// (whereby tapping the widgets below causes both the widget and the menu item to fire their callbacks)
|
||||||
return new Material(
|
return new Material(
|
||||||
type: MaterialType.canvas,
|
|
||||||
child: new ScrollableViewport(
|
child: new ScrollableViewport(
|
||||||
child: new Container(
|
child: new Container(
|
||||||
padding: const EdgeDims.symmetric(vertical: 20.0),
|
padding: const EdgeDims.symmetric(vertical: 20.0),
|
||||||
child: new BlockBody([
|
child: new BlockBody(<Widget>[
|
||||||
new DrawerItem(
|
new DrawerItem(
|
||||||
icon: 'action/thumb_up',
|
icon: 'action/thumb_up',
|
||||||
onPressed: () => _confirmOptimismChange(),
|
onPressed: () => _confirmOptimismChange(),
|
||||||
child: new Row([
|
child: new Row(<Widget>[
|
||||||
new Flexible(child: new Text('Everything is awesome')),
|
new Flexible(child: new Text('Everything is awesome')),
|
||||||
new Checkbox(
|
new Checkbox(
|
||||||
value: config.optimism == StockMode.optimistic,
|
value: config.optimism == StockMode.optimistic,
|
||||||
onChanged: (_) => _confirmOptimismChange()
|
onChanged: (bool value) => _confirmOptimismChange()
|
||||||
),
|
),
|
||||||
])
|
])
|
||||||
),
|
),
|
||||||
new DrawerItem(
|
new DrawerItem(
|
||||||
icon: 'action/backup',
|
icon: 'action/backup',
|
||||||
onPressed: () { _handleBackupChanged(!(config.backup == BackupMode.enabled)); },
|
onPressed: () { _handleBackupChanged(!(config.backup == BackupMode.enabled)); },
|
||||||
child: new Row([
|
child: new Row(<Widget>[
|
||||||
new Flexible(child: new Text('Back up stock list to the cloud')),
|
new Flexible(child: new Text('Back up stock list to the cloud')),
|
||||||
new Switch(
|
new Switch(
|
||||||
value: config.backup == BackupMode.enabled,
|
value: config.backup == BackupMode.enabled,
|
||||||
|
@ -33,13 +33,12 @@ class StockSymbolViewerState extends State<StockSymbolViewer> {
|
|||||||
center: new Text('${config.stock.name} (${config.stock.symbol})')
|
center: new Text('${config.stock.name} (${config.stock.symbol})')
|
||||||
),
|
),
|
||||||
body: new Material(
|
body: new Material(
|
||||||
type: MaterialType.canvas,
|
child: new Block(<Widget>[
|
||||||
child: new Block([
|
|
||||||
new Container(
|
new Container(
|
||||||
padding: new EdgeDims.all(20.0),
|
padding: new EdgeDims.all(20.0),
|
||||||
child: new Column([
|
child: new Column(<Widget>[
|
||||||
new Text('Last Sale', style: headings),
|
new Text('Last Sale', style: headings),
|
||||||
new Text('${lastSale} (${changeInPrice})'),
|
new Text('$lastSale ($changeInPrice)'),
|
||||||
new Container(
|
new Container(
|
||||||
height: 8.0
|
height: 8.0
|
||||||
),
|
),
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
name: stocks
|
name: stocks
|
||||||
dependencies:
|
dependencies:
|
||||||
sky: any
|
flutter: ">=0.0.3 <0.1.0"
|
||||||
sky_tools: any
|
sky_tools: any
|
||||||
dependency_overrides:
|
dependency_overrides:
|
||||||
material_design_icons:
|
material_design_icons:
|
||||||
path: ../../sky/packages/material_design_icons
|
path: ../../sky/packages/material_design_icons
|
||||||
sky:
|
flutter:
|
||||||
path: ../../sky/packages/sky
|
path: ../../sky/packages/sky
|
||||||
|
@ -1,27 +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("//sky/build/skyx.gni")
|
|
||||||
|
|
||||||
skyx("sector") {
|
|
||||||
main_dart = "sector.dart"
|
|
||||||
}
|
|
||||||
|
|
||||||
skyx("piano") {
|
|
||||||
main_dart = "piano.dart"
|
|
||||||
}
|
|
||||||
|
|
||||||
skyx("cards") {
|
|
||||||
main_dart = "card_collection.dart"
|
|
||||||
}
|
|
||||||
|
|
||||||
group("widgets") {
|
|
||||||
testonly = true
|
|
||||||
|
|
||||||
deps = [
|
|
||||||
":cards",
|
|
||||||
":piano",
|
|
||||||
":sector",
|
|
||||||
]
|
|
||||||
}
|
|
12
examples/widgets/README
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
Small examples of the Flutter widget framework
|
||||||
|
==============================================
|
||||||
|
|
||||||
|
To run these, open a terminal in this directory and use the following
|
||||||
|
command:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pub global activate flutter
|
||||||
|
flutter start --checked -t foo.dart
|
||||||
|
```
|
||||||
|
|
||||||
|
...where `foo.dart` is the file you want to run.
|
@ -2,8 +2,7 @@
|
|||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
import 'package:sky/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:sky/widgets.dart';
|
|
||||||
|
|
||||||
class BigSwitch extends StatefulComponent {
|
class BigSwitch extends StatefulComponent {
|
||||||
BigSwitch({ this.scale });
|
BigSwitch({ this.scale });
|
||||||
|
@ -2,18 +2,19 @@
|
|||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
import 'dart:sky' as sky;
|
import 'dart:ui' as ui;
|
||||||
|
|
||||||
import 'package:sky/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:sky/painting.dart';
|
import 'package:flutter/painting.dart';
|
||||||
import 'package:sky/widgets.dart';
|
|
||||||
|
|
||||||
class CardModel {
|
class CardModel {
|
||||||
CardModel(this.value, this.height, this.color);
|
CardModel(this.value, this.height) {
|
||||||
|
label = "Item $value";
|
||||||
|
}
|
||||||
int value;
|
int value;
|
||||||
double height;
|
double height;
|
||||||
Color color;
|
int get color => ((value % 9) + 1) * 100;
|
||||||
String get label => "Item $value";
|
String label;
|
||||||
Key get key => new ObjectKey(this);
|
Key get key => new ObjectKey(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -36,6 +37,7 @@ class CardCollectionState extends State<CardCollection> {
|
|||||||
final TextStyle backgroundTextStyle =
|
final TextStyle backgroundTextStyle =
|
||||||
Typography.white.title.copyWith(textAlign: TextAlign.center);
|
Typography.white.title.copyWith(textAlign: TextAlign.center);
|
||||||
|
|
||||||
|
Map<int, Color> _primaryColor = Colors.deepPurple;
|
||||||
List<CardModel> _cardModels;
|
List<CardModel> _cardModels;
|
||||||
DismissDirection _dismissDirection = DismissDirection.horizontal;
|
DismissDirection _dismissDirection = DismissDirection.horizontal;
|
||||||
bool _snapToCenter = false;
|
bool _snapToCenter = false;
|
||||||
@ -50,19 +52,13 @@ class CardCollectionState extends State<CardCollection> {
|
|||||||
48.0, 63.0, 82.0, 146.0, 60.0, 55.0, 84.0, 96.0, 50.0,
|
48.0, 63.0, 82.0, 146.0, 60.0, 55.0, 84.0, 96.0, 50.0,
|
||||||
48.0, 63.0, 82.0, 146.0, 60.0, 55.0, 84.0, 96.0, 50.0
|
48.0, 63.0, 82.0, 146.0, 60.0, 55.0, 84.0, 96.0, 50.0
|
||||||
];
|
];
|
||||||
_cardModels = new List.generate(cardHeights.length, (i) {
|
_cardModels = new List.generate(cardHeights.length, (i) => new CardModel(i, cardHeights[i]));
|
||||||
Color color = Color.lerp(Colors.red[300], Colors.blue[900], i / cardHeights.length);
|
|
||||||
return new CardModel(i, cardHeights[i], color);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void _initFixedSizedCardModels() {
|
void _initFixedSizedCardModels() {
|
||||||
const int cardCount = 27;
|
const int cardCount = 27;
|
||||||
const double cardHeight = 100.0;
|
const double cardHeight = 100.0;
|
||||||
_cardModels = new List.generate(cardCount, (i) {
|
_cardModels = new List.generate(cardCount, (i) => new CardModel(i, cardHeight));
|
||||||
Color color = Color.lerp(Colors.red[300], Colors.blue[900], i / cardCount);
|
|
||||||
return new CardModel(i, cardHeight, color);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void _initCardModels() {
|
void _initCardModels() {
|
||||||
@ -126,9 +122,14 @@ class CardCollectionState extends State<CardCollection> {
|
|||||||
buildDrawerCheckbox("Fixed size cards", _fixedSizeCards, _toggleFixedSizeCards),
|
buildDrawerCheckbox("Fixed size cards", _fixedSizeCards, _toggleFixedSizeCards),
|
||||||
buildDrawerCheckbox("Let the sun shine", _sunshine, _toggleSunshine),
|
buildDrawerCheckbox("Let the sun shine", _sunshine, _toggleSunshine),
|
||||||
new DrawerDivider(),
|
new DrawerDivider(),
|
||||||
buildDrawerRadioItem(DismissDirection.horizontal, 'action/code'),
|
buildDrawerRadioItem("Deep Purple", Colors.deepPurple, _primaryColor, _selectColor),
|
||||||
buildDrawerRadioItem(DismissDirection.left, 'navigation/arrow_back'),
|
buildDrawerRadioItem("Green", Colors.green, _primaryColor, _selectColor),
|
||||||
buildDrawerRadioItem(DismissDirection.right, 'navigation/arrow_forward'),
|
buildDrawerRadioItem("Amber", Colors.amber, _primaryColor, _selectColor),
|
||||||
|
buildDrawerRadioItem("Teal", Colors.teal, _primaryColor, _selectColor),
|
||||||
|
new DrawerDivider(),
|
||||||
|
buildDrawerRadioItem("Dismiss horizontally", DismissDirection.horizontal, _dismissDirection, _changeDismissDirection, icon: 'action/code'),
|
||||||
|
buildDrawerRadioItem("Dismiss left", DismissDirection.left, _dismissDirection, _changeDismissDirection, icon: 'navigation/arrow_back'),
|
||||||
|
buildDrawerRadioItem("Dismiss right", DismissDirection.right, _dismissDirection, _changeDismissDirection, icon: 'navigation/arrow_forward'),
|
||||||
])
|
])
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
@ -158,6 +159,12 @@ class CardCollectionState extends State<CardCollection> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _selectColor(selection) {
|
||||||
|
setState(() {
|
||||||
|
_primaryColor = selection;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
void _changeDismissDirection(DismissDirection newDismissDirection) {
|
void _changeDismissDirection(DismissDirection newDismissDirection) {
|
||||||
setState(() {
|
setState(() {
|
||||||
_dismissDirection = newDismissDirection;
|
_dismissDirection = newDismissDirection;
|
||||||
@ -175,16 +182,16 @@ class CardCollectionState extends State<CardCollection> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget buildDrawerRadioItem(DismissDirection direction, String icon) {
|
Widget buildDrawerRadioItem(String label, itemValue, currentValue, RadioValueChanged onChanged, { String icon }) {
|
||||||
return new DrawerItem(
|
return new DrawerItem(
|
||||||
icon: icon,
|
icon: icon,
|
||||||
onPressed: () { _changeDismissDirection(direction); },
|
onPressed: () { onChanged(itemValue); },
|
||||||
child: new Row([
|
child: new Row([
|
||||||
new Flexible(child: new Text(_dismissDirectionText(direction))),
|
new Flexible(child: new Text(label)),
|
||||||
new Radio(
|
new Radio(
|
||||||
value: direction,
|
value: itemValue,
|
||||||
onChanged: _changeDismissDirection,
|
groupValue: currentValue,
|
||||||
groupValue: _dismissDirection
|
onChanged: onChanged
|
||||||
)
|
)
|
||||||
])
|
])
|
||||||
);
|
);
|
||||||
@ -210,11 +217,22 @@ class CardCollectionState extends State<CardCollection> {
|
|||||||
onResized: () { _invalidator([index]); },
|
onResized: () { _invalidator([index]); },
|
||||||
onDismissed: () { dismissCard(cardModel); },
|
onDismissed: () { dismissCard(cardModel); },
|
||||||
child: new Card(
|
child: new Card(
|
||||||
color: cardModel.color,
|
color: Theme.of(context).primarySwatch[cardModel.color],
|
||||||
child: new Container(
|
child: new Container(
|
||||||
height: cardModel.height,
|
height: cardModel.height,
|
||||||
padding: const EdgeDims.all(8.0),
|
padding: const EdgeDims.all(8.0),
|
||||||
child: new Center(child: new Text(cardModel.label, style: cardLabelStyle))
|
child: new Center(
|
||||||
|
child: new DefaultTextStyle(
|
||||||
|
style: cardLabelStyle,
|
||||||
|
child: new Input(
|
||||||
|
key: new GlobalObjectKey(cardModel),
|
||||||
|
initialValue: cardModel.label,
|
||||||
|
onChanged: (String value) {
|
||||||
|
cardModel.label = value;
|
||||||
|
}
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
@ -281,7 +299,7 @@ class CardCollectionState extends State<CardCollection> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
sky.Shader _createShader(Rect bounds) {
|
ui.Shader _createShader(Rect bounds) {
|
||||||
return new LinearGradient(
|
return new LinearGradient(
|
||||||
begin: Point.origin,
|
begin: Point.origin,
|
||||||
end: new Point(0.0, bounds.height),
|
end: new Point(0.0, bounds.height),
|
||||||
@ -341,21 +359,21 @@ class CardCollectionState extends State<CardCollection> {
|
|||||||
body = new Stack([body, indicator]);
|
body = new Stack([body, indicator]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Scaffold(
|
return new Theme(
|
||||||
toolBar: buildToolBar(),
|
data: new ThemeData(
|
||||||
body: body
|
primarySwatch: _primaryColor
|
||||||
|
),
|
||||||
|
child: new Scaffold(
|
||||||
|
toolBar: buildToolBar(),
|
||||||
|
body: body
|
||||||
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
runApp(new App(
|
runApp(new MaterialApp(
|
||||||
title: 'Cards',
|
title: 'Cards',
|
||||||
theme: new ThemeData(
|
|
||||||
brightness: ThemeBrightness.light,
|
|
||||||
primarySwatch: Colors.blue,
|
|
||||||
accentColor: Colors.redAccent[200]
|
|
||||||
),
|
|
||||||
routes: {
|
routes: {
|
||||||
'/': (RouteArguments args) => new CardCollection(navigator: args.navigator),
|
'/': (RouteArguments args) => new CardCollection(navigator: args.navigator),
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
import 'package:sky/widgets.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
class ContainerApp extends StatelessComponent {
|
class ContainerApp extends StatelessComponent {
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
@ -2,8 +2,7 @@
|
|||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
import 'package:sky/widgets.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:sky/material.dart';
|
|
||||||
|
|
||||||
void main() => runApp(new DatePickerDemo());
|
void main() => runApp(new DatePickerDemo());
|
||||||
|
|
||||||
|
@ -2,10 +2,9 @@
|
|||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
import 'package:sky/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:sky/painting.dart';
|
import 'package:flutter/painting.dart';
|
||||||
import 'package:sky/rendering.dart';
|
import 'package:flutter/rendering.dart';
|
||||||
import 'package:sky/widgets.dart';
|
|
||||||
|
|
||||||
class DragData {
|
class DragData {
|
||||||
DragData(this.text);
|
DragData(this.text);
|
||||||
@ -130,7 +129,7 @@ class DragAndDropAppState extends State<DragAndDropApp> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
runApp(new App(
|
runApp(new MaterialApp(
|
||||||
title: 'Drag and Drop Flutter Demo',
|
title: 'Drag and Drop Flutter Demo',
|
||||||
routes: {
|
routes: {
|
||||||
'/': (RouteArguments args) => new DragAndDropApp(navigator: args.navigator)
|
'/': (RouteArguments args) => new DragAndDropApp(navigator: args.navigator)
|
||||||
|
@ -2,8 +2,7 @@
|
|||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
import 'package:sky/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:sky/widgets.dart';
|
|
||||||
|
|
||||||
class CardModel {
|
class CardModel {
|
||||||
CardModel(this.value, this.height, this.color);
|
CardModel(this.value, this.height, this.color);
|
||||||
@ -14,7 +13,7 @@ class CardModel {
|
|||||||
Key get key => new ObjectKey(this);
|
Key get key => new ObjectKey(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
class EnsureVisibleApp extends App {
|
class EnsureVisibleApp extends MaterialApp {
|
||||||
|
|
||||||
static const TextStyle cardLabelStyle =
|
static const TextStyle cardLabelStyle =
|
||||||
const TextStyle(color: Colors.white, fontSize: 18.0, fontWeight: bold);
|
const TextStyle(color: Colors.white, fontSize: 18.0, fontWeight: bold);
|
@ -2,7 +2,7 @@
|
|||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
import 'package:sky/widgets.dart';
|
import 'package:flutter/widgets.dart';
|
||||||
|
|
||||||
class Circle extends StatelessComponent {
|
class Circle extends StatelessComponent {
|
||||||
Circle({ this.margin: EdgeDims.zero });
|
Circle({ this.margin: EdgeDims.zero });
|
||||||
|
70
examples/widgets/indexed_stack.dart
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
// 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:flutter/material.dart';
|
||||||
|
import 'package:flutter/rendering.dart';
|
||||||
|
|
||||||
|
class IndexedStackDemo extends StatefulComponent {
|
||||||
|
IndexedStackDemo({ this.navigator });
|
||||||
|
|
||||||
|
final NavigatorState navigator;
|
||||||
|
|
||||||
|
IndexedStackDemoState createState() => new IndexedStackDemoState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class IndexedStackDemoState extends State<IndexedStackDemo> {
|
||||||
|
int _itemCount = 7;
|
||||||
|
int _itemIndex = 0;
|
||||||
|
|
||||||
|
void _handleTap() {
|
||||||
|
setState(() {
|
||||||
|
_itemIndex = (_itemIndex + 1) % _itemCount;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
List <PopupMenuItem> _buildMenu(NavigatorState navigator) {
|
||||||
|
TextStyle style = const TextStyle(fontSize: 18.0, fontWeight: bold);
|
||||||
|
String pad = '';
|
||||||
|
return new List.generate(_itemCount, (int i) {
|
||||||
|
pad += '-';
|
||||||
|
return new PopupMenuItem(value: i, child: new Text('$pad Hello World $i $pad', style: style));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
List <PopupMenuItem> items = _buildMenu(config.navigator);
|
||||||
|
IndexedStack indexedStack = new IndexedStack(items, index: _itemIndex, horizontalAlignment: 0.5);
|
||||||
|
|
||||||
|
return new Scaffold(
|
||||||
|
toolBar: new ToolBar(center: new Text('IndexedStackDemo Demo')),
|
||||||
|
body: new GestureDetector(
|
||||||
|
onTap: _handleTap,
|
||||||
|
child: new Container(
|
||||||
|
decoration: new BoxDecoration(backgroundColor: Theme.of(context).primarySwatch[50]),
|
||||||
|
child: new Center(
|
||||||
|
child: new Container(
|
||||||
|
child: indexedStack,
|
||||||
|
padding: const EdgeDims.all(8.0),
|
||||||
|
decoration: new BoxDecoration(border: new Border.all(color: Theme.of(context).accentColor))
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
runApp(new MaterialApp(
|
||||||
|
title: 'IndexedStackDemo',
|
||||||
|
theme: new ThemeData(
|
||||||
|
brightness: ThemeBrightness.light,
|
||||||
|
primarySwatch: Colors.blue,
|
||||||
|
accentColor: Colors.redAccent[200]
|
||||||
|
),
|
||||||
|
routes: {
|
||||||
|
'/': (RouteArguments args) => new IndexedStackDemo(navigator: args.navigator),
|
||||||
|
}
|
||||||
|
));
|
||||||
|
}
|