提交 e8b2d8ad 编写于 作者: E Eric Seidel

Update paths in sky_home.dart

I also removed the leading /, so it is now possible
to use shelldb start sky/sky_home to test.

Also fixed touch_demo.dart and sector layout to
work and not crash.

R=ianh@google.com

Review URL: https://codereview.chromium.org/1177343002.
上级 2795216f
......@@ -4,18 +4,22 @@
import 'dart:math';
import 'dart:sky';
import 'package:sky/framework/app.dart';
import 'package:sky/framework/rendering/box.dart';
import 'package:sky/framework/rendering/object.dart';
import 'package:sky/framework/rendering/paragraph.dart';
import 'package:sky/framework/rendering/stack.dart';
import 'package:sky/framework/theme2/colors.dart';
// Material design colors. :p
List<int> colors = [
0xFF009688,
0xFFFFC107,
0xFF9C27B0,
0xFF03A9F4,
0xFF673AB7,
0xFFCDDC39,
List<Color> colors = [
Teal[500],
Amber[500],
Purple[500],
LightBlue[500],
DeepPurple[500],
Lime[500],
];
class Dot {
......@@ -24,7 +28,7 @@ class Dot {
double y = 0.0;
double radius = 0.0;
Dot({int color}) : _paint = new Paint()..color = color;
Dot({ Color color }) : _paint = new Paint()..color = color;
void update(PointerEvent event) {
x = event.x;
......@@ -45,7 +49,7 @@ class RenderTouchDemo extends RenderBox {
void handleEvent(Event event, BoxHitTestEntry entry) {
switch (event.type) {
case 'pointerdown':
int color = colors[event.pointer.remainder(colors.length)];
Color color = colors[event.pointer.remainder(colors.length)];
dots[event.pointer] = new Dot(color: color)..update(event);
break;
case 'pointerup':
......@@ -66,14 +70,23 @@ class RenderTouchDemo extends RenderBox {
}
void paint(RenderObjectDisplayList canvas) {
dots.forEach((_, Dot dot) {
Paint white = new Paint()..color = const Color(0xFFFFFFFF);
canvas.drawRect(new Rect.fromSize(size), white);
for (Dot dot in dots.values)
dot.paint(canvas);
});
}
}
AppView app;
void main() {
app = new AppView(new RenderTouchDemo());
var para = new RenderParagraph(text: "Touch me!");
var stack = new RenderStack(children: [
new RenderTouchDemo(),
para,
]);
// Make the paragraph not fill the whole screen so it doesn't eat events.
para.parentData..top = 40.0
..left = 20.0;
app = new AppView(stack);
}
......@@ -134,19 +134,12 @@ class BoxConstraints {
final double minHeight;
final double maxHeight;
static double _clamp({double min: 0.0, double value: 0.0, double max: double.INFINITY}) {
assert(min != null);
assert(value != null);
assert(max != null);
return math.max(min, math.min(max, value));
}
double constrainWidth(double width) {
return _clamp(min: minWidth, max: maxWidth, value: width);
return clamp(min: minWidth, max: maxWidth, value: width);
}
double constrainHeight(double height) {
return _clamp(min: minHeight, max: maxHeight, value: height);
return clamp(min: minHeight, max: maxHeight, value: height);
}
Size constrain(Size size) {
......@@ -190,19 +183,19 @@ abstract class RenderBox extends RenderObject {
child.parentData = new BoxParentData();
}
// getMinIntrinsicWidth() should return the minimum width that this box could
// getMinIntrinsicWidth() should return the minimum width that this box could
// be without failing to render its contents within itself.
double getMinIntrinsicWidth(BoxConstraints constraints) {
return constraints.constrainWidth(0.0);
}
// getMaxIntrinsicWidth() should return the smallest width beyond which
// getMaxIntrinsicWidth() should return the smallest width beyond which
// increasing the width never decreases the height.
double getMaxIntrinsicWidth(BoxConstraints constraints) {
return constraints.constrainWidth(0.0);
}
// getMinIntrinsicHeight() should return the minimum height that this box could
// getMinIntrinsicHeight() should return the minimum height that this box could
// be without failing to render its contents within itself.
double getMinIntrinsicHeight(BoxConstraints constraints) {
return constraints.constrainHeight(0.0);
......
......@@ -2,10 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import '../node.dart';
import '../scheduler.dart' as scheduler;
import 'dart:math' as math;
import 'dart:sky' as sky;
import 'dart:sky' show Point, Size, Rect, Color, Paint, Path;
import '../node.dart';
import '../scheduler.dart' as scheduler;
export 'dart:sky' show Point, Size, Rect, Color, Paint, Path;
class ParentData {
......@@ -266,6 +269,13 @@ class HitTestResult {
}
}
double clamp({ double min: 0.0, double value: 0.0, double max: double.INFINITY }) {
assert(min != null);
assert(value != null);
assert(max != null);
return math.max(min, math.min(max, value));
}
// GENERIC MIXIN FOR RENDER NODES WITH ONE CHILD
......
......@@ -29,18 +29,18 @@ class SkyHome extends App {
UINode build() {
List<UINode> children = [
new SkyLink('Stocks2 App', '/examples/stocks2/lib/stock_app.dart'),
new SkyLink('Interactive Flex', '/examples/raw/interactive_flex.dart'),
new SkyLink('Ink Well', '/examples/raw/ink_well.dart'),
new SkyLink('Box2D Game', '/examples/game/main.dart'),
new SkyLink('Sector Layout', '/examples/raw/sector_layout.dart'),
new SkyLink('Stocks2 App', 'examples/stocks2/lib/stock_app.dart'),
new SkyLink('Box2D Game', 'examples/game/main.dart'),
new SkyLink('Interactive Flex', 'examples/rendering/interactive_flex.dart'),
new SkyLink('Sector Layout', 'examples/rendering/sector_layout.dart'),
new SkyLink('Touch Demo', 'examples/rendering/touch_demo.dart'),
// TODO(eseidel): We could use to separate these groups?
new SkyLink('Stocks App (Old)', '/examples/stocks/main.sky'),
new SkyLink('Touch Demo (Old)', '/examples/raw/touch-demo.sky'),
new SkyLink('Spinning Square (Old)', '/examples/raw/spinning-square.sky'),
new SkyLink('Stocks App (Old)', 'examples/stocks/main.sky'),
new SkyLink('Touch Demo (Old)', 'examples/raw/touch-demo.sky'),
new SkyLink('Spinning Square (Old)', 'examples/raw/spinning-square.sky'),
new SkyLink('Licences (Old)', '/LICENSES.sky'),
new SkyLink('Licences (Old)', 'LICENSES.sky'),
];
return new Scaffold(
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册