Commit 1cf1cf9c authored by Hixie's avatar Hixie

Port first sector demo to fn3

Also, fix warnings in rendering/sector_layout.dart
Also, fix hit testing in rendering/sector_layout.dart
Also, add WidgetToRenderBoxAdapter
Also, make the rendering library debugging tools more resilient to
dumping stuff before layout is complete.
parent 8f65e0cb
name: raw name: sky_raw_examples
dependencies: dependencies:
flutter: ">=0.0.3 <0.1.0" flutter: ">=0.0.3 <0.1.0"
sky_tools: any sky_tools: any
......
This diff is collapsed.
name: rendering name: flutter_rendering_examples
dependencies: dependencies:
flutter: ">=0.0.3 <0.1.0" flutter: ">=0.0.3 <0.1.0"
sky_tools: any sky_tools: any
......
This diff is collapsed.
name: widgets name: sky_widgets_examples
dependencies: dependencies:
flutter: ">=0.0.3 <0.1.0" flutter: ">=0.0.3 <0.1.0"
sky_tools: any sky_tools: any
flutter_rendering_examples: any
dependency_overrides: dependency_overrides:
material_design_icons: material_design_icons:
path: ../../sky/packages/material_design_icons path: ../../sky/packages/material_design_icons
flutter: flutter:
path: ../../sky/packages/sky path: ../../sky/packages/sky
flutter_rendering_examples:
path: ../rendering
...@@ -7,7 +7,7 @@ import 'dart:math' as math; ...@@ -7,7 +7,7 @@ import 'dart:math' as math;
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart'; import 'package:flutter/rendering.dart';
import '../rendering/sector_layout.dart'; import 'package:flutter_rendering_examples/sector_layout.dart';
RenderBox initCircle() { RenderBox initCircle() {
return new RenderBoxToRenderSectorAdapter( return new RenderBoxToRenderSectorAdapter(
...@@ -16,10 +16,14 @@ RenderBox initCircle() { ...@@ -16,10 +16,14 @@ RenderBox initCircle() {
); );
} }
class SectorApp extends MaterialApp { class SectorApp extends StatefulComponent {
SectorAppState createState() => new SectorAppState();
}
class SectorAppState extends State<SectorApp> {
RenderBoxToRenderSectorAdapter sectors = initCircle(); final RenderBoxToRenderSectorAdapter sectors = initCircle();
math.Random rand = new math.Random(1); final math.Random rand = new math.Random(1);
void addSector() { void addSector() {
double deltaTheta; double deltaTheta;
...@@ -52,27 +56,27 @@ class SectorApp extends MaterialApp { ...@@ -52,27 +56,27 @@ class SectorApp extends MaterialApp {
RenderBoxToRenderSectorAdapter sectorAddIcon = initSector(const Color(0xFF00DD00)); RenderBoxToRenderSectorAdapter sectorAddIcon = initSector(const Color(0xFF00DD00));
RenderBoxToRenderSectorAdapter sectorRemoveIcon = initSector(const Color(0xFFDD0000)); RenderBoxToRenderSectorAdapter sectorRemoveIcon = initSector(const Color(0xFFDD0000));
bool enabledAdd = true; bool _enabledAdd = true;
bool enabledRemove = false; bool _enabledRemove = false;
void updateEnabledState() { void updateEnabledState() {
setState(() { setState(() {
var ring = (sectors.child as RenderSectorRing); var ring = (sectors.child as RenderSectorRing);
SectorDimensions currentSize = ring.getIntrinsicDimensions(const SectorConstraints(), ring.deltaRadius); SectorDimensions currentSize = ring.getIntrinsicDimensions(const SectorConstraints(), ring.deltaRadius);
enabledAdd = currentSize.deltaTheta < kTwoPi; _enabledAdd = currentSize.deltaTheta < kTwoPi;
enabledRemove = ring.firstChild != null; _enabledRemove = ring.firstChild != null;
}); });
} }
Widget buildBody() { Widget buildBody() {
return new Material( return new Material(
child: new Column([ child: new Column(<Widget>[
new Container( new Container(
padding: new EdgeDims.symmetric(horizontal: 8.0, vertical: 25.0), padding: new EdgeDims.symmetric(horizontal: 8.0, vertical: 25.0),
child: new Row([ child: new Row(<Widget>[
new RaisedButton( new RaisedButton(
enabled: enabledAdd, enabled: _enabledAdd,
child: new IntrinsicWidth( child: new IntrinsicWidth(
child: new Row([ child: new Row(<Widget>[
new Container( new Container(
padding: new EdgeDims.all(4.0), padding: new EdgeDims.all(4.0),
margin: new EdgeDims.only(right: 10.0), margin: new EdgeDims.only(right: 10.0),
...@@ -84,9 +88,9 @@ class SectorApp extends MaterialApp { ...@@ -84,9 +88,9 @@ class SectorApp extends MaterialApp {
onPressed: addSector onPressed: addSector
), ),
new RaisedButton( new RaisedButton(
enabled: enabledRemove, enabled: _enabledRemove,
child: new IntrinsicWidth( child: new IntrinsicWidth(
child: new Row([ child: new Row(<Widget>[
new Container( new Container(
padding: new EdgeDims.all(4.0), padding: new EdgeDims.all(4.0),
margin: new EdgeDims.only(right: 10.0), margin: new EdgeDims.only(right: 10.0),
...@@ -117,18 +121,20 @@ class SectorApp extends MaterialApp { ...@@ -117,18 +121,20 @@ class SectorApp extends MaterialApp {
); );
} }
Widget build() { Widget build(BuildContext context) {
return new Theme( return new MaterialApp(
data: new ThemeData.light(), theme: new ThemeData.light(),
child: new Title( title: 'Sector Layout',
title: 'Sector Layout', routes: <String, RouteBuilder>{
child: new Scaffold( '/': (RouteArguments args) {
toolBar: new ToolBar( return new Scaffold(
center: new Text('Sector Layout in a Widget Tree') toolBar: new ToolBar(
), center: new Text('Sector Layout in a Widget Tree')
body: buildBody() ),
) body: buildBody()
) );
}
}
); );
} }
} }
......
...@@ -633,7 +633,7 @@ abstract class RenderBox extends RenderObject { ...@@ -633,7 +633,7 @@ abstract class RenderBox extends RenderObject {
} }
} }
String debugDescribeSettings(String prefix) => '${super.debugDescribeSettings(prefix)}${prefix}size: $size\n'; String debugDescribeSettings(String prefix) => '${super.debugDescribeSettings(prefix)}${prefix}size: ${ hasSize ? size : "MISSING" }\n';
} }
/// A mixin that provides useful default behaviors for boxes with children /// A mixin that provides useful default behaviors for boxes with children
......
...@@ -961,6 +961,22 @@ class AssetImage extends StatelessComponent { ...@@ -961,6 +961,22 @@ class AssetImage extends StatelessComponent {
} }
} }
class WidgetToRenderBoxAdapter extends LeafRenderObjectWidget {
WidgetToRenderBoxAdapter(RenderBox renderBox)
: renderBox = renderBox,
// WidgetToRenderBoxAdapter objects are keyed to their render box. This
// prevents the widget being used in the widget hierarchy in two different
// places, which would cause the RenderBox to get inserted in multiple
// places in the RenderObject tree.
super(key: new GlobalObjectKey(renderBox)) {
assert(renderBox != null);
}
final RenderBox renderBox;
RenderBox createRenderObject() => renderBox;
}
// EVENT HANDLING // EVENT HANDLING
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment