• Adam Barth's avatar
    Improve hit testing · 9bc64540
    Adam Barth authored
    Now a RenderBox is considered hit if one of its children are hit or it itself
    decides that it's hit. In particular, empty space inside a flex won't be hit
    because none of the children are located there and a RenderFlex doesn't
    consider itself hittable.
    
    Fixes #53
    Fixes #1221
    9bc64540
error.dart 1.17 KB
// 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 'box.dart';
import 'debug.dart';
import 'object.dart';

const double _kMaxWidth = 100000.0;
const double _kMaxHeight = 100000.0;

/// A render object used as a placeholder when an error occurs
class RenderErrorBox extends RenderBox {

  double getMinIntrinsicWidth(BoxConstraints constraints) {
    return constraints.constrainWidth(0.0);
  }

  double getMaxIntrinsicWidth(BoxConstraints constraints) {
    return constraints.constrainWidth(_kMaxWidth);
  }

  double getMinIntrinsicHeight(BoxConstraints constraints) {
    return constraints.constrainHeight(0.0);
  }

  double getMaxIntrinsicHeight(BoxConstraints constraints) {
    return constraints.constrainHeight(_kMaxHeight);
  }

  bool get sizedByParent => true;

  bool hitTestSelf(Point position) => true;

  void performResize() {
    size = constraints.constrain(const Size(_kMaxWidth, _kMaxHeight));
  }

  void paint(PaintingContext context, Offset offset) {
    context.canvas.drawRect(offset & size, new Paint() .. color = debugErrorBoxColor);
  }

}