Commit 6f17228e authored by Adam Barth's avatar Adam Barth

Merge pull request #634 from abarth/popup_menu_align

PopupMenu shouldn't use CustomPaint
parents 114135aa c810b050
...@@ -5,13 +5,11 @@ ...@@ -5,13 +5,11 @@
import 'dart:async'; import 'dart:async';
import 'package:flutter/animation.dart'; import 'package:flutter/animation.dart';
import 'package:flutter/painting.dart';
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
import 'ink_well.dart'; import 'ink_well.dart';
import 'material.dart';
import 'popup_menu_item.dart'; import 'popup_menu_item.dart';
import 'shadows.dart';
import 'theme.dart';
const Duration _kMenuDuration = const Duration(milliseconds: 300); const Duration _kMenuDuration = const Duration(milliseconds: 300);
const double _kMenuCloseIntervalEnd = 2.0 / 3.0; const double _kMenuCloseIntervalEnd = 2.0 / 3.0;
...@@ -21,38 +19,6 @@ const double _kMenuMaxWidth = 5.0 * _kMenuWidthStep; ...@@ -21,38 +19,6 @@ const double _kMenuMaxWidth = 5.0 * _kMenuWidthStep;
const double _kMenuHorizontalPadding = 16.0; const double _kMenuHorizontalPadding = 16.0;
const double _kMenuVerticalPadding = 8.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 { class _PopupMenu<T> extends StatelessComponent {
_PopupMenu({ _PopupMenu({
Key key, Key key,
...@@ -88,25 +54,26 @@ class _PopupMenu<T> extends StatelessComponent { ...@@ -88,25 +54,26 @@ class _PopupMenu<T> extends StatelessComponent {
builder: (BuildContext context) { builder: (BuildContext context) {
return new Opacity( return new Opacity(
opacity: opacity.value, opacity: opacity.value,
child: new CustomPaint( child: new Material(
painter: new _PopupMenuPainter( type: MaterialType.card,
color: Theme.of(context).canvasColor, elevation: route.elevation,
elevation: route.elevation, child: new Align(
width: width.value, alignment: const FractionalOffset(1.0, 0.0),
height: height.value widthFactor: width.value,
), heightFactor: height.value,
child: new ConstrainedBox( child: new ConstrainedBox(
constraints: new BoxConstraints( constraints: new BoxConstraints(
minWidth: _kMenuMinWidth, minWidth: _kMenuMinWidth,
maxWidth: _kMenuMaxWidth maxWidth: _kMenuMaxWidth
), ),
child: new IntrinsicWidth( child: new IntrinsicWidth(
stepWidth: _kMenuWidthStep, stepWidth: _kMenuWidthStep,
child: new Block( child: new Block(
children, children,
padding: const EdgeDims.symmetric( padding: const EdgeDims.symmetric(
horizontal: _kMenuHorizontalPadding, horizontal: _kMenuHorizontalPadding,
vertical: _kMenuVerticalPadding vertical: _kMenuVerticalPadding
)
) )
) )
) )
......
...@@ -162,8 +162,8 @@ class RenderFractionallySizedBox extends RenderProxyBox { ...@@ -162,8 +162,8 @@ class RenderFractionallySizedBox extends RenderProxyBox {
double widthFactor, double widthFactor,
double heightFactor double heightFactor
}) : _widthFactor = widthFactor, _heightFactor = heightFactor, super(child) { }) : _widthFactor = widthFactor, _heightFactor = heightFactor, super(child) {
assert(_widthFactor == null || _widthFactor > 0.0); assert(_widthFactor == null || _widthFactor >= 0.0);
assert(_heightFactor == null || _heightFactor > 0.0); assert(_heightFactor == null || _heightFactor >= 0.0);
} }
/// The multiple to apply to the incoming maximum width constraint to use as /// The multiple to apply to the incoming maximum width constraint to use as
...@@ -172,7 +172,7 @@ class RenderFractionallySizedBox extends RenderProxyBox { ...@@ -172,7 +172,7 @@ class RenderFractionallySizedBox extends RenderProxyBox {
double get widthFactor => _widthFactor; double get widthFactor => _widthFactor;
double _widthFactor; double _widthFactor;
void set widthFactor (double value) { void set widthFactor (double value) {
assert(value == null || value > 0.0); assert(value == null || value >= 0.0);
if (_widthFactor == value) if (_widthFactor == value)
return; return;
_widthFactor = value; _widthFactor = value;
...@@ -185,7 +185,7 @@ class RenderFractionallySizedBox extends RenderProxyBox { ...@@ -185,7 +185,7 @@ class RenderFractionallySizedBox extends RenderProxyBox {
double get heightFactor => _heightFactor; double get heightFactor => _heightFactor;
double _heightFactor; double _heightFactor;
void set heightFactor (double value) { void set heightFactor (double value) {
assert(value == null || value > 0.0); assert(value == null || value >= 0.0);
if (_heightFactor == value) if (_heightFactor == value)
return; return;
_heightFactor = value; _heightFactor = value;
...@@ -193,11 +193,25 @@ class RenderFractionallySizedBox extends RenderProxyBox { ...@@ -193,11 +193,25 @@ class RenderFractionallySizedBox extends RenderProxyBox {
} }
BoxConstraints _getInnerConstraints(BoxConstraints constraints) { 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( return new BoxConstraints(
minWidth: _widthFactor == null ? constraints.minWidth : constraints.maxWidth * _widthFactor, minWidth: minWidth,
maxWidth: _widthFactor == null ? constraints.maxWidth : constraints.maxWidth * _widthFactor, maxWidth: maxWidth,
minHeight: _heightFactor == null ? constraints.minHeight : constraints.maxHeight * _heightFactor, minHeight: minHeight,
maxHeight: _heightFactor == null ? constraints.maxHeight : constraints.maxHeight * _heightFactor 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