Commit c810b050 authored by Adam Barth's avatar Adam Barth

PopupMenu shouldn't use CustomPaint

Align is now powerful enough to do all the work we need to do here.
parent 4472d06e
......@@ -5,13 +5,11 @@
import 'dart:async';
import 'package:flutter/animation.dart';
import 'package:flutter/painting.dart';
import 'package:flutter/widgets.dart';
import 'ink_well.dart';
import 'material.dart';
import 'popup_menu_item.dart';
import 'shadows.dart';
import 'theme.dart';
const Duration _kMenuDuration = const Duration(milliseconds: 300);
const double _kMenuCloseIntervalEnd = 2.0 / 3.0;
......@@ -21,38 +19,6 @@ const double _kMenuMaxWidth = 5.0 * _kMenuWidthStep;
const double _kMenuHorizontalPadding = 16.0;
const double _kMenuVerticalPadding = 8.0;
class _PopupMenuPainter extends CustomPainter {
const _PopupMenuPainter({
this.color,
this.elevation,
this.width,
this.height
});
final Color color;
final int elevation;
final double width;
final double height;
void paint(Canvas canvas, Size size) {
double widthValue = width * size.width;
double heightValue = height * size.height;
final BoxPainter painter = new BoxPainter(new BoxDecoration(
backgroundColor: color,
borderRadius: 2.0,
boxShadow: elevationToShadow[elevation]
));
painter.paint(canvas, new Rect.fromLTWH(size.width - widthValue, 0.0, widthValue, heightValue));
}
bool shouldRepaint(_PopupMenuPainter oldPainter) {
return oldPainter.color != color
|| oldPainter.elevation != elevation
|| oldPainter.width != width
|| oldPainter.height != height;
}
}
class _PopupMenu<T> extends StatelessComponent {
_PopupMenu({
Key key,
......@@ -88,25 +54,26 @@ class _PopupMenu<T> extends StatelessComponent {
builder: (BuildContext context) {
return new Opacity(
opacity: opacity.value,
child: new CustomPaint(
painter: new _PopupMenuPainter(
color: Theme.of(context).canvasColor,
elevation: route.elevation,
width: width.value,
height: height.value
),
child: new ConstrainedBox(
constraints: new BoxConstraints(
minWidth: _kMenuMinWidth,
maxWidth: _kMenuMaxWidth
),
child: new IntrinsicWidth(
stepWidth: _kMenuWidthStep,
child: new Block(
children,
padding: const EdgeDims.symmetric(
horizontal: _kMenuHorizontalPadding,
vertical: _kMenuVerticalPadding
child: new Material(
type: MaterialType.card,
elevation: route.elevation,
child: new Align(
alignment: const FractionalOffset(1.0, 0.0),
widthFactor: width.value,
heightFactor: height.value,
child: new ConstrainedBox(
constraints: new BoxConstraints(
minWidth: _kMenuMinWidth,
maxWidth: _kMenuMaxWidth
),
child: new IntrinsicWidth(
stepWidth: _kMenuWidthStep,
child: new Block(
children,
padding: const EdgeDims.symmetric(
horizontal: _kMenuHorizontalPadding,
vertical: _kMenuVerticalPadding
)
)
)
)
......
......@@ -162,8 +162,8 @@ class RenderFractionallySizedBox extends RenderProxyBox {
double widthFactor,
double heightFactor
}) : _widthFactor = widthFactor, _heightFactor = heightFactor, super(child) {
assert(_widthFactor == null || _widthFactor > 0.0);
assert(_heightFactor == null || _heightFactor > 0.0);
assert(_widthFactor == null || _widthFactor >= 0.0);
assert(_heightFactor == null || _heightFactor >= 0.0);
}
/// The multiple to apply to the incoming maximum width constraint to use as
......@@ -172,7 +172,7 @@ class RenderFractionallySizedBox extends RenderProxyBox {
double get widthFactor => _widthFactor;
double _widthFactor;
void set widthFactor (double value) {
assert(value == null || value > 0.0);
assert(value == null || value >= 0.0);
if (_widthFactor == value)
return;
_widthFactor = value;
......@@ -185,7 +185,7 @@ class RenderFractionallySizedBox extends RenderProxyBox {
double get heightFactor => _heightFactor;
double _heightFactor;
void set heightFactor (double value) {
assert(value == null || value > 0.0);
assert(value == null || value >= 0.0);
if (_heightFactor == value)
return;
_heightFactor = value;
......@@ -193,11 +193,25 @@ class RenderFractionallySizedBox extends RenderProxyBox {
}
BoxConstraints _getInnerConstraints(BoxConstraints constraints) {
double minWidth = constraints.minWidth;
double maxWidth = constraints.maxWidth;
if (_widthFactor != null) {
double width = maxWidth * _widthFactor;
minWidth = width;
maxWidth = width;
}
double minHeight = constraints.minHeight;
double maxHeight = constraints.maxHeight;
if (_heightFactor != null) {
double height = maxHeight * _heightFactor;
minHeight = height;
maxHeight = height;
}
return new BoxConstraints(
minWidth: _widthFactor == null ? constraints.minWidth : constraints.maxWidth * _widthFactor,
maxWidth: _widthFactor == null ? constraints.maxWidth : constraints.maxWidth * _widthFactor,
minHeight: _heightFactor == null ? constraints.minHeight : constraints.maxHeight * _heightFactor,
maxHeight: _heightFactor == null ? constraints.maxHeight : constraints.maxHeight * _heightFactor
minWidth: minWidth,
maxWidth: maxWidth,
minHeight: minHeight,
maxHeight: maxHeight
);
}
......
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