public static void paintOverflowIndicator( RenderObject renderObject, PaintingContext context, Offset offset, Rect containerRect, Rect childRect, string overflowHints = null ) { RelativeRect overflow = RelativeRect.fromRect(containerRect, childRect); if (overflow.left <= 0.0f && overflow.right <= 0.0f && overflow.top <= 0.0f && overflow.bottom <= 0.0f) { return; } List <_OverflowRegionData> overflowRegions = _calculateOverflowRegions(overflow, containerRect); foreach (_OverflowRegionData region in overflowRegions) { context.canvas.drawRect(region.rect.shift(offset), _indicatorPaint); if (_indicatorLabel[(int)region.side].text?.text != region.label) { _indicatorLabel[(int)region.side].text = new TextSpan( text: region.label, style: _indicatorTextStyle ); _indicatorLabel[(int)region.side].layout(); } Offset labelOffset = region.labelOffset + offset; Offset centerOffset = new Offset(-_indicatorLabel[(int)region.side].width / 2.0f, 0.0f); Rect textBackgroundRect = centerOffset & _indicatorLabel[(int)region.side].size; context.canvas.save(); context.canvas.translate(labelOffset.dx, labelOffset.dy); context.canvas.rotate(region.rotation); context.canvas.drawRect(textBackgroundRect, _labelBackgroundPaint); _indicatorLabel[(int)region.side].paint(context.canvas, centerOffset); context.canvas.restore(); } bool containsKey = _overflowReportNeeded.TryGetValue(renderObject, out var overflowReportNeeded); overflowReportNeeded |= !containsKey; if (overflowReportNeeded) { _overflowReportNeeded[renderObject] = false; _reportOverflow(renderObject, overflow, overflowHints); } }
void showButtonMenu() { PopupMenuThemeData popupMenuTheme = PopupMenuTheme.of(context); RenderBox button = (RenderBox)context.findRenderObject(); RenderBox overlay = (RenderBox)Overlay.of(context).context.findRenderObject(); RelativeRect position = RelativeRect.fromRect( Rect.fromPoints( button.localToGlobal(widget.offset, ancestor: overlay), button.localToGlobal(button.size.bottomRight(Offset.zero), ancestor: overlay) ), Offset.zero & overlay.size ); List <PopupMenuEntry <T> > items = widget.itemBuilder(context); if (items.isNotEmpty()) { material_.showMenu <T>( context: context, elevation: widget.elevation ?? popupMenuTheme.elevation, items: items, initialValue: widget.initialValue, position: position, shape: widget.shape ?? popupMenuTheme.shape, color: widget.color ?? popupMenuTheme.color, captureInheritedThemes: widget.captureInheritedThemes ) .then(newValue => { if (!mounted) { return; } if (newValue == null) { if (widget.onCanceled != null) { widget.onCanceled(); } return; } if (widget.onSelected != null) { widget.onSelected((T)newValue); } }); } }
void showButtonMenu() { RenderBox button = (RenderBox)this.context.findRenderObject(); RenderBox overlay = (RenderBox)Overlay.of(this.context).context.findRenderObject(); RelativeRect position = RelativeRect.fromRect( Rect.fromPoints( button.localToGlobal(this.widget.offset, ancestor: overlay), button.localToGlobal(button.size.bottomRight(Offset.zero), ancestor: overlay) ), Offset.zero & overlay.size ); PopupMenuUtils.showMenu( context: this.context, elevation: this.widget.elevation, items: this.widget.itemBuilder(this.context), initialValue: this.widget.initialValue, position: position ) .Then(newValue => { if (!this.mounted) { return; } if (newValue == null) { if (this.widget.onCanceled != null) { this.widget.onCanceled(); } return; } if (this.widget.onSelected != null) { this.widget.onSelected((T)newValue); } }); }
public static void paintOverflowIndicator( RenderObject renderObject, PaintingContext context, Offset offset, Rect containerRect, Rect childRect, List <DiagnosticsNode> overflowHints = null ) { RelativeRect overflow = RelativeRect.fromRect(containerRect, childRect); if (overflow.left <= 0.0f && overflow.right <= 0.0f && overflow.top <= 0.0f && overflow.bottom <= 0.0f) { return; } TextStyle _indicatorTextStyle = new TextStyle( color: new Color(0xFF900000), fontSize: _indicatorFontSizePixels, fontWeight: FontWeight.w800 ); Paint _indicatorPaint = new Paint { shader = Gradient.linear( new Offset(0.0f, 0.0f), new Offset(10.0f, 10.0f), new List <Color> { _black, _yellow, _yellow, _black }, new List <float> { 0.25f, 0.25f, 0.75f, 0.75f }, TileMode.repeated ) }; Paint _labelBackgroundPaint = new Paint { color = new Color(0xFFFFFFFF) }; List <_OverflowRegionData> overflowRegions = _calculateOverflowRegions(overflow, containerRect); foreach (_OverflowRegionData region in overflowRegions) { context.canvas.drawRect(region.rect.shift(offset), _indicatorPaint); var textPainter = new TextPainter(textDirection: TextDirection.ltr) { text = new TextSpan( text: region.label, style: _indicatorTextStyle) }; textPainter.layout(); Offset labelOffset = region.labelOffset + offset; Offset centerOffset = new Offset(-textPainter.width / 2.0f, 0.0f); Rect textBackgroundRect = centerOffset & textPainter.size; context.canvas.save(); context.canvas.translate(labelOffset.dx, labelOffset.dy); context.canvas.rotate(region.rotation); context.canvas.drawRect(textBackgroundRect, _labelBackgroundPaint); textPainter.paint(context.canvas, centerOffset); context.canvas.restore(); } bool containsKey = _overflowReportNeeded.TryGetValue(renderObject, out var overflowReportNeeded); overflowReportNeeded |= !containsKey; if (overflowReportNeeded) { _overflowReportNeeded[renderObject] = false; _reportOverflow(renderObject, overflow, overflowHints); } }