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:
flutter: ">=0.0.3 <0.1.0"
sky_tools: any
......
This diff is collapsed.
name: rendering
name: flutter_rendering_examples
dependencies:
flutter: ">=0.0.3 <0.1.0"
sky_tools: any
......
This diff is collapsed.
name: widgets
name: sky_widgets_examples
dependencies:
flutter: ">=0.0.3 <0.1.0"
sky_tools: any
flutter_rendering_examples: any
dependency_overrides:
material_design_icons:
path: ../../sky/packages/material_design_icons
flutter:
path: ../../sky/packages/sky
flutter_rendering_examples:
path: ../rendering
......@@ -7,7 +7,7 @@ import 'dart:math' as math;
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import '../rendering/sector_layout.dart';
import 'package:flutter_rendering_examples/sector_layout.dart';
RenderBox initCircle() {
return new RenderBoxToRenderSectorAdapter(
......@@ -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();
math.Random rand = new math.Random(1);
final RenderBoxToRenderSectorAdapter sectors = initCircle();
final math.Random rand = new math.Random(1);
void addSector() {
double deltaTheta;
......@@ -52,27 +56,27 @@ class SectorApp extends MaterialApp {
RenderBoxToRenderSectorAdapter sectorAddIcon = initSector(const Color(0xFF00DD00));
RenderBoxToRenderSectorAdapter sectorRemoveIcon = initSector(const Color(0xFFDD0000));
bool enabledAdd = true;
bool enabledRemove = false;
bool _enabledAdd = true;
bool _enabledRemove = false;
void updateEnabledState() {
setState(() {
var ring = (sectors.child as RenderSectorRing);
SectorDimensions currentSize = ring.getIntrinsicDimensions(const SectorConstraints(), ring.deltaRadius);
enabledAdd = currentSize.deltaTheta < kTwoPi;
enabledRemove = ring.firstChild != null;
_enabledAdd = currentSize.deltaTheta < kTwoPi;
_enabledRemove = ring.firstChild != null;
});
}
Widget buildBody() {
return new Material(
child: new Column([
child: new Column(<Widget>[
new Container(
padding: new EdgeDims.symmetric(horizontal: 8.0, vertical: 25.0),
child: new Row([
child: new Row(<Widget>[
new RaisedButton(
enabled: enabledAdd,
enabled: _enabledAdd,
child: new IntrinsicWidth(
child: new Row([
child: new Row(<Widget>[
new Container(
padding: new EdgeDims.all(4.0),
margin: new EdgeDims.only(right: 10.0),
......@@ -84,9 +88,9 @@ class SectorApp extends MaterialApp {
onPressed: addSector
),
new RaisedButton(
enabled: enabledRemove,
enabled: _enabledRemove,
child: new IntrinsicWidth(
child: new Row([
child: new Row(<Widget>[
new Container(
padding: new EdgeDims.all(4.0),
margin: new EdgeDims.only(right: 10.0),
......@@ -117,18 +121,20 @@ class SectorApp extends MaterialApp {
);
}
Widget build() {
return new Theme(
data: new ThemeData.light(),
child: new Title(
title: 'Sector Layout',
child: new Scaffold(
toolBar: new ToolBar(
center: new Text('Sector Layout in a Widget Tree')
),
body: buildBody()
)
)
Widget build(BuildContext context) {
return new MaterialApp(
theme: new ThemeData.light(),
title: 'Sector Layout',
routes: <String, RouteBuilder>{
'/': (RouteArguments args) {
return new Scaffold(
toolBar: new ToolBar(
center: new Text('Sector Layout in a Widget Tree')
),
body: buildBody()
);
}
}
);
}
}
......
......@@ -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
......
......@@ -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
......
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