Commit 529fa95f authored by Adam Barth's avatar Adam Barth

Give the CustomPaint and SizeObserver callbacks better names

The style we use for callbacks in widgets is "onFoo". These classes were using
an order naming convention and just called their callbacks "callback".
parent 2edc6dbb
...@@ -159,7 +159,7 @@ class TextureButtonState extends State<TextureButton> { ...@@ -159,7 +159,7 @@ class TextureButtonState extends State<TextureButton> {
width: config.width, width: config.width,
height: config.height, height: config.height,
child: new CustomPaint( child: new CustomPaint(
callback: paintCallback, onPaint: paintCallback,
token: new _TextureButtonToken( token: new _TextureButtonToken(
_highlight, _highlight,
config.texture, config.texture,
......
...@@ -37,7 +37,7 @@ RenderBox getBox(double lh) { ...@@ -37,7 +37,7 @@ RenderBox getBox(double lh) {
padding: new EdgeDims.all(10.0), padding: new EdgeDims.all(10.0),
child: new RenderCustomPaint( child: new RenderCustomPaint(
child: paragraph, child: paragraph,
callback: (canvas, size) { onPaint: (canvas, size) {
double baseline = paragraph.getDistanceToBaseline(TextBaseline.alphabetic); double baseline = paragraph.getDistanceToBaseline(TextBaseline.alphabetic);
double w = paragraph.getMaxIntrinsicWidth(new BoxConstraints.loose(size)); double w = paragraph.getMaxIntrinsicWidth(new BoxConstraints.loose(size));
double h = paragraph.getMaxIntrinsicHeight(new BoxConstraints.loose(size)); double h = paragraph.getMaxIntrinsicHeight(new BoxConstraints.loose(size));
......
...@@ -25,7 +25,7 @@ class StockArrow extends StatelessComponent { ...@@ -25,7 +25,7 @@ class StockArrow extends StatelessComponent {
// TODO(jackson): This should change colors with the theme // TODO(jackson): This should change colors with the theme
Color color = _colorForPercentChange(percentChange); Color color = _colorForPercentChange(percentChange);
const double kSize = 40.0; const double kSize = 40.0;
var arrow = new CustomPaint(callback: (ui.Canvas canvas, Size size) { var arrow = new CustomPaint(onPaint: (ui.Canvas canvas, Size size) {
Paint paint = new Paint()..color = color; Paint paint = new Paint()..color = color;
paint.strokeWidth = 1.0; paint.strokeWidth = 1.0;
const double padding = 2.0; const double padding = 2.0;
......
...@@ -337,7 +337,7 @@ class CardCollectionState extends State<CardCollection> { ...@@ -337,7 +337,7 @@ class CardCollectionState extends State<CardCollection> {
]); ]);
Widget body = new SizeObserver( Widget body = new SizeObserver(
callback: _updateCardCollectionSize, onSizeChanged: _updateCardCollectionSize,
child: new Container( child: new Container(
padding: const EdgeDims.symmetric(vertical: 12.0, horizontal: 8.0), padding: const EdgeDims.symmetric(vertical: 12.0, horizontal: 8.0),
decoration: new BoxDecoration(backgroundColor: Theme.of(context).primarySwatch[50]), decoration: new BoxDecoration(backgroundColor: Theme.of(context).primarySwatch[50]),
......
...@@ -58,7 +58,7 @@ class Marker extends StatelessComponent { ...@@ -58,7 +58,7 @@ class Marker extends StatelessComponent {
child: new Container( child: new Container(
width: size, width: size,
height: size, height: size,
child: new CustomPaint(callback: paintMarker) child: new CustomPaint(onPaint: paintMarker)
) )
) )
); );
......
...@@ -136,7 +136,7 @@ class PageableListAppState extends State<PageableListApp> { ...@@ -136,7 +136,7 @@ class PageableListAppState extends State<PageableListApp> {
: pageSize.width : pageSize.width
); );
return new SizeObserver( return new SizeObserver(
callback: updatePageSize, onSizeChanged: updatePageSize,
child: list child: list
); );
} }
......
...@@ -63,7 +63,7 @@ class ScaleAppState extends State<ScaleApp> { ...@@ -63,7 +63,7 @@ class ScaleAppState extends State<ScaleApp> {
body: new GestureDetector( body: new GestureDetector(
onScaleStart: _handleScaleStart, onScaleStart: _handleScaleStart,
onScaleUpdate: _handleScaleUpdate, onScaleUpdate: _handleScaleUpdate,
child: new CustomPaint(callback: paint, token: "$_zoom $_offset") child: new CustomPaint(onPaint: paint, token: "$_zoom $_offset")
) )
) )
); );
......
...@@ -116,7 +116,7 @@ class _InputState extends ScrollableState<Input> { ...@@ -116,7 +116,7 @@ class _InputState extends ScrollableState<Input> {
return new Listener( return new Listener(
child: new SizeObserver( child: new SizeObserver(
callback: _handleContainerSizeChanged, onSizeChanged: _handleContainerSizeChanged,
child: new Container( child: new Container(
child: new Stack(textChildren), child: new Stack(textChildren),
padding: _kTextfieldPadding, padding: _kTextfieldPadding,
......
...@@ -75,7 +75,7 @@ class PopupMenu extends StatelessComponent { ...@@ -75,7 +75,7 @@ class PopupMenu extends StatelessComponent {
variables: <AnimatedValue<double>>[width, height], variables: <AnimatedValue<double>>[width, height],
builder: (BuildContext context) { builder: (BuildContext context) {
return new CustomPaint( return new CustomPaint(
callback: (ui.Canvas canvas, Size size) { onPaint: (ui.Canvas canvas, Size size) {
double widthValue = width.value * size.width; double widthValue = width.value * size.width;
double heightValue = height.value * size.height; double heightValue = height.value * size.height;
painter.paint(canvas, new Rect.fromLTWH(size.width - widthValue, 0.0, widthValue, heightValue)); painter.paint(canvas, new Rect.fromLTWH(size.width - widthValue, 0.0, widthValue, heightValue));
......
...@@ -107,7 +107,7 @@ class LinearProgressIndicator extends ProgressIndicator { ...@@ -107,7 +107,7 @@ class LinearProgressIndicator extends ProgressIndicator {
), ),
child: new CustomPaint( child: new CustomPaint(
token: _getCustomPaintToken(performanceValue), token: _getCustomPaintToken(performanceValue),
callback: (Canvas canvas, Size size) { onPaint: (Canvas canvas, Size size) {
_paint(context, performanceValue, canvas, size); _paint(context, performanceValue, canvas, size);
} }
) )
...@@ -157,7 +157,7 @@ class CircularProgressIndicator extends ProgressIndicator { ...@@ -157,7 +157,7 @@ class CircularProgressIndicator extends ProgressIndicator {
), ),
child: new CustomPaint( child: new CustomPaint(
token: _getCustomPaintToken(performanceValue), token: _getCustomPaintToken(performanceValue),
callback: (Canvas canvas, Size size) { onPaint: (Canvas canvas, Size size) {
_paint(context, performanceValue, canvas, size); _paint(context, performanceValue, canvas, size);
} }
) )
......
...@@ -45,7 +45,7 @@ class Radio extends StatelessComponent { ...@@ -45,7 +45,7 @@ class Radio extends StatelessComponent {
width: kDiameter, width: kDiameter,
height: kDiameter, height: kDiameter,
child: new CustomPaint( child: new CustomPaint(
callback: (Canvas canvas, Size size) { onPaint: (Canvas canvas, Size size) {
// Draw the outer circle // Draw the outer circle
Paint paint = new Paint() Paint paint = new Paint()
......
...@@ -545,7 +545,7 @@ class _TabBarState extends ScrollableState<TabBar> { ...@@ -545,7 +545,7 @@ class _TabBarState extends ScrollableState<TabBar> {
if (config.isScrollable) { if (config.isScrollable) {
content = new SizeObserver( content = new SizeObserver(
callback: _handleViewportSizeChanged, onSizeChanged: _handleViewportSizeChanged,
child: new Viewport( child: new Viewport(
scrollDirection: ScrollDirection.horizontal, scrollDirection: ScrollDirection.horizontal,
scrollOffset: new Offset(scrollOffset, 0.0), scrollOffset: new Offset(scrollOffset, 0.0),
......
...@@ -962,33 +962,33 @@ class RenderTransform extends RenderProxyBox { ...@@ -962,33 +962,33 @@ class RenderTransform extends RenderProxyBox {
/// Called when a size changes /// Called when a size changes
typedef void SizeChangedCallback(Size newSize); typedef void SizeChangedCallback(Size newSize);
/// Calls [callback] whenever the child's layout size changes /// Calls [onSizeChanged] whenever the child's layout size changes
/// ///
/// Note: Size observer calls its callback during layout, which means you cannot /// Note: Size observer calls its callback during layout, which means you cannot
/// dirty layout information during the callback. /// dirty layout information during the callback.
class RenderSizeObserver extends RenderProxyBox { class RenderSizeObserver extends RenderProxyBox {
RenderSizeObserver({ RenderSizeObserver({
this.callback, this.onSizeChanged,
RenderBox child RenderBox child
}) : super(child) { }) : super(child) {
assert(callback != null); assert(onSizeChanged != null);
} }
/// The callback to call whenever the child's layout size changes /// The callback to call whenever the child's layout size changes
SizeChangedCallback callback; SizeChangedCallback onSizeChanged;
void performLayout() { void performLayout() {
Size oldSize = hasSize ? size : null; Size oldSize = hasSize ? size : null;
super.performLayout(); super.performLayout();
if (oldSize != size) if (oldSize != size)
callback(size); onSizeChanged(size);
} }
} }
/// Called when its time to paint into the given canvas /// Called when its time to paint into the given canvas
typedef void CustomPaintCallback(PaintingCanvas canvas, Size size); typedef void CustomPaintCallback(PaintingCanvas canvas, Size size);
/// Delegates its painting to [callback] /// Delegates its painting to [onPaint]
/// ///
/// When asked to paint, custom paint first calls its callback with the current /// When asked to paint, custom paint first calls its callback with the current
/// canvas and then paints its children. The coodinate system of the canvas /// canvas and then paints its children. The coodinate system of the canvas
...@@ -1003,36 +1003,36 @@ typedef void CustomPaintCallback(PaintingCanvas canvas, Size size); ...@@ -1003,36 +1003,36 @@ typedef void CustomPaintCallback(PaintingCanvas canvas, Size size);
class RenderCustomPaint extends RenderProxyBox { class RenderCustomPaint extends RenderProxyBox {
RenderCustomPaint({ RenderCustomPaint({
CustomPaintCallback callback, CustomPaintCallback onPaint,
RenderBox child RenderBox child
}) : super(child) { }) : super(child) {
assert(callback != null); assert(onPaint != null);
_callback = callback; _onPaint = onPaint;
} }
/// The callback to which this render object delegates its painting /// The callback to which this render object delegates its painting
/// ///
/// The callback must be non-null whenever the render object is attached to /// The callback must be non-null whenever the render object is attached to
/// the render tree. /// the render tree.
CustomPaintCallback get callback => _callback; CustomPaintCallback get onPaint => _onPaint;
CustomPaintCallback _callback; CustomPaintCallback _onPaint;
void set callback (CustomPaintCallback newCallback) { void set onPaint (CustomPaintCallback newCallback) {
assert(newCallback != null || !attached); assert(newCallback != null || !attached);
if (_callback == newCallback) if (_onPaint == newCallback)
return; return;
_callback = newCallback; _onPaint = newCallback;
markNeedsPaint(); markNeedsPaint();
} }
void attach() { void attach() {
assert(_callback != null); assert(_onPaint != null);
super.attach(); super.attach();
} }
void paint(PaintingContext context, Offset offset) { void paint(PaintingContext context, Offset offset) {
assert(_callback != null); assert(_onPaint != null);
context.canvas.translate(offset.dx, offset.dy); context.canvas.translate(offset.dx, offset.dy);
_callback(context.canvas, size); _onPaint(context.canvas, size);
// TODO(abarth): We should translate back before calling super because in // TODO(abarth): We should translate back before calling super because in
// the future, super.paint might switch our compositing layer. // the future, super.paint might switch our compositing layer.
super.paint(context, Offset.zero); super.paint(context, Offset.zero);
......
...@@ -134,24 +134,24 @@ class DecoratedBox extends OneChildRenderObjectWidget { ...@@ -134,24 +134,24 @@ class DecoratedBox extends OneChildRenderObjectWidget {
} }
class CustomPaint extends OneChildRenderObjectWidget { class CustomPaint extends OneChildRenderObjectWidget {
CustomPaint({ Key key, this.callback, this.token, Widget child }) CustomPaint({ Key key, this.onPaint, this.token, Widget child })
: super(key: key, child: child) { : super(key: key, child: child) {
assert(callback != null); assert(onPaint != null);
} }
final CustomPaintCallback callback; final CustomPaintCallback onPaint;
final Object token; // set this to be repainted automatically when the token changes final Object token; // set this to be repainted automatically when the token changes
RenderCustomPaint createRenderObject() => new RenderCustomPaint(callback: callback); RenderCustomPaint createRenderObject() => new RenderCustomPaint(onPaint: onPaint);
void updateRenderObject(RenderCustomPaint renderObject, CustomPaint oldWidget) { void updateRenderObject(RenderCustomPaint renderObject, CustomPaint oldWidget) {
if (oldWidget != null && oldWidget.token != token) if (oldWidget != null && oldWidget.token != token)
renderObject.markNeedsPaint(); renderObject.markNeedsPaint();
renderObject.callback = callback; renderObject.onPaint = onPaint;
} }
void didUnmountRenderObject(RenderCustomPaint renderObject) { void didUnmountRenderObject(RenderCustomPaint renderObject) {
renderObject.callback = null; renderObject.onPaint = null;
} }
} }
...@@ -428,21 +428,21 @@ class Viewport extends OneChildRenderObjectWidget { ...@@ -428,21 +428,21 @@ class Viewport extends OneChildRenderObjectWidget {
} }
class SizeObserver extends OneChildRenderObjectWidget { class SizeObserver extends OneChildRenderObjectWidget {
SizeObserver({ Key key, this.callback, Widget child }) SizeObserver({ Key key, this.onSizeChanged, Widget child })
: super(key: key, child: child) { : super(key: key, child: child) {
assert(callback != null); assert(onSizeChanged != null);
} }
final SizeChangedCallback callback; final SizeChangedCallback onSizeChanged;
RenderSizeObserver createRenderObject() => new RenderSizeObserver(callback: callback); RenderSizeObserver createRenderObject() => new RenderSizeObserver(onSizeChanged: onSizeChanged);
void updateRenderObject(RenderSizeObserver renderObject, SizeObserver oldWidget) { void updateRenderObject(RenderSizeObserver renderObject, SizeObserver oldWidget) {
renderObject.callback = callback; renderObject.onSizeChanged = onSizeChanged;
} }
void didUnmountRenderObject(RenderSizeObserver renderObject) { void didUnmountRenderObject(RenderSizeObserver renderObject) {
renderObject.callback = null; renderObject.onSizeChanged = null;
} }
} }
......
...@@ -251,7 +251,7 @@ class _DismissableState extends State<Dismissable> { ...@@ -251,7 +251,7 @@ class _DismissableState extends State<Dismissable> {
onVerticalDragUpdate: _directionIsYAxis ? _handleDragUpdate : null, onVerticalDragUpdate: _directionIsYAxis ? _handleDragUpdate : null,
onVerticalDragEnd: _directionIsYAxis ? _handleDragEnd : null, onVerticalDragEnd: _directionIsYAxis ? _handleDragEnd : null,
child: new SizeObserver( child: new SizeObserver(
callback: _handleSizeChanged, onSizeChanged: _handleSizeChanged,
child: new FadeTransition( child: new FadeTransition(
performance: _fadePerformance.view, performance: _fadePerformance.view,
opacity: new AnimatedValue<double>(1.0, end: 0.0), opacity: new AnimatedValue<double>(1.0, end: 0.0),
......
...@@ -81,7 +81,7 @@ class MimicableState extends State<Mimicable> { ...@@ -81,7 +81,7 @@ class MimicableState extends State<Mimicable> {
); );
} }
return new SizeObserver( return new SizeObserver(
callback: _handleSizeChanged, onSizeChanged: _handleSizeChanged,
child: config.child child: config.child
); );
} }
......
...@@ -54,11 +54,11 @@ class NavigatorState extends State<Navigator> { ...@@ -54,11 +54,11 @@ class NavigatorState extends State<Navigator> {
_insertRoute(route); _insertRoute(route);
} }
void pushState(State owner, Function callback) { void pushState(State owner, StateRouteCallback onPop) {
push(new StateRoute( push(new StateRoute(
route: currentRoute, route: currentRoute,
owner: owner, owner: owner,
callback: callback onPop: onPop
)); ));
} }
...@@ -318,11 +318,11 @@ class PageRoute extends PerformanceRoute { ...@@ -318,11 +318,11 @@ class PageRoute extends PerformanceRoute {
} }
class StateRoute extends Route { class StateRoute extends Route {
StateRoute({ this.route, this.owner, this.callback }); StateRoute({ this.route, this.owner, this.onPop });
Route route; Route route;
State owner; State owner;
StateRouteCallback callback; StateRouteCallback onPop;
bool get hasContent => false; bool get hasContent => false;
bool get modal => false; bool get modal => false;
...@@ -330,8 +330,8 @@ class StateRoute extends Route { ...@@ -330,8 +330,8 @@ class StateRoute extends Route {
void didPop([dynamic result]) { void didPop([dynamic result]) {
assert(result == null); assert(result == null);
if (callback != null) if (onPop != null)
callback(this); onPop(this);
super.didPop(result); super.didPop(result);
} }
......
...@@ -362,12 +362,12 @@ class ScrollableViewportState extends ScrollableState<ScrollableViewport> { ...@@ -362,12 +362,12 @@ class ScrollableViewportState extends ScrollableState<ScrollableViewport> {
Widget buildContent(BuildContext context) { Widget buildContent(BuildContext context) {
return new SizeObserver( return new SizeObserver(
callback: _handleViewportSizeChanged, onSizeChanged: _handleViewportSizeChanged,
child: new Viewport( child: new Viewport(
scrollOffset: scrollOffsetVector, scrollOffset: scrollOffsetVector,
scrollDirection: config.scrollDirection, scrollDirection: config.scrollDirection,
child: new SizeObserver( child: new SizeObserver(
callback: _handleChildSizeChanged, onSizeChanged: _handleChildSizeChanged,
child: config.child child: config.child
) )
) )
...@@ -596,7 +596,7 @@ abstract class ScrollableWidgetListState<T extends ScrollableWidgetList> extends ...@@ -596,7 +596,7 @@ abstract class ScrollableWidgetListState<T extends ScrollableWidgetList> extends
} }
return new SizeObserver( return new SizeObserver(
callback: _handleSizeChanged, onSizeChanged: _handleSizeChanged,
child: new Container( child: new Container(
padding: _crossAxisPadding, padding: _crossAxisPadding,
child: new HomogeneousViewport( child: new HomogeneousViewport(
...@@ -820,7 +820,7 @@ class ScrollableMixedWidgetListState extends ScrollableState<ScrollableMixedWidg ...@@ -820,7 +820,7 @@ class ScrollableMixedWidgetListState extends ScrollableState<ScrollableMixedWidg
Widget buildContent(BuildContext context) { Widget buildContent(BuildContext context) {
return new SizeObserver( return new SizeObserver(
callback: _handleSizeChanged, onSizeChanged: _handleSizeChanged,
child: new MixedViewport( child: new MixedViewport(
startOffset: scrollOffset, startOffset: scrollOffset,
builder: config.builder, builder: config.builder,
......
...@@ -19,7 +19,7 @@ void main() { ...@@ -19,7 +19,7 @@ void main() {
width: 0.5, width: 0.5,
height: 0.25, height: 0.25,
child: new SizeObserver( child: new SizeObserver(
callback: (Size size) { onSizeChanged: (Size size) {
detectedSize = size; detectedSize = size;
}, },
child: new Container( child: new Container(
......
...@@ -11,7 +11,7 @@ void main() { ...@@ -11,7 +11,7 @@ void main() {
List<Size> results = <Size>[]; List<Size> results = <Size>[];
tester.pumpWidget(new Center( tester.pumpWidget(new Center(
child: new SizeObserver( child: new SizeObserver(
callback: (Size size) { results.add(size); }, onSizeChanged: (Size size) { results.add(size); },
child: new Container(width:0.0, height:0.0) child: new Container(width:0.0, height:0.0)
) )
)); ));
...@@ -20,7 +20,7 @@ void main() { ...@@ -20,7 +20,7 @@ void main() {
expect(results, equals([Size.zero])); expect(results, equals([Size.zero]));
tester.pumpWidget(new Center( tester.pumpWidget(new Center(
child: new SizeObserver( child: new SizeObserver(
callback: (Size size) { results.add(size); }, onSizeChanged: (Size size) { results.add(size); },
child: new Container(width:100.0, height:0.0) child: new Container(width:100.0, height:0.0)
) )
)); ));
...@@ -29,7 +29,7 @@ void main() { ...@@ -29,7 +29,7 @@ void main() {
expect(results, equals([Size.zero, const Size(100.0, 0.0)])); expect(results, equals([Size.zero, const Size(100.0, 0.0)]));
tester.pumpWidget(new Center( tester.pumpWidget(new Center(
child: new SizeObserver( child: new SizeObserver(
callback: (Size size) { results.add(size); }, onSizeChanged: (Size size) { results.add(size); },
child: new Container(width:0.0, height:0.0) child: new Container(width:0.0, height:0.0)
) )
)); ));
...@@ -38,7 +38,7 @@ void main() { ...@@ -38,7 +38,7 @@ void main() {
expect(results, equals([Size.zero, const Size(100.0, 0.0), Size.zero])); expect(results, equals([Size.zero, const Size(100.0, 0.0), Size.zero]));
tester.pumpWidget(new Center( tester.pumpWidget(new Center(
child: new SizeObserver( child: new SizeObserver(
callback: (Size size) { results.add(size); }, onSizeChanged: (Size size) { results.add(size); },
child: new Container(width:0.0, height:0.0) child: new Container(width:0.0, height:0.0)
) )
)); ));
......
...@@ -139,7 +139,7 @@ void main() { ...@@ -139,7 +139,7 @@ void main() {
Widget buildFrame(int index) { Widget buildFrame(int index) {
itemsPainted = <int>[]; itemsPainted = <int>[];
List<Widget> items = new List<Widget>.generate(itemCount, (i) { List<Widget> items = new List<Widget>.generate(itemCount, (i) {
return new CustomPaint(child: new Text('$i'), callback: (_, __) { itemsPainted.add(i); }); return new CustomPaint(child: new Text('$i'), onPaint: (_, __) { itemsPainted.add(i); });
}); });
return new Center(child: new IndexedStack(items, index: index)); return new Center(child: new IndexedStack(items, index: index));
} }
......
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