Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(350)

Side by Side Diff: sky/sdk/example/widgets/block_viewport.dart

Issue 1222913013: Introduce BlockViewport. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « sky/sdk/BUILD.gn ('k') | sky/sdk/lib/rendering/block.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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/sky_binding.dart';
8 import 'package:sky/widgets/basic.dart';
9 import 'package:sky/widgets/block_viewport.dart';
10 import 'package:sky/widgets/material.dart';
11 import 'package:sky/widgets/raised_button.dart';
12 import 'package:sky/widgets/scaffold.dart';
13 import 'package:sky/widgets/theme.dart';
14 import 'package:sky/widgets/tool_bar.dart';
15 import 'package:sky/widgets/widget.dart';
16
17 class BlockViewportApp extends App {
18
19 List<double> lengths = <double>[];
20 double offset = 0.0;
21
22 static const double kMaxLength = 100.0;
23
24 static math.Random rand = new math.Random();
25
26 void addBox() {
27 lengths.add(rand.nextDouble() * kMaxLength);
28 updateEnabledState();
29 }
30
31 void removeBox(int index) {
32 lengths.removeAt(index);
33 updateEnabledState();
34 }
35
36 void goUp() {
37 offset -= 9.9;
38 updateEnabledState();
39 }
40
41 void goDown() {
42 offset += 20.45;
43 updateEnabledState();
44 }
45
46 bool enabledDown = true;
47 bool enabledUp = true;
48 bool enabledAdd = true;
49 bool enabledRemove = false;
50 void updateEnabledState() {
51 setState(() {
52 enabledUp = offset > -100.0;
53 enabledDown = offset < lengths.fold(0.0, (double result, double len) => re sult + len) + 100.0;
54 enabledAdd = true;
55 enabledRemove = lengths.length > 0;
56 });
57 }
58
59 Widget build() {
60 return new Theme(
61 data: new ThemeData.light(),
62 child: new Scaffold(
63 toolbar: new ToolBar(
64 center: new Text('Block Viewport Demo')),
65 body: new Material(
66 type: MaterialType.canvas,
67 child: new Flex([
68 new Container(
69 padding: new EdgeDims.symmetric(horizontal: 8.0, vertical: 25.0) ,
70 child: new Flex([
71 new RaisedButton(
72 enabled: enabledAdd,
73 child: new Text('ADD'),
74 onPressed: addBox
75 ),
76 new RaisedButton(
77 enabled: enabledUp,
78 child: new Text('UP'),
79 onPressed: goUp
80 ),
81 new RaisedButton(
82 enabled: enabledDown,
83 child: new Text('DOWN'),
84 onPressed: goDown
85 )
86 ],
87 justifyContent: FlexJustifyContent.spaceAround
88 )
89 ),
90 new Flexible(
91 child: new Container(
92 margin: new EdgeDims.all(8.0),
93 decoration: new BoxDecoration(
94 border: new Border.all(new BorderSide(color: new Color(0xFF0 00000)))
95 ),
96 padding: new EdgeDims.all(16.0),
97 child: new BlockViewport(
98 builder: builder,
99 startOffset: offset,
100 token: lengths.length
101 )
102 )
103 ),
104 ],
105 direction: FlexDirection.vertical,
106 justifyContent: FlexJustifyContent.spaceBetween
107 )
108 )
109 )
110 );
111 }
112
113 Widget builder(int index) {
114 if (index >= lengths.length)
115 return null;
116 return new Listener(
117 key: lengths[index].toString(),
118 child: new Container(
119 decoration: new BoxDecoration(
120 backgroundColor: new Color((0xFF000000 + 0xFFFFFF * lengths[index] / k MaxLength).round())
121 ),
122 height: lengths[index] + 12.0
123 ),
124 onGestureTap: (_) {
125 removeBox(index);
126 }
127 );
128 }
129
130 }
131
132 void main() {
133 runApp(new BlockViewportApp());
134 SkyBinding.instance.onFrame = () {
135 // uncomment this for debugging:
136 // SkyBinding.instance.debugDumpRenderTree();
137 };
138 }
OLDNEW
« no previous file with comments | « sky/sdk/BUILD.gn ('k') | sky/sdk/lib/rendering/block.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698