Commit 8eb8c47a authored by Adam Barth's avatar Adam Barth

Add CustomPaint and few other basic widgets to fn3

We'll need tag nodes before finishing Flex and Stack.
parent 61d0ca77
...@@ -46,7 +46,7 @@ class Opacity extends OneChildRenderObjectWidget { ...@@ -46,7 +46,7 @@ class Opacity extends OneChildRenderObjectWidget {
RenderOpacity createRenderObject() => new RenderOpacity(opacity: opacity); RenderOpacity createRenderObject() => new RenderOpacity(opacity: opacity);
void updateRenderObject(RenderOpacity renderObject) { void updateRenderObject(RenderOpacity renderObject, Opacity oldWidget) {
renderObject.opacity = opacity; renderObject.opacity = opacity;
} }
} }
...@@ -63,7 +63,7 @@ class ColorFilter extends OneChildRenderObjectWidget { ...@@ -63,7 +63,7 @@ class ColorFilter extends OneChildRenderObjectWidget {
RenderColorFilter createRenderObject() => new RenderColorFilter(color: color, transferMode: transferMode); RenderColorFilter createRenderObject() => new RenderColorFilter(color: color, transferMode: transferMode);
void updateRenderObject(RenderColorFilter renderObject) { void updateRenderObject(RenderColorFilter renderObject, ColorFilter oldWidget) {
renderObject.color = color; renderObject.color = color;
renderObject.transferMode = transferMode; renderObject.transferMode = transferMode;
} }
...@@ -85,13 +85,33 @@ class DecoratedBox extends OneChildRenderObjectWidget { ...@@ -85,13 +85,33 @@ class DecoratedBox extends OneChildRenderObjectWidget {
RenderObject createRenderObject() => new RenderDecoratedBox(decoration: decoration, position: position); RenderObject createRenderObject() => new RenderDecoratedBox(decoration: decoration, position: position);
void updateRenderObject(RenderDecoratedBox renderObject) { void updateRenderObject(RenderDecoratedBox renderObject, DecoratedBox oldWidget) {
renderObject.decoration = decoration; renderObject.decoration = decoration;
renderObject.position = position; renderObject.position = position;
} }
} }
// TODO(abarth): CustomPaint class CustomPaint extends OneChildRenderObjectWidget {
CustomPaint({ Key key, this.callback, this.token, Widget child })
: super(key: key, child: child) {
assert(callback != null);
}
final CustomPaintCallback callback;
final Object token; // set this to be repainted automatically when the token changes
RenderCustomPaint createRenderObject() => new RenderCustomPaint(callback: callback);
void updateRenderObject(RenderCustomPaint renderObject, CustomPaint oldWidget) {
if (oldWidget != null && oldWidget.token != token)
renderObject.markNeedsPaint();
renderObject.callback = callback;
}
void didUnmountRenderObject(RenderCustomPaint renderObject) {
renderObject.callback = null;
}
}
class ClipRect extends OneChildRenderObjectWidget { class ClipRect extends OneChildRenderObjectWidget {
ClipRect({ Key key, Widget child }) ClipRect({ Key key, Widget child })
...@@ -99,7 +119,7 @@ class ClipRect extends OneChildRenderObjectWidget { ...@@ -99,7 +119,7 @@ class ClipRect extends OneChildRenderObjectWidget {
RenderClipRect createRenderObject() => new RenderClipRect(); RenderClipRect createRenderObject() => new RenderClipRect();
void updateRenderObject(ClipRect renderObject) { void updateRenderObject(ClipRect renderObject, ClipRect oldWidget) {
// Nothing to update // Nothing to update
} }
} }
...@@ -113,7 +133,7 @@ class ClipRRect extends OneChildRenderObjectWidget { ...@@ -113,7 +133,7 @@ class ClipRRect extends OneChildRenderObjectWidget {
RenderClipRRect createRenderObject() => new RenderClipRRect(xRadius: xRadius, yRadius: yRadius); RenderClipRRect createRenderObject() => new RenderClipRRect(xRadius: xRadius, yRadius: yRadius);
void updateRenderObject(RenderClipRRect renderObject) { void updateRenderObject(RenderClipRRect renderObject, ClipRRect oldWidget) {
renderObject.xRadius = xRadius; renderObject.xRadius = xRadius;
renderObject.yRadius = yRadius; renderObject.yRadius = yRadius;
} }
...@@ -125,7 +145,7 @@ class ClipOval extends OneChildRenderObjectWidget { ...@@ -125,7 +145,7 @@ class ClipOval extends OneChildRenderObjectWidget {
RenderClipOval createRenderObject() => new RenderClipOval(); RenderClipOval createRenderObject() => new RenderClipOval();
void updateRenderObject(ClipOval renderObject) { void updateRenderObject(ClipOval renderObject, ClipOval oldWidget) {
// Nothing to update // Nothing to update
} }
} }
...@@ -144,7 +164,7 @@ class Transform extends OneChildRenderObjectWidget { ...@@ -144,7 +164,7 @@ class Transform extends OneChildRenderObjectWidget {
RenderTransform createRenderObject() => new RenderTransform(transform: transform, origin: origin); RenderTransform createRenderObject() => new RenderTransform(transform: transform, origin: origin);
void updateRenderObject(RenderTransform renderObject) { void updateRenderObject(RenderTransform renderObject, Transform oldWidget) {
renderObject.transform = transform; renderObject.transform = transform;
renderObject.origin = origin; renderObject.origin = origin;
} }
...@@ -160,7 +180,7 @@ class Padding extends OneChildRenderObjectWidget { ...@@ -160,7 +180,7 @@ class Padding extends OneChildRenderObjectWidget {
RenderPadding createRenderObject() => new RenderPadding(padding: padding); RenderPadding createRenderObject() => new RenderPadding(padding: padding);
void updateRenderObject(RenderPadding renderObject) { void updateRenderObject(RenderPadding renderObject, Padding oldWidget) {
renderObject.padding = padding; renderObject.padding = padding;
} }
} }
...@@ -184,7 +204,7 @@ class Align extends OneChildRenderObjectWidget { ...@@ -184,7 +204,7 @@ class Align extends OneChildRenderObjectWidget {
RenderPositionedBox createRenderObject() => new RenderPositionedBox(horizontal: horizontal, vertical: vertical, shrinkWrap: shrinkWrap); RenderPositionedBox createRenderObject() => new RenderPositionedBox(horizontal: horizontal, vertical: vertical, shrinkWrap: shrinkWrap);
void updateRenderObject(RenderPositionedBox renderObject) { void updateRenderObject(RenderPositionedBox renderObject, Align oldWidget) {
renderObject.horizontal = horizontal; renderObject.horizontal = horizontal;
renderObject.vertical = vertical; renderObject.vertical = vertical;
renderObject.shrinkWrap = shrinkWrap; renderObject.shrinkWrap = shrinkWrap;
...@@ -214,7 +234,7 @@ class SizedBox extends OneChildRenderObjectWidget { ...@@ -214,7 +234,7 @@ class SizedBox extends OneChildRenderObjectWidget {
return result; return result;
} }
void updateRenderObject(RenderConstrainedBox renderObject) { void updateRenderObject(RenderConstrainedBox renderObject, SizedBox oldWidget) {
renderObject.additionalConstraints = _additionalConstraints; renderObject.additionalConstraints = _additionalConstraints;
} }
} }
...@@ -229,7 +249,7 @@ class ConstrainedBox extends OneChildRenderObjectWidget { ...@@ -229,7 +249,7 @@ class ConstrainedBox extends OneChildRenderObjectWidget {
RenderConstrainedBox createRenderObject() => new RenderConstrainedBox(additionalConstraints: constraints); RenderConstrainedBox createRenderObject() => new RenderConstrainedBox(additionalConstraints: constraints);
void updateRenderObject(RenderConstrainedBox renderObject) { void updateRenderObject(RenderConstrainedBox renderObject, ConstrainedBox oldWidget) {
renderObject.additionalConstraints = constraints; renderObject.additionalConstraints = constraints;
} }
} }
...@@ -244,7 +264,7 @@ class AspectRatio extends OneChildRenderObjectWidget { ...@@ -244,7 +264,7 @@ class AspectRatio extends OneChildRenderObjectWidget {
RenderAspectRatio createRenderObject() => new RenderAspectRatio(aspectRatio: aspectRatio); RenderAspectRatio createRenderObject() => new RenderAspectRatio(aspectRatio: aspectRatio);
void updateRenderObject(RenderAspectRatio renderObject) { void updateRenderObject(RenderAspectRatio renderObject, AspectRatio oldWidget) {
renderObject.aspectRatio = aspectRatio; renderObject.aspectRatio = aspectRatio;
} }
} }
...@@ -258,7 +278,7 @@ class IntrinsicWidth extends OneChildRenderObjectWidget { ...@@ -258,7 +278,7 @@ class IntrinsicWidth extends OneChildRenderObjectWidget {
RenderIntrinsicWidth createRenderObject() => new RenderIntrinsicWidth(stepWidth: stepWidth, stepHeight: stepHeight); RenderIntrinsicWidth createRenderObject() => new RenderIntrinsicWidth(stepWidth: stepWidth, stepHeight: stepHeight);
void updateRenderObject(RenderIntrinsicWidth renderObject) { void updateRenderObject(RenderIntrinsicWidth renderObject, IntrinsicWidth oldWidget) {
renderObject.stepWidth = stepWidth; renderObject.stepWidth = stepWidth;
renderObject.stepHeight = stepHeight; renderObject.stepHeight = stepHeight;
} }
...@@ -270,7 +290,7 @@ class IntrinsicHeight extends OneChildRenderObjectWidget { ...@@ -270,7 +290,7 @@ class IntrinsicHeight extends OneChildRenderObjectWidget {
RenderIntrinsicHeight createRenderObject() => new RenderIntrinsicHeight(); RenderIntrinsicHeight createRenderObject() => new RenderIntrinsicHeight();
void updateRenderObject(RenderIntrinsicHeight renderObject) { void updateRenderObject(RenderIntrinsicHeight renderObject, IntrinsicHeight oldWidget) {
// Nothing to update // Nothing to update
} }
} }
...@@ -287,7 +307,7 @@ class Baseline extends OneChildRenderObjectWidget { ...@@ -287,7 +307,7 @@ class Baseline extends OneChildRenderObjectWidget {
RenderBaseline createRenderObject() => new RenderBaseline(baseline: baseline, baselineType: baselineType); RenderBaseline createRenderObject() => new RenderBaseline(baseline: baseline, baselineType: baselineType);
void updateRenderObject(RenderBaseline renderObject) { void updateRenderObject(RenderBaseline renderObject, Baseline oldWidget) {
renderObject.baseline = baseline; renderObject.baseline = baseline;
renderObject.baselineType = baselineType; renderObject.baselineType = baselineType;
} }
...@@ -309,7 +329,7 @@ class Viewport extends OneChildRenderObjectWidget { ...@@ -309,7 +329,7 @@ class Viewport extends OneChildRenderObjectWidget {
RenderViewport createRenderObject() => new RenderViewport(scrollDirection: scrollDirection, scrollOffset: scrollOffset); RenderViewport createRenderObject() => new RenderViewport(scrollDirection: scrollDirection, scrollOffset: scrollOffset);
void updateRenderObject(RenderViewport renderObject) { void updateRenderObject(RenderViewport renderObject, Viewport oldWidget) {
// Order dependency: RenderViewport validates scrollOffset based on scrollDirection. // Order dependency: RenderViewport validates scrollOffset based on scrollDirection.
renderObject.scrollDirection = scrollDirection; renderObject.scrollDirection = scrollDirection;
renderObject.scrollOffset = scrollOffset; renderObject.scrollOffset = scrollOffset;
...@@ -326,11 +346,13 @@ class SizeObserver extends OneChildRenderObjectWidget { ...@@ -326,11 +346,13 @@ class SizeObserver extends OneChildRenderObjectWidget {
RenderSizeObserver createRenderObject() => new RenderSizeObserver(callback: callback); RenderSizeObserver createRenderObject() => new RenderSizeObserver(callback: callback);
void updateRenderObject(RenderSizeObserver renderObject) { void updateRenderObject(RenderSizeObserver renderObject, SizeObserver oldWidget) {
renderObject.callback = callback; renderObject.callback = callback;
} }
// TODO(abarth): Null out renderObject.callback during unmount void didUnmountRenderObject(RenderSizeObserver renderObject) {
renderObject.callback = null;
}
} }
...@@ -431,7 +453,7 @@ class BlockBody extends MultiChildRenderObjectWidget { ...@@ -431,7 +453,7 @@ class BlockBody extends MultiChildRenderObjectWidget {
RenderBlock createRenderObject() => new RenderBlock(direction: direction); RenderBlock createRenderObject() => new RenderBlock(direction: direction);
void updateRenderObject(RenderBlock renderObject) { void updateRenderObject(RenderBlock renderObject, BlockBody oldWidget) {
renderObject.direction = direction; renderObject.direction = direction;
} }
} }
...@@ -442,7 +464,7 @@ class Stack extends MultiChildRenderObjectWidget { ...@@ -442,7 +464,7 @@ class Stack extends MultiChildRenderObjectWidget {
RenderStack createRenderObject() => new RenderStack(); RenderStack createRenderObject() => new RenderStack();
void updateRenderObject(ClipRect renderObject) { void updateRenderObject(ClipRect renderObject, Stack oldWidget) {
// Nothing to update // Nothing to update
} }
...@@ -461,7 +483,7 @@ class Grid extends MultiChildRenderObjectWidget { ...@@ -461,7 +483,7 @@ class Grid extends MultiChildRenderObjectWidget {
RenderGrid createRenderObject() => new RenderGrid(maxChildExtent: maxChildExtent); RenderGrid createRenderObject() => new RenderGrid(maxChildExtent: maxChildExtent);
void updateRenderObject(RenderGrid renderObject) { void updateRenderObject(RenderGrid renderObject, Grid oldWidget) {
renderObject.maxChildExtent = maxChildExtent; renderObject.maxChildExtent = maxChildExtent;
} }
} }
...@@ -486,7 +508,7 @@ class Flex extends MultiChildRenderObjectWidget { ...@@ -486,7 +508,7 @@ class Flex extends MultiChildRenderObjectWidget {
RenderFlex createRenderObject() => new RenderFlex(direction: direction); RenderFlex createRenderObject() => new RenderFlex(direction: direction);
void updateRenderObject(RenderFlex renderObject) { void updateRenderObject(RenderFlex renderObject, Flex oldWidget) {
renderObject.direction = direction; renderObject.direction = direction;
renderObject.justifyContent = justifyContent; renderObject.justifyContent = justifyContent;
renderObject.alignItems = alignItems; renderObject.alignItems = alignItems;
...@@ -525,7 +547,7 @@ class Paragraph extends LeafRenderObjectWidget { ...@@ -525,7 +547,7 @@ class Paragraph extends LeafRenderObjectWidget {
RenderParagraph createRenderObject() => new RenderParagraph(text); RenderParagraph createRenderObject() => new RenderParagraph(text);
void updateRenderObject(RenderParagraph renderObject) { void updateRenderObject(RenderParagraph renderObject, Paragraph oldWidget) {
renderObject.text = text; renderObject.text = text;
} }
} }
...@@ -585,7 +607,7 @@ class Image extends LeafRenderObjectWidget { ...@@ -585,7 +607,7 @@ class Image extends LeafRenderObjectWidget {
fit: fit, fit: fit,
repeat: repeat); repeat: repeat);
void updateRenderObject(RenderImage renderObject) { void updateRenderObject(RenderImage renderObject, Image oldWidget) {
renderObject.image = image; renderObject.image = image;
renderObject.width = width; renderObject.width = width;
renderObject.height = height; renderObject.height = height;
...@@ -716,8 +738,6 @@ class AssetImage extends StatelessComponent { ...@@ -716,8 +738,6 @@ class AssetImage extends StatelessComponent {
} }
} }
// TODO(abarth): WidgetToRenderBoxAdapter
// EVENT HANDLING // EVENT HANDLING
...@@ -729,7 +749,7 @@ class IgnorePointer extends OneChildRenderObjectWidget { ...@@ -729,7 +749,7 @@ class IgnorePointer extends OneChildRenderObjectWidget {
RenderIgnorePointer createElement() => new RenderIgnorePointer(ignoring: ignoring); RenderIgnorePointer createElement() => new RenderIgnorePointer(ignoring: ignoring);
void updateRenderObject(RenderIgnorePointer renderObject) { void updateRenderObject(RenderIgnorePointer renderObject, IgnorePointer oldWidget) {
renderObject.ignoring = ignoring; renderObject.ignoring = ignoring;
} }
} }
...@@ -5,7 +5,26 @@ ...@@ -5,7 +5,26 @@
import 'package:sky/animation.dart'; import 'package:sky/animation.dart';
import 'package:sky/rendering.dart'; import 'package:sky/rendering.dart';
abstract class Key { } abstract class Key {
const Key.constructor(); // so that subclasses can call us, since the Key() factory constructor shadows the implicit constructor
factory Key(String value) => new ValueKey<String>(value);
}
class ValueKey<T> extends Key {
const ValueKey(this.value) : super.constructor();
final T value;
String toString() => '[\'${value}\']';
bool operator==(other) => other is ValueKey<T> && other.value == value;
int get hashCode => value.hashCode;
}
class ObjectKey extends Key {
const ObjectKey(this.value) : super.constructor();
final Object value;
String toString() => '[${value.runtimeType}(${value.hashCode})]';
bool operator==(other) => other is ObjectKey && identical(other.value, value);
int get hashCode => identityHashCode(value);
}
/// A Widget object describes the configuration for an [Element]. /// A Widget object describes the configuration for an [Element].
/// Widget subclasses should be immutable with const constructors. /// Widget subclasses should be immutable with const constructors.
...@@ -35,7 +54,9 @@ abstract class RenderObjectWidget extends Widget { ...@@ -35,7 +54,9 @@ abstract class RenderObjectWidget extends Widget {
/// Copies the configuration described by this RenderObjectWidget to the given /// Copies the configuration described by this RenderObjectWidget to the given
/// RenderObject, which must be of the same type as returned by this class' /// RenderObject, which must be of the same type as returned by this class'
/// createRenderObject(). /// createRenderObject().
void updateRenderObject(RenderObject renderObject); void updateRenderObject(RenderObject renderObject, RenderObjectWidget oldWidget);
void didUnmountRenderObject(RenderObject renderObject) { }
} }
/// A superclass for RenderObjectWidgets that configure RenderObject subclasses /// A superclass for RenderObjectWidgets that configure RenderObject subclasses
...@@ -469,9 +490,15 @@ abstract class RenderObjectElement<T extends RenderObjectWidget> extends Element ...@@ -469,9 +490,15 @@ abstract class RenderObjectElement<T extends RenderObjectWidget> extends Element
} }
void update(T newWidget) { void update(T newWidget) {
Widget oldWidget = _widget;
super.update(newWidget); super.update(newWidget);
assert(_widget == newWidget); assert(_widget == newWidget);
_widget.updateRenderObject(renderObject); _widget.updateRenderObject(renderObject, oldWidget);
}
void unmount() {
super.unmount();
_widget.didUnmountRenderObject(renderObject);
} }
void detachRenderObject() { void detachRenderObject() {
......
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