Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 import 'dart:math' as math; | |
| 6 | |
| 7 import 'package:sky/rendering/box.dart'; | |
| 8 import 'package:sky/rendering/flex.dart'; | |
| 9 import 'package:sky/theme2/colors.dart'; | |
| 10 import 'package:sky/theme2/edges.dart'; | |
| 11 import 'package:sky/theme2/typography.dart'; | |
| 12 import 'package:sky/widgets/basic.dart'; | |
| 13 import 'package:sky/widgets/material.dart'; | |
| 14 import 'package:sky/widgets/raised_button.dart'; | |
| 15 import 'package:sky/widgets/scaffold.dart'; | |
| 16 import 'package:sky/widgets/tool_bar.dart'; | |
| 17 import 'package:sky/widgets/ui_node.dart'; | |
| 18 | |
| 19 import '../rendering/sector_layout.dart'; | |
| 20 | |
| 21 RenderBox initCircle() { | |
| 22 return new RenderBoxToRenderSectorAdapter( | |
| 23 innerRadius: 25.0, | |
| 24 child: new RenderSectorRing(padding: 0.0) | |
| 25 ); | |
| 26 } | |
| 27 | |
| 28 class ContainerApp extends App { | |
|
abarth-chromium
2015/06/16 02:32:34
s/ContainerApp/SectorApp/
| |
| 29 | |
| 30 RenderBoxToRenderSectorAdapter sectors = initCircle(); | |
| 31 math.Random rand = new math.Random(); | |
| 32 | |
| 33 void addSector() { | |
| 34 double deltaTheta; | |
| 35 var ring = (sectors.child as RenderSectorRing); | |
| 36 SectorDimensions currentSize = ring.getIntrinsicDimensions(const SectorConst raints(), ring.deltaRadius); | |
| 37 if (currentSize.deltaTheta >= kTwoPi - (math.PI * 0.2 + 0.05)) | |
| 38 deltaTheta = kTwoPi - currentSize.deltaTheta; | |
| 39 else | |
| 40 deltaTheta = math.PI * rand.nextDouble() / 5.0 + 0.05; | |
| 41 Color color = new Color(((0xFF << 24) + rand.nextInt(0xFFFFFF)) | 0x808080); | |
|
abarth-chromium
2015/06/16 02:32:34
I would have used | rather than +, but it's all th
| |
| 42 ring.add(new RenderSolidColor(color, desiredDeltaTheta: deltaTheta)); | |
| 43 updateEnabledState(); | |
| 44 } | |
| 45 | |
| 46 void removeSector() { | |
| 47 (sectors.child as RenderSectorRing).remove((sectors.child as RenderSectorRin g).lastChild); | |
| 48 updateEnabledState(); | |
| 49 } | |
| 50 | |
| 51 static RenderBox initSector(Color color) { | |
| 52 RenderSectorRing ring = new RenderSectorRing(padding: 1.0); | |
| 53 ring.add(new RenderSolidColor(const Color(0xFF909090), desiredDeltaTheta: kT woPi * 0.15)); | |
| 54 ring.add(new RenderSolidColor(const Color(0xFF909090), desiredDeltaTheta: kT woPi * 0.15)); | |
| 55 ring.add(new RenderSolidColor(color, desiredDeltaTheta: kTwoPi * 0.2)); | |
| 56 return new RenderBoxToRenderSectorAdapter( | |
| 57 innerRadius: 5.0, | |
| 58 child: ring | |
| 59 ); | |
| 60 } | |
| 61 RenderBoxToRenderSectorAdapter sectorAddIcon = initSector(const Color(0xFF00DD 00)); | |
| 62 RenderBoxToRenderSectorAdapter sectorRemoveIcon = initSector(const Color(0xFFD D0000)); | |
| 63 | |
| 64 bool enabledAdd = true; | |
| 65 bool enabledRemove = false; | |
| 66 void updateEnabledState() { | |
| 67 setState(() { | |
| 68 var ring = (sectors.child as RenderSectorRing); | |
| 69 SectorDimensions currentSize = ring.getIntrinsicDimensions(const SectorCon straints(), ring.deltaRadius); | |
| 70 enabledAdd = currentSize.deltaTheta < kTwoPi; | |
| 71 enabledRemove = ring.firstChild != null; | |
| 72 }); | |
| 73 } | |
| 74 | |
| 75 UINode build() { | |
| 76 return new Scaffold( | |
| 77 toolbar: new ToolBar( | |
| 78 center: new Text('Sector Layout in a Widget Tree', style: white.title) , | |
| 79 backgroundColor: Blue[500]), | |
| 80 body: new Material( | |
| 81 edge: MaterialEdge.canvas, | |
| 82 child: new Flex([ | |
| 83 new Container( | |
| 84 padding: new EdgeDims.symmetric(horizontal: 8.0, vertical: 25.0), | |
| 85 child: new Flex([ | |
| 86 new RaisedButton( | |
| 87 key: 'add-button', | |
| 88 enabled: enabledAdd, | |
| 89 child: new ShrinkWrapWidth( | |
| 90 child: new Flex([ | |
| 91 new Container( | |
| 92 padding: new EdgeDims.all(4.0), | |
| 93 margin: new EdgeDims.only(right: 10.0), | |
| 94 child: new UINodeToRenderBoxAdapter(sectorAddIcon) | |
| 95 ), | |
| 96 new Text('ADD SECTOR'), | |
| 97 ]) | |
| 98 ), | |
| 99 onPressed: addSector | |
| 100 ), | |
| 101 new RaisedButton( | |
| 102 key: 'remove-button', | |
| 103 enabled: enabledRemove, | |
| 104 child: new ShrinkWrapWidth( | |
| 105 child: new Flex([ | |
| 106 new Container( | |
| 107 padding: new EdgeDims.all(4.0), | |
| 108 margin: new EdgeDims.only(right: 10.0), | |
| 109 child: new UINodeToRenderBoxAdapter(sectorRemoveIcon) | |
| 110 ), | |
| 111 new Text('REMOVE SECTOR'), | |
| 112 ]) | |
| 113 ), | |
| 114 onPressed: removeSector | |
| 115 ) | |
| 116 ], | |
| 117 justifyContent: FlexJustifyContent.spaceAround | |
| 118 ) | |
| 119 ), | |
| 120 new FlexExpandingChild( | |
| 121 new Container( | |
| 122 margin: new EdgeDims.all(8.0), | |
| 123 decoration: new BoxDecoration( | |
| 124 border: new Border.all(new BorderSide(color: new Color(0xFF000 000))) | |
| 125 ), | |
| 126 padding: new EdgeDims.all(8.0), | |
| 127 child: new UINodeToRenderBoxAdapter(sectors) | |
| 128 ) | |
| 129 ), | |
| 130 ], | |
| 131 direction: FlexDirection.vertical, | |
| 132 justifyContent: FlexJustifyContent.spaceBetween | |
| 133 ) | |
| 134 ) | |
| 135 ); | |
| 136 } | |
| 137 } | |
| 138 | |
| 139 void main() { | |
| 140 App app = new ContainerApp(); | |
| 141 UINodeAppView.appView.onFrame = () { | |
| 142 // uncomment this for debugging: | |
| 143 // UINodeAppView.appView.debugDumpRenderTree(); | |
| 144 }; | |
| 145 } | |
| OLD | NEW |