Add a basic InkWell implementation

This CL replaces the (non-working) components2 InkWell with some code based on
the ink_well example. There are at least two issues with the implementation:

1) The ink splash always starts at the center of the well because we don't have
   a facility for converting from global to local coordinates, which means we
   can't tell where the tap occurred in the local coordinates we need to use
   for painting.

2) When used inside a MenuItem, the in splash disappears shortly after
   starting, presumably because the button starts highlighting, which causes a
   component rebuild and somehow we lose the RenderInkWell instance.

I plan to address these issues in subsequent CLs.

R=ianh@google.com

Review URL: https://codereview.chromium.org/1172033003.
This commit is contained in:
Adam Barth 2015-06-10 09:04:15 -07:00
parent ad5df9147f
commit 0e5bb2d231

View file

@ -1,70 +0,0 @@
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:sky' as sky;
import 'package:sky/framework/app.dart';
import 'package:sky/framework/rendering/box.dart';
import 'package:sky/framework/rendering/object.dart';
import 'package:sky/framework/animation/animated_value.dart';
import 'package:sky/framework/animation/curves.dart';
const double _kInitialSize = 0.0;
const double _kTargetSize = 100.0;
const double _kSplashDuration = 500.0;
const int _kInitialOpacity = 0x80;
class InkSplash {
final InkWell inkWell;
final sky.Paint _paint = new sky.Paint();
final sky.Point position;
AnimatedValue radius;
InkSplash({ this.position, this.inkWell }) {
radius = new AnimatedValue(_kInitialSize, onChange: _handleRadiusChange);
radius.animateTo(_kTargetSize, _kSplashDuration, curve: easeOut);
}
void _handleRadiusChange() {
if (radius.value == _kTargetSize)
inkWell._splashes.remove(this);
inkWell.markNeedsPaint();
}
void paint(RenderObjectDisplayList canvas) {
int opacity = (_kInitialOpacity * (1.0 - (radius.value / _kTargetSize))).floor();
_paint.color = new sky.Color(opacity << 24);
canvas.drawCircle(position.x, position.y, radius.value, _paint);
}
}
class InkWell extends RenderBox {
final List<InkSplash> _splashes = new List<InkSplash>();
void handleEvent(sky.Event event) {
switch (event.type) {
case 'pointerdown':
_splashes.add(new InkSplash(position: new sky.Point(event.x, event.y),
inkWell: this));
break;
}
markNeedsPaint();
}
void performLayout() {
size = constraints.constrain(sky.Size.infinite);
}
void paint(RenderObjectDisplayList canvas) {
canvas.drawRect(new sky.Rect.fromLTRB(0.0, 0.0, size.width, size.height),
new sky.Paint()..color = const sky.Color(0xFFCCCCCC));
for (InkSplash splash in _splashes)
splash.paint(canvas);
}
}
AppView app;
void main() {
app = new AppView(new InkWell());
}