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

Unified Diff: sky/sdk/lib/framework/fn2.dart

Issue 1158983005: Implement Container in fn2 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: nit Created 5 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: sky/sdk/lib/framework/fn2.dart
diff --git a/sky/sdk/lib/framework/fn2.dart b/sky/sdk/lib/framework/fn2.dart
index e4fbb47c708b8281ed84acec14e150541ba0773b..d1f66af23f4da7a43803207fed3b71cfa5c69dac 100644
--- a/sky/sdk/lib/framework/fn2.dart
+++ b/sky/sdk/lib/framework/fn2.dart
@@ -327,6 +327,74 @@ abstract class RenderNodeWrapper extends UINode {
}
}
+abstract class OneChildRenderNodeWrapper extends RenderNodeWrapper {
+ final UINode child;
+
+ OneChildRenderNodeWrapper({ this.child, Object key }) : super(key: key);
+
+ void insert(RenderNodeWrapper child, dynamic slot) {
+ assert(slot == null);
+ root.child = child.root;
+ }
+
+ void syncRenderNode(RenderNodeWrapper old) {
+ super.syncRenderNode(old);
+ UINode oldChild = old == null ? null : (old as OneChildRenderNodeWrapper).child;
+ syncChild(child, oldChild, null);
+ }
+
+ void _remove() {
+ assert(child != null);
+ removeChild(child);
+ super._remove();
+ }
+}
+
+class Padding extends OneChildRenderNodeWrapper {
+ RenderPadding root;
+ final EdgeDims padding;
+
+ Padding({ this.padding, UINode child, Object key })
+ : super(child: child, key: key);
+
+ RenderPadding createNode() => new RenderPadding(padding: padding);
+
+ void syncRenderNode(Padding old) {
+ super.syncRenderNode(old);
+ root.padding = padding;
+ }
+}
+
+class DecoratedBox extends OneChildRenderNodeWrapper {
+ RenderDecoratedBox root;
+ final BoxDecoration decoration;
+
+ DecoratedBox({ this.decoration, UINode child, Object key })
+ : super(child: child, key: key);
+
+ RenderDecoratedBox createNode() => new RenderDecoratedBox(decoration: decoration);
+
+ void syncRenderNode(DecoratedBox old) {
+ super.syncRenderNode(old);
+ root.decoration = decoration;
+ }
+}
+
+class SizedBox extends OneChildRenderNodeWrapper {
+ RenderSizedBox root;
+ final sky.Size desiredSize;
+
+ SizedBox({ this.desiredSize, UINode child, Object key })
+ : super(child: child, key: key);
+
+ RenderSizedBox createNode() => new RenderSizedBox(desiredSize: desiredSize);
+
+ void syncRenderNode(DecoratedBox old) {
+ super.syncRenderNode(old);
+ root.desiredSize = desiredSize;
+ }
+}
+
Hixie 2015/06/02 21:52:21 Man, this could really benefit from macros.
final List<UINode> _emptyList = new List<UINode>();
abstract class OneChildListRenderNodeWrapper extends RenderNodeWrapper {
@@ -780,6 +848,41 @@ abstract class Component extends UINode {
UINode build();
}
+class Container extends Component {
+ final UINode child;
+ final EdgeDims margin;
+ final BoxDecoration decoration;
+ final sky.Size desiredSize;
+ final EdgeDims padding;
+
+ Container({
+ Object key,
+ this.child,
+ this.margin,
+ this.decoration,
+ this.desiredSize,
+ this.padding
+ }) : super(key: key);
+
+ UINode build() {
+ UINode current = child;
+
+ if (padding != null)
+ current = new Padding(padding: padding, child: current);
+
+ if (decoration != null)
+ current = new DecoratedBox(decoration: decoration, child: current);
+
+ if (desiredSize != null)
+ current = new SizedBox(desiredSize: desiredSize, child: current);
+
+ if (margin != null)
+ current = new Padding(padding: margin, child: current);
+
+ return current;
+ }
+}
+
class _AppView extends AppView {
_AppView() : super(null);

Powered by Google App Engine
This is Rietveld 408576698